| 37 | |
| 38 | |
| 39 | TEST(EncoderTest, Response) |
| 40 | { |
| 41 | http::Request request; |
| 42 | const http::OK response("body"); |
| 43 | |
| 44 | // Encode the response. |
| 45 | const string encoded = HttpResponseEncoder::encode(response, request); |
| 46 | |
| 47 | // Now decode it back, and verify the encoding was correct. |
| 48 | ResponseDecoder decoder; |
| 49 | deque<http::Response*> responses = |
| 50 | decoder.decode(encoded.data(), encoded.length()); |
| 51 | |
| 52 | ASSERT_FALSE(decoder.failed()); |
| 53 | ASSERT_EQ(1u, responses.size()); |
| 54 | |
| 55 | Owned<http::Response> decoded(responses[0]); |
| 56 | EXPECT_EQ("200 OK", decoded->status); |
| 57 | EXPECT_EQ("body", decoded->body); |
| 58 | |
| 59 | // Encoding should have inserted the 'Date', 'Content-Length' and |
| 60 | // 'Content-Type' headers. |
| 61 | EXPECT_EQ(3u, decoded->headers.size()); |
| 62 | EXPECT_TRUE(decoded->headers.contains("Date")); |
| 63 | EXPECT_SOME_EQ( |
| 64 | stringify(response.body.size()), |
| 65 | decoded->headers.get("Content-Length")); |
| 66 | EXPECT_SOME_EQ( |
| 67 | "text/plain; charset=utf-8", |
| 68 | decoded->headers.get("Content-Type")); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | TEST(EncoderTest, AcceptableEncodings) |