OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/server/http_server.h" | 5 #include "net/server/http_server.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "net/base/io_buffer.h" | 33 #include "net/base/io_buffer.h" |
34 #include "net/base/ip_endpoint.h" | 34 #include "net/base/ip_endpoint.h" |
35 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
36 #include "net/base/test_completion_callback.h" | 36 #include "net/base/test_completion_callback.h" |
37 #include "net/http/http_response_headers.h" | 37 #include "net/http/http_response_headers.h" |
38 #include "net/http/http_util.h" | 38 #include "net/http/http_util.h" |
39 #include "net/log/net_log.h" | 39 #include "net/log/net_log.h" |
40 #include "net/server/http_server_request_info.h" | 40 #include "net/server/http_server_request_info.h" |
41 #include "net/socket/tcp_client_socket.h" | 41 #include "net/socket/tcp_client_socket.h" |
42 #include "net/socket/tcp_server_socket.h" | 42 #include "net/socket/tcp_server_socket.h" |
| 43 #include "net/test/gtest_util.h" |
43 #include "net/url_request/url_fetcher.h" | 44 #include "net/url_request/url_fetcher.h" |
44 #include "net/url_request/url_fetcher_delegate.h" | 45 #include "net/url_request/url_fetcher_delegate.h" |
45 #include "net/url_request/url_request_context.h" | 46 #include "net/url_request/url_request_context.h" |
46 #include "net/url_request/url_request_context_getter.h" | 47 #include "net/url_request/url_request_context_getter.h" |
47 #include "net/url_request/url_request_test_util.h" | 48 #include "net/url_request/url_request_test_util.h" |
| 49 #include "testing/gmock/include/gmock/gmock.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 50 #include "testing/gtest/include/gtest/gtest.h" |
49 | 51 |
| 52 using net::test::IsOk; |
| 53 |
50 namespace net { | 54 namespace net { |
51 | 55 |
52 namespace { | 56 namespace { |
53 | 57 |
54 const int kMaxExpectedResponseLength = 2048; | 58 const int kMaxExpectedResponseLength = 2048; |
55 | 59 |
56 void SetTimedOutAndQuitLoop(const base::WeakPtr<bool> timed_out, | 60 void SetTimedOutAndQuitLoop(const base::WeakPtr<bool> timed_out, |
57 const base::Closure& quit_loop_func) { | 61 const base::Closure& quit_loop_func) { |
58 if (timed_out) { | 62 if (timed_out) { |
59 *timed_out = true; | 63 *timed_out = true; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 class HttpServerTest : public testing::Test, | 188 class HttpServerTest : public testing::Test, |
185 public HttpServer::Delegate { | 189 public HttpServer::Delegate { |
186 public: | 190 public: |
187 HttpServerTest() : quit_after_request_count_(0) {} | 191 HttpServerTest() : quit_after_request_count_(0) {} |
188 | 192 |
189 void SetUp() override { | 193 void SetUp() override { |
190 std::unique_ptr<ServerSocket> server_socket( | 194 std::unique_ptr<ServerSocket> server_socket( |
191 new TCPServerSocket(NULL, NetLog::Source())); | 195 new TCPServerSocket(NULL, NetLog::Source())); |
192 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); | 196 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); |
193 server_.reset(new HttpServer(std::move(server_socket), this)); | 197 server_.reset(new HttpServer(std::move(server_socket), this)); |
194 ASSERT_EQ(OK, server_->GetLocalAddress(&server_address_)); | 198 ASSERT_THAT(server_->GetLocalAddress(&server_address_), IsOk()); |
195 } | 199 } |
196 | 200 |
197 void OnConnect(int connection_id) override {} | 201 void OnConnect(int connection_id) override {} |
198 | 202 |
199 void OnHttpRequest(int connection_id, | 203 void OnHttpRequest(int connection_id, |
200 const HttpServerRequestInfo& info) override { | 204 const HttpServerRequestInfo& info) override { |
201 requests_.push_back(std::make_pair(info, connection_id)); | 205 requests_.push_back(std::make_pair(info, connection_id)); |
202 if (requests_.size() == quit_after_request_count_) | 206 if (requests_.size() == quit_after_request_count_) |
203 run_loop_quit_func_.Run(); | 207 run_loop_quit_func_.Run(); |
204 } | 208 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 const HttpServerRequestInfo& info) override { | 265 const HttpServerRequestInfo& info) override { |
262 HttpServerTest::OnHttpRequest(connection_id, info); | 266 HttpServerTest::OnHttpRequest(connection_id, info); |
263 } | 267 } |
264 | 268 |
265 void OnWebSocketMessage(int connection_id, const std::string& data) override { | 269 void OnWebSocketMessage(int connection_id, const std::string& data) override { |
266 } | 270 } |
267 }; | 271 }; |
268 | 272 |
269 TEST_F(HttpServerTest, Request) { | 273 TEST_F(HttpServerTest, Request) { |
270 TestHttpClient client; | 274 TestHttpClient client; |
271 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 275 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
272 client.Send("GET /test HTTP/1.1\r\n\r\n"); | 276 client.Send("GET /test HTTP/1.1\r\n\r\n"); |
273 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 277 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
274 ASSERT_EQ("GET", GetRequest(0).method); | 278 ASSERT_EQ("GET", GetRequest(0).method); |
275 ASSERT_EQ("/test", GetRequest(0).path); | 279 ASSERT_EQ("/test", GetRequest(0).path); |
276 ASSERT_EQ("", GetRequest(0).data); | 280 ASSERT_EQ("", GetRequest(0).data); |
277 ASSERT_EQ(0u, GetRequest(0).headers.size()); | 281 ASSERT_EQ(0u, GetRequest(0).headers.size()); |
278 ASSERT_TRUE(base::StartsWith(GetRequest(0).peer.ToString(), "127.0.0.1", | 282 ASSERT_TRUE(base::StartsWith(GetRequest(0).peer.ToString(), "127.0.0.1", |
279 base::CompareCase::SENSITIVE)); | 283 base::CompareCase::SENSITIVE)); |
280 } | 284 } |
281 | 285 |
282 TEST_F(HttpServerTest, RequestWithHeaders) { | 286 TEST_F(HttpServerTest, RequestWithHeaders) { |
283 TestHttpClient client; | 287 TestHttpClient client; |
284 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 288 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
285 const char* const kHeaders[][3] = { | 289 const char* const kHeaders[][3] = { |
286 {"Header", ": ", "1"}, | 290 {"Header", ": ", "1"}, |
287 {"HeaderWithNoWhitespace", ":", "1"}, | 291 {"HeaderWithNoWhitespace", ":", "1"}, |
288 {"HeaderWithWhitespace", " : \t ", "1 1 1 \t "}, | 292 {"HeaderWithWhitespace", " : \t ", "1 1 1 \t "}, |
289 {"HeaderWithColon", ": ", "1:1"}, | 293 {"HeaderWithColon", ": ", "1:1"}, |
290 {"EmptyHeader", ":", ""}, | 294 {"EmptyHeader", ":", ""}, |
291 {"EmptyHeaderWithWhitespace", ": \t ", ""}, | 295 {"EmptyHeaderWithWhitespace", ": \t ", ""}, |
292 {"HeaderWithNonASCII", ": ", "\xf7"}, | 296 {"HeaderWithNonASCII", ": ", "\xf7"}, |
293 }; | 297 }; |
294 std::string headers; | 298 std::string headers; |
295 for (size_t i = 0; i < arraysize(kHeaders); ++i) { | 299 for (size_t i = 0; i < arraysize(kHeaders); ++i) { |
296 headers += | 300 headers += |
297 std::string(kHeaders[i][0]) + kHeaders[i][1] + kHeaders[i][2] + "\r\n"; | 301 std::string(kHeaders[i][0]) + kHeaders[i][1] + kHeaders[i][2] + "\r\n"; |
298 } | 302 } |
299 | 303 |
300 client.Send("GET /test HTTP/1.1\r\n" + headers + "\r\n"); | 304 client.Send("GET /test HTTP/1.1\r\n" + headers + "\r\n"); |
301 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 305 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
302 ASSERT_EQ("", GetRequest(0).data); | 306 ASSERT_EQ("", GetRequest(0).data); |
303 | 307 |
304 for (size_t i = 0; i < arraysize(kHeaders); ++i) { | 308 for (size_t i = 0; i < arraysize(kHeaders); ++i) { |
305 std::string field = base::ToLowerASCII(std::string(kHeaders[i][0])); | 309 std::string field = base::ToLowerASCII(std::string(kHeaders[i][0])); |
306 std::string value = kHeaders[i][2]; | 310 std::string value = kHeaders[i][2]; |
307 ASSERT_EQ(1u, GetRequest(0).headers.count(field)) << field; | 311 ASSERT_EQ(1u, GetRequest(0).headers.count(field)) << field; |
308 ASSERT_EQ(value, GetRequest(0).headers[field]) << kHeaders[i][0]; | 312 ASSERT_EQ(value, GetRequest(0).headers[field]) << kHeaders[i][0]; |
309 } | 313 } |
310 } | 314 } |
311 | 315 |
312 TEST_F(HttpServerTest, RequestWithDuplicateHeaders) { | 316 TEST_F(HttpServerTest, RequestWithDuplicateHeaders) { |
313 TestHttpClient client; | 317 TestHttpClient client; |
314 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 318 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
315 const char* const kHeaders[][3] = { | 319 const char* const kHeaders[][3] = { |
316 {"FirstHeader", ": ", "1"}, | 320 {"FirstHeader", ": ", "1"}, |
317 {"DuplicateHeader", ": ", "2"}, | 321 {"DuplicateHeader", ": ", "2"}, |
318 {"MiddleHeader", ": ", "3"}, | 322 {"MiddleHeader", ": ", "3"}, |
319 {"DuplicateHeader", ": ", "4"}, | 323 {"DuplicateHeader", ": ", "4"}, |
320 {"LastHeader", ": ", "5"}, | 324 {"LastHeader", ": ", "5"}, |
321 }; | 325 }; |
322 std::string headers; | 326 std::string headers; |
323 for (size_t i = 0; i < arraysize(kHeaders); ++i) { | 327 for (size_t i = 0; i < arraysize(kHeaders); ++i) { |
324 headers += | 328 headers += |
325 std::string(kHeaders[i][0]) + kHeaders[i][1] + kHeaders[i][2] + "\r\n"; | 329 std::string(kHeaders[i][0]) + kHeaders[i][1] + kHeaders[i][2] + "\r\n"; |
326 } | 330 } |
327 | 331 |
328 client.Send("GET /test HTTP/1.1\r\n" + headers + "\r\n"); | 332 client.Send("GET /test HTTP/1.1\r\n" + headers + "\r\n"); |
329 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 333 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
330 ASSERT_EQ("", GetRequest(0).data); | 334 ASSERT_EQ("", GetRequest(0).data); |
331 | 335 |
332 for (size_t i = 0; i < arraysize(kHeaders); ++i) { | 336 for (size_t i = 0; i < arraysize(kHeaders); ++i) { |
333 std::string field = base::ToLowerASCII(std::string(kHeaders[i][0])); | 337 std::string field = base::ToLowerASCII(std::string(kHeaders[i][0])); |
334 std::string value = (field == "duplicateheader") ? "2,4" : kHeaders[i][2]; | 338 std::string value = (field == "duplicateheader") ? "2,4" : kHeaders[i][2]; |
335 ASSERT_EQ(1u, GetRequest(0).headers.count(field)) << field; | 339 ASSERT_EQ(1u, GetRequest(0).headers.count(field)) << field; |
336 ASSERT_EQ(value, GetRequest(0).headers[field]) << kHeaders[i][0]; | 340 ASSERT_EQ(value, GetRequest(0).headers[field]) << kHeaders[i][0]; |
337 } | 341 } |
338 } | 342 } |
339 | 343 |
340 TEST_F(HttpServerTest, HasHeaderValueTest) { | 344 TEST_F(HttpServerTest, HasHeaderValueTest) { |
341 TestHttpClient client; | 345 TestHttpClient client; |
342 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 346 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
343 const char* const kHeaders[] = { | 347 const char* const kHeaders[] = { |
344 "Header: Abcd", | 348 "Header: Abcd", |
345 "HeaderWithNoWhitespace:E", | 349 "HeaderWithNoWhitespace:E", |
346 "HeaderWithWhitespace : \t f \t ", | 350 "HeaderWithWhitespace : \t f \t ", |
347 "DuplicateHeader: g", | 351 "DuplicateHeader: g", |
348 "HeaderWithComma: h, i ,j", | 352 "HeaderWithComma: h, i ,j", |
349 "DuplicateHeader: k", | 353 "DuplicateHeader: k", |
350 "EmptyHeader:", | 354 "EmptyHeader:", |
351 "EmptyHeaderWithWhitespace: \t ", | 355 "EmptyHeaderWithWhitespace: \t ", |
352 "HeaderWithNonASCII: \xf7", | 356 "HeaderWithNonASCII: \xf7", |
(...skipping 16 matching lines...) Expand all Loading... |
369 ASSERT_TRUE(GetRequest(0).HasHeaderValue("headerwithcomma", "i")); | 373 ASSERT_TRUE(GetRequest(0).HasHeaderValue("headerwithcomma", "i")); |
370 ASSERT_TRUE(GetRequest(0).HasHeaderValue("headerwithcomma", "j")); | 374 ASSERT_TRUE(GetRequest(0).HasHeaderValue("headerwithcomma", "j")); |
371 ASSERT_TRUE(GetRequest(0).HasHeaderValue("duplicateheader", "k")); | 375 ASSERT_TRUE(GetRequest(0).HasHeaderValue("duplicateheader", "k")); |
372 ASSERT_FALSE(GetRequest(0).HasHeaderValue("emptyheader", "x")); | 376 ASSERT_FALSE(GetRequest(0).HasHeaderValue("emptyheader", "x")); |
373 ASSERT_FALSE(GetRequest(0).HasHeaderValue("emptyheaderwithwhitespace", "x")); | 377 ASSERT_FALSE(GetRequest(0).HasHeaderValue("emptyheaderwithwhitespace", "x")); |
374 ASSERT_TRUE(GetRequest(0).HasHeaderValue("headerwithnonascii", "\xf7")); | 378 ASSERT_TRUE(GetRequest(0).HasHeaderValue("headerwithnonascii", "\xf7")); |
375 } | 379 } |
376 | 380 |
377 TEST_F(HttpServerTest, RequestWithBody) { | 381 TEST_F(HttpServerTest, RequestWithBody) { |
378 TestHttpClient client; | 382 TestHttpClient client; |
379 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 383 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
380 std::string body = "a" + std::string(1 << 10, 'b') + "c"; | 384 std::string body = "a" + std::string(1 << 10, 'b') + "c"; |
381 client.Send(base::StringPrintf( | 385 client.Send(base::StringPrintf( |
382 "GET /test HTTP/1.1\r\n" | 386 "GET /test HTTP/1.1\r\n" |
383 "SomeHeader: 1\r\n" | 387 "SomeHeader: 1\r\n" |
384 "Content-Length: %" PRIuS "\r\n\r\n%s", | 388 "Content-Length: %" PRIuS "\r\n\r\n%s", |
385 body.length(), | 389 body.length(), |
386 body.c_str())); | 390 body.c_str())); |
387 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 391 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
388 ASSERT_EQ(2u, GetRequest(0).headers.size()); | 392 ASSERT_EQ(2u, GetRequest(0).headers.size()); |
389 ASSERT_EQ(body.length(), GetRequest(0).data.length()); | 393 ASSERT_EQ(body.length(), GetRequest(0).data.length()); |
390 ASSERT_EQ('a', body[0]); | 394 ASSERT_EQ('a', body[0]); |
391 ASSERT_EQ('c', *body.rbegin()); | 395 ASSERT_EQ('c', *body.rbegin()); |
392 } | 396 } |
393 | 397 |
394 TEST_F(WebSocketTest, RequestWebSocket) { | 398 TEST_F(WebSocketTest, RequestWebSocket) { |
395 TestHttpClient client; | 399 TestHttpClient client; |
396 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 400 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
397 client.Send( | 401 client.Send( |
398 "GET /test HTTP/1.1\r\n" | 402 "GET /test HTTP/1.1\r\n" |
399 "Upgrade: WebSocket\r\n" | 403 "Upgrade: WebSocket\r\n" |
400 "Connection: SomethingElse, Upgrade\r\n" | 404 "Connection: SomethingElse, Upgrade\r\n" |
401 "Sec-WebSocket-Version: 8\r\n" | 405 "Sec-WebSocket-Version: 8\r\n" |
402 "Sec-WebSocket-Key: key\r\n" | 406 "Sec-WebSocket-Key: key\r\n" |
403 "\r\n"); | 407 "\r\n"); |
404 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 408 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
405 } | 409 } |
406 | 410 |
(...skipping 26 matching lines...) Expand all Loading... |
433 fetcher->AddExtraRequestHeader( | 437 fetcher->AddExtraRequestHeader( |
434 base::StringPrintf("content-length:%d", 1 << 30)); | 438 base::StringPrintf("content-length:%d", 1 << 30)); |
435 fetcher->Start(); | 439 fetcher->Start(); |
436 | 440 |
437 ASSERT_TRUE(RunLoopWithTimeout(&run_loop)); | 441 ASSERT_TRUE(RunLoopWithTimeout(&run_loop)); |
438 ASSERT_EQ(0u, requests_.size()); | 442 ASSERT_EQ(0u, requests_.size()); |
439 } | 443 } |
440 | 444 |
441 TEST_F(HttpServerTest, Send200) { | 445 TEST_F(HttpServerTest, Send200) { |
442 TestHttpClient client; | 446 TestHttpClient client; |
443 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 447 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
444 client.Send("GET /test HTTP/1.1\r\n\r\n"); | 448 client.Send("GET /test HTTP/1.1\r\n\r\n"); |
445 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 449 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
446 server_->Send200(GetConnectionId(0), "Response!", "text/plain"); | 450 server_->Send200(GetConnectionId(0), "Response!", "text/plain"); |
447 | 451 |
448 std::string response; | 452 std::string response; |
449 ASSERT_TRUE(client.ReadResponse(&response)); | 453 ASSERT_TRUE(client.ReadResponse(&response)); |
450 ASSERT_TRUE(base::StartsWith(response, "HTTP/1.1 200 OK", | 454 ASSERT_TRUE(base::StartsWith(response, "HTTP/1.1 200 OK", |
451 base::CompareCase::SENSITIVE)); | 455 base::CompareCase::SENSITIVE)); |
452 ASSERT_TRUE( | 456 ASSERT_TRUE( |
453 base::EndsWith(response, "Response!", base::CompareCase::SENSITIVE)); | 457 base::EndsWith(response, "Response!", base::CompareCase::SENSITIVE)); |
454 } | 458 } |
455 | 459 |
456 TEST_F(HttpServerTest, SendRaw) { | 460 TEST_F(HttpServerTest, SendRaw) { |
457 TestHttpClient client; | 461 TestHttpClient client; |
458 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 462 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
459 client.Send("GET /test HTTP/1.1\r\n\r\n"); | 463 client.Send("GET /test HTTP/1.1\r\n\r\n"); |
460 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 464 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
461 server_->SendRaw(GetConnectionId(0), "Raw Data "); | 465 server_->SendRaw(GetConnectionId(0), "Raw Data "); |
462 server_->SendRaw(GetConnectionId(0), "More Data"); | 466 server_->SendRaw(GetConnectionId(0), "More Data"); |
463 server_->SendRaw(GetConnectionId(0), "Third Piece of Data"); | 467 server_->SendRaw(GetConnectionId(0), "Third Piece of Data"); |
464 | 468 |
465 const std::string expected_response("Raw Data More DataThird Piece of Data"); | 469 const std::string expected_response("Raw Data More DataThird Piece of Data"); |
466 std::string response; | 470 std::string response; |
467 ASSERT_TRUE(client.Read(&response, expected_response.length())); | 471 ASSERT_TRUE(client.Read(&response, expected_response.length())); |
468 ASSERT_EQ(expected_response, response); | 472 ASSERT_EQ(expected_response, response); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 ASSERT_EQ(0u, requests_.size()); | 586 ASSERT_EQ(0u, requests_.size()); |
583 socket->DidRead(request_text.c_str() + request_text.length() - 2, 2); | 587 socket->DidRead(request_text.c_str() + request_text.length() - 2, 2); |
584 ASSERT_EQ(1u, requests_.size()); | 588 ASSERT_EQ(1u, requests_.size()); |
585 ASSERT_EQ(body, GetRequest(0).data); | 589 ASSERT_EQ(body, GetRequest(0).data); |
586 } | 590 } |
587 | 591 |
588 TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) { | 592 TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) { |
589 // The idea behind this test is that requests with or without bodies should | 593 // The idea behind this test is that requests with or without bodies should |
590 // not break parsing of the next request. | 594 // not break parsing of the next request. |
591 TestHttpClient client; | 595 TestHttpClient client; |
592 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 596 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
593 std::string body = "body"; | 597 std::string body = "body"; |
594 client.Send(base::StringPrintf( | 598 client.Send(base::StringPrintf( |
595 "GET /test HTTP/1.1\r\n" | 599 "GET /test HTTP/1.1\r\n" |
596 "Content-Length: %" PRIuS "\r\n\r\n%s", | 600 "Content-Length: %" PRIuS "\r\n\r\n%s", |
597 body.length(), | 601 body.length(), |
598 body.c_str())); | 602 body.c_str())); |
599 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 603 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
600 ASSERT_EQ(body, GetRequest(0).data); | 604 ASSERT_EQ(body, GetRequest(0).data); |
601 | 605 |
602 int client_connection_id = GetConnectionId(0); | 606 int client_connection_id = GetConnectionId(0); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 connection_ids_.push_back(connection_id); | 643 connection_ids_.push_back(connection_id); |
640 server_->Close(connection_id); | 644 server_->Close(connection_id); |
641 } | 645 } |
642 | 646 |
643 protected: | 647 protected: |
644 std::vector<int> connection_ids_; | 648 std::vector<int> connection_ids_; |
645 }; | 649 }; |
646 | 650 |
647 TEST_F(CloseOnConnectHttpServerTest, ServerImmediatelyClosesConnection) { | 651 TEST_F(CloseOnConnectHttpServerTest, ServerImmediatelyClosesConnection) { |
648 TestHttpClient client; | 652 TestHttpClient client; |
649 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 653 ASSERT_THAT(client.ConnectAndWait(server_address_), IsOk()); |
650 client.Send("GET / HTTP/1.1\r\n\r\n"); | 654 client.Send("GET / HTTP/1.1\r\n\r\n"); |
651 ASSERT_FALSE(RunUntilRequestsReceived(1)); | 655 ASSERT_FALSE(RunUntilRequestsReceived(1)); |
652 ASSERT_EQ(1ul, connection_ids_.size()); | 656 ASSERT_EQ(1ul, connection_ids_.size()); |
653 ASSERT_EQ(0ul, requests_.size()); | 657 ASSERT_EQ(0ul, requests_.size()); |
654 } | 658 } |
655 | 659 |
656 } // namespace | 660 } // namespace |
657 | 661 |
658 } // namespace net | 662 } // namespace net |
OLD | NEW |