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 <algorithm> |
5 #include <utility> | 6 #include <utility> |
6 #include <vector> | 7 #include <vector> |
7 | 8 |
8 #include "base/bind.h" | 9 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback_helpers.h" |
10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
11 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
16 #include "base/message_loop/message_loop_proxy.h" | 18 #include "base/message_loop/message_loop_proxy.h" |
17 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
18 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
19 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
20 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
21 #include "base/time/time.h" | 23 #include "base/time/time.h" |
22 #include "net/base/address_list.h" | 24 #include "net/base/address_list.h" |
23 #include "net/base/io_buffer.h" | 25 #include "net/base/io_buffer.h" |
24 #include "net/base/ip_endpoint.h" | 26 #include "net/base/ip_endpoint.h" |
25 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
26 #include "net/base/net_log.h" | 28 #include "net/base/net_log.h" |
| 29 #include "net/base/net_util.h" |
27 #include "net/base/test_completion_callback.h" | 30 #include "net/base/test_completion_callback.h" |
| 31 #include "net/http/http_response_headers.h" |
| 32 #include "net/http/http_util.h" |
28 #include "net/server/http_server.h" | 33 #include "net/server/http_server.h" |
29 #include "net/server/http_server_request_info.h" | 34 #include "net/server/http_server_request_info.h" |
30 #include "net/socket/tcp_client_socket.h" | 35 #include "net/socket/tcp_client_socket.h" |
31 #include "net/socket/tcp_listen_socket.h" | 36 #include "net/socket/tcp_server_socket.h" |
32 #include "net/url_request/url_fetcher.h" | 37 #include "net/url_request/url_fetcher.h" |
33 #include "net/url_request/url_fetcher_delegate.h" | 38 #include "net/url_request/url_fetcher_delegate.h" |
34 #include "net/url_request/url_request_context.h" | 39 #include "net/url_request/url_request_context.h" |
35 #include "net/url_request/url_request_context_getter.h" | 40 #include "net/url_request/url_request_context_getter.h" |
36 #include "net/url_request/url_request_test_util.h" | 41 #include "net/url_request/url_request_test_util.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
38 | 43 |
39 namespace net { | 44 namespace net { |
40 | 45 |
41 namespace { | 46 namespace { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 return ERR_TIMED_OUT; | 88 return ERR_TIMED_OUT; |
84 return connect_result_; | 89 return connect_result_; |
85 } | 90 } |
86 | 91 |
87 void Send(const std::string& data) { | 92 void Send(const std::string& data) { |
88 write_buffer_ = | 93 write_buffer_ = |
89 new DrainableIOBuffer(new StringIOBuffer(data), data.length()); | 94 new DrainableIOBuffer(new StringIOBuffer(data), data.length()); |
90 Write(); | 95 Write(); |
91 } | 96 } |
92 | 97 |
93 bool Read(std::string* message) { | |
94 return Read(message, 1); | |
95 } | |
96 | |
97 bool Read(std::string* message, int expected_bytes) { | 98 bool Read(std::string* message, int expected_bytes) { |
98 int total_bytes_received = 0; | 99 int total_bytes_received = 0; |
99 message->clear(); | 100 message->clear(); |
100 while (total_bytes_received < expected_bytes) { | 101 while (total_bytes_received < expected_bytes) { |
101 net::TestCompletionCallback callback; | 102 net::TestCompletionCallback callback; |
102 ReadInternal(callback.callback()); | 103 ReadInternal(callback.callback()); |
103 int bytes_received = callback.WaitForResult(); | 104 int bytes_received = callback.WaitForResult(); |
104 if (bytes_received <= 0) | 105 if (bytes_received <= 0) |
105 return false; | 106 return false; |
106 | 107 |
107 total_bytes_received += bytes_received; | 108 total_bytes_received += bytes_received; |
108 message->append(read_buffer_->data(), bytes_received); | 109 message->append(read_buffer_->data(), bytes_received); |
109 } | 110 } |
110 return true; | 111 return true; |
111 } | 112 } |
112 | 113 |
| 114 bool ReadResponse(std::string* message) { |
| 115 if (!Read(message, 1)) |
| 116 return false; |
| 117 while (!IsCompleteResponse(*message)) { |
| 118 std::string chunk; |
| 119 if (!Read(&chunk, 1)) |
| 120 return false; |
| 121 message->append(chunk); |
| 122 } |
| 123 return true; |
| 124 } |
| 125 |
113 private: | 126 private: |
114 void OnConnect(const base::Closure& quit_loop, int result) { | 127 void OnConnect(const base::Closure& quit_loop, int result) { |
115 connect_result_ = result; | 128 connect_result_ = result; |
116 quit_loop.Run(); | 129 quit_loop.Run(); |
117 } | 130 } |
118 | 131 |
119 void Write() { | 132 void Write() { |
120 int result = socket_->Write( | 133 int result = socket_->Write( |
121 write_buffer_.get(), | 134 write_buffer_.get(), |
122 write_buffer_->BytesRemaining(), | 135 write_buffer_->BytesRemaining(), |
(...skipping 11 matching lines...) Expand all Loading... |
134 | 147 |
135 void ReadInternal(const net::CompletionCallback& callback) { | 148 void ReadInternal(const net::CompletionCallback& callback) { |
136 read_buffer_ = new IOBufferWithSize(kMaxExpectedResponseLength); | 149 read_buffer_ = new IOBufferWithSize(kMaxExpectedResponseLength); |
137 int result = socket_->Read(read_buffer_, | 150 int result = socket_->Read(read_buffer_, |
138 kMaxExpectedResponseLength, | 151 kMaxExpectedResponseLength, |
139 callback); | 152 callback); |
140 if (result != ERR_IO_PENDING) | 153 if (result != ERR_IO_PENDING) |
141 callback.Run(result); | 154 callback.Run(result); |
142 } | 155 } |
143 | 156 |
| 157 bool IsCompleteResponse(const std::string& response) { |
| 158 // Check end of headers first. |
| 159 int end_of_headers = HttpUtil::LocateEndOfHeaders(response.data(), |
| 160 response.size()); |
| 161 if (end_of_headers < 0) |
| 162 return false; |
| 163 |
| 164 // Return true if response has data equal to or more than content length. |
| 165 int64 body_size = static_cast<int64>(response.size()) - end_of_headers; |
| 166 DCHECK_LE(0, body_size); |
| 167 scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders( |
| 168 HttpUtil::AssembleRawHeaders(response.data(), end_of_headers))); |
| 169 return body_size >= headers->GetContentLength(); |
| 170 } |
| 171 |
144 scoped_refptr<IOBufferWithSize> read_buffer_; | 172 scoped_refptr<IOBufferWithSize> read_buffer_; |
145 scoped_refptr<DrainableIOBuffer> write_buffer_; | 173 scoped_refptr<DrainableIOBuffer> write_buffer_; |
146 scoped_ptr<TCPClientSocket> socket_; | 174 scoped_ptr<TCPClientSocket> socket_; |
147 int connect_result_; | 175 int connect_result_; |
148 }; | 176 }; |
149 | 177 |
150 } // namespace | 178 } // namespace |
151 | 179 |
152 class HttpServerTest : public testing::Test, | 180 class HttpServerTest : public testing::Test, |
153 public HttpServer::Delegate { | 181 public HttpServer::Delegate { |
154 public: | 182 public: |
155 HttpServerTest() : quit_after_request_count_(0) {} | 183 HttpServerTest() : quit_after_request_count_(0) {} |
156 | 184 |
157 virtual void SetUp() OVERRIDE { | 185 virtual void SetUp() OVERRIDE { |
158 TCPListenSocketFactory socket_factory("127.0.0.1", 0); | 186 scoped_ptr<ServerSocket> server_socket( |
159 server_ = new HttpServer(socket_factory, this); | 187 new TCPServerSocket(NULL, net::NetLog::Source())); |
| 188 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); |
| 189 server_.reset(new HttpServer(server_socket.Pass(), this)); |
160 ASSERT_EQ(OK, server_->GetLocalAddress(&server_address_)); | 190 ASSERT_EQ(OK, server_->GetLocalAddress(&server_address_)); |
161 } | 191 } |
162 | 192 |
163 virtual void OnHttpRequest(int connection_id, | 193 virtual void OnHttpRequest(int connection_id, |
164 const HttpServerRequestInfo& info) OVERRIDE { | 194 const HttpServerRequestInfo& info) OVERRIDE { |
165 requests_.push_back(std::make_pair(info, connection_id)); | 195 requests_.push_back(std::make_pair(info, connection_id)); |
166 if (requests_.size() == quit_after_request_count_) | 196 if (requests_.size() == quit_after_request_count_) |
167 run_loop_quit_func_.Run(); | 197 run_loop_quit_func_.Run(); |
168 } | 198 } |
169 | 199 |
(...skipping 22 matching lines...) Expand all Loading... |
192 } | 222 } |
193 | 223 |
194 HttpServerRequestInfo GetRequest(size_t request_index) { | 224 HttpServerRequestInfo GetRequest(size_t request_index) { |
195 return requests_[request_index].first; | 225 return requests_[request_index].first; |
196 } | 226 } |
197 | 227 |
198 int GetConnectionId(size_t request_index) { | 228 int GetConnectionId(size_t request_index) { |
199 return requests_[request_index].second; | 229 return requests_[request_index].second; |
200 } | 230 } |
201 | 231 |
| 232 void HandleAcceptResult(scoped_ptr<StreamSocket> socket) { |
| 233 server_->accepted_socket_.reset(socket.release()); |
| 234 server_->HandleAcceptResult(OK); |
| 235 } |
| 236 |
202 protected: | 237 protected: |
203 scoped_refptr<HttpServer> server_; | 238 scoped_ptr<HttpServer> server_; |
204 IPEndPoint server_address_; | 239 IPEndPoint server_address_; |
205 base::Closure run_loop_quit_func_; | 240 base::Closure run_loop_quit_func_; |
206 std::vector<std::pair<HttpServerRequestInfo, int> > requests_; | 241 std::vector<std::pair<HttpServerRequestInfo, int> > requests_; |
207 | 242 |
208 private: | 243 private: |
209 size_t quit_after_request_count_; | 244 size_t quit_after_request_count_; |
210 }; | 245 }; |
211 | 246 |
212 class WebSocketTest : public HttpServerTest { | 247 class WebSocketTest : public HttpServerTest { |
213 virtual void OnHttpRequest(int connection_id, | 248 virtual void OnHttpRequest(int connection_id, |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 435 } |
401 | 436 |
402 TEST_F(HttpServerTest, Send200) { | 437 TEST_F(HttpServerTest, Send200) { |
403 TestHttpClient client; | 438 TestHttpClient client; |
404 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 439 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); |
405 client.Send("GET /test HTTP/1.1\r\n\r\n"); | 440 client.Send("GET /test HTTP/1.1\r\n\r\n"); |
406 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 441 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
407 server_->Send200(GetConnectionId(0), "Response!", "text/plain"); | 442 server_->Send200(GetConnectionId(0), "Response!", "text/plain"); |
408 | 443 |
409 std::string response; | 444 std::string response; |
410 ASSERT_TRUE(client.Read(&response)); | 445 ASSERT_TRUE(client.ReadResponse(&response)); |
411 ASSERT_TRUE(StartsWithASCII(response, "HTTP/1.1 200 OK", true)); | 446 ASSERT_TRUE(StartsWithASCII(response, "HTTP/1.1 200 OK", true)); |
412 ASSERT_TRUE(EndsWith(response, "Response!", true)); | 447 ASSERT_TRUE(EndsWith(response, "Response!", true)); |
413 } | 448 } |
414 | 449 |
415 TEST_F(HttpServerTest, SendRaw) { | 450 TEST_F(HttpServerTest, SendRaw) { |
416 TestHttpClient client; | 451 TestHttpClient client; |
417 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 452 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); |
418 client.Send("GET /test HTTP/1.1\r\n\r\n"); | 453 client.Send("GET /test HTTP/1.1\r\n\r\n"); |
419 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 454 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
420 server_->SendRaw(GetConnectionId(0), "Raw Data "); | 455 server_->SendRaw(GetConnectionId(0), "Raw Data "); |
421 server_->SendRaw(GetConnectionId(0), "More Data"); | 456 server_->SendRaw(GetConnectionId(0), "More Data"); |
422 server_->SendRaw(GetConnectionId(0), "Third Piece of Data"); | 457 server_->SendRaw(GetConnectionId(0), "Third Piece of Data"); |
423 | 458 |
424 const std::string expected_response("Raw Data More DataThird Piece of Data"); | 459 const std::string expected_response("Raw Data More DataThird Piece of Data"); |
425 std::string response; | 460 std::string response; |
426 ASSERT_TRUE(client.Read(&response, expected_response.length())); | 461 ASSERT_TRUE(client.Read(&response, expected_response.length())); |
427 ASSERT_EQ(expected_response, response); | 462 ASSERT_EQ(expected_response, response); |
428 } | 463 } |
429 | 464 |
430 namespace { | 465 namespace { |
431 | 466 |
432 class MockStreamListenSocket : public StreamListenSocket { | 467 class MockStreamSocket : public StreamSocket { |
433 public: | 468 public: |
434 MockStreamListenSocket(StreamListenSocket::Delegate* delegate) | 469 MockStreamSocket() |
435 : StreamListenSocket(kInvalidSocket, delegate) {} | 470 : connected_(true), |
| 471 read_buf_(NULL), |
| 472 read_buf_len_(0) {} |
436 | 473 |
437 virtual void Accept() OVERRIDE { NOTREACHED(); } | 474 // StreamSocket |
| 475 virtual int Connect(const CompletionCallback& callback) OVERRIDE { |
| 476 return ERR_NOT_IMPLEMENTED; |
| 477 } |
| 478 virtual void Disconnect() OVERRIDE { |
| 479 connected_ = false; |
| 480 if (!read_callback_.is_null()) { |
| 481 read_buf_ = NULL; |
| 482 read_buf_len_ = 0; |
| 483 base::ResetAndReturn(&read_callback_).Run(ERR_CONNECTION_CLOSED); |
| 484 } |
| 485 } |
| 486 virtual bool IsConnected() const OVERRIDE { return connected_; } |
| 487 virtual bool IsConnectedAndIdle() const OVERRIDE { return IsConnected(); } |
| 488 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { |
| 489 return ERR_NOT_IMPLEMENTED; |
| 490 } |
| 491 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { |
| 492 return ERR_NOT_IMPLEMENTED; |
| 493 } |
| 494 virtual const BoundNetLog& NetLog() const OVERRIDE { return net_log_; } |
| 495 virtual void SetSubresourceSpeculation() OVERRIDE {} |
| 496 virtual void SetOmniboxSpeculation() OVERRIDE {} |
| 497 virtual bool WasEverUsed() const OVERRIDE { return true; } |
| 498 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } |
| 499 virtual bool WasNpnNegotiated() const OVERRIDE { return false; } |
| 500 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { |
| 501 return kProtoUnknown; |
| 502 } |
| 503 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { return false; } |
| 504 |
| 505 // Socket |
| 506 virtual int Read(IOBuffer* buf, int buf_len, |
| 507 const CompletionCallback& callback) OVERRIDE { |
| 508 if (!connected_) { |
| 509 return ERR_SOCKET_NOT_CONNECTED; |
| 510 } |
| 511 if (pending_read_data_.empty()) { |
| 512 read_buf_ = buf; |
| 513 read_buf_len_ = buf_len; |
| 514 read_callback_ = callback; |
| 515 return ERR_IO_PENDING; |
| 516 } |
| 517 DCHECK_GT(buf_len, 0); |
| 518 int read_len = std::min(static_cast<int>(pending_read_data_.size()), |
| 519 buf_len); |
| 520 memcpy(buf->data(), pending_read_data_.data(), read_len); |
| 521 pending_read_data_.erase(0, read_len); |
| 522 return read_len; |
| 523 } |
| 524 virtual int Write(IOBuffer* buf, int buf_len, |
| 525 const CompletionCallback& callback) OVERRIDE { |
| 526 return ERR_NOT_IMPLEMENTED; |
| 527 } |
| 528 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { |
| 529 return ERR_NOT_IMPLEMENTED; |
| 530 } |
| 531 virtual int SetSendBufferSize(int32 size) OVERRIDE { |
| 532 return ERR_NOT_IMPLEMENTED; |
| 533 } |
| 534 |
| 535 void DidRead(const char* data, int data_len) { |
| 536 if (!read_buf_) { |
| 537 pending_read_data_.append(data, data_len); |
| 538 return; |
| 539 } |
| 540 int read_len = std::min(data_len, read_buf_len_); |
| 541 memcpy(read_buf_->data(), data, read_len); |
| 542 pending_read_data_.assign(data + read_len, data_len - read_len); |
| 543 read_buf_ = NULL; |
| 544 read_buf_len_ = 0; |
| 545 base::ResetAndReturn(&read_callback_).Run(read_len); |
| 546 } |
438 | 547 |
439 private: | 548 private: |
440 virtual ~MockStreamListenSocket() {} | 549 virtual ~MockStreamSocket() {} |
| 550 |
| 551 bool connected_; |
| 552 scoped_refptr<IOBuffer> read_buf_; |
| 553 int read_buf_len_; |
| 554 CompletionCallback read_callback_; |
| 555 std::string pending_read_data_; |
| 556 BoundNetLog net_log_; |
| 557 |
| 558 DISALLOW_COPY_AND_ASSIGN(MockStreamSocket); |
441 }; | 559 }; |
442 | 560 |
443 } // namespace | 561 } // namespace |
444 | 562 |
445 TEST_F(HttpServerTest, RequestWithBodySplitAcrossPackets) { | 563 TEST_F(HttpServerTest, RequestWithBodySplitAcrossPackets) { |
446 StreamListenSocket* socket = | 564 MockStreamSocket* socket = new MockStreamSocket(); |
447 new MockStreamListenSocket(server_.get()); | 565 HandleAcceptResult(make_scoped_ptr<StreamSocket>(socket)); |
448 server_->DidAccept(NULL, make_scoped_ptr(socket)); | |
449 std::string body("body"); | 566 std::string body("body"); |
450 std::string request_text = base::StringPrintf( | 567 std::string request_text = base::StringPrintf( |
451 "GET /test HTTP/1.1\r\n" | 568 "GET /test HTTP/1.1\r\n" |
452 "SomeHeader: 1\r\n" | 569 "SomeHeader: 1\r\n" |
453 "Content-Length: %" PRIuS "\r\n\r\n%s", | 570 "Content-Length: %" PRIuS "\r\n\r\n%s", |
454 body.length(), | 571 body.length(), |
455 body.c_str()); | 572 body.c_str()); |
456 server_->DidRead(socket, request_text.c_str(), request_text.length() - 2); | 573 socket->DidRead(request_text.c_str(), request_text.length() - 2); |
457 ASSERT_EQ(0u, requests_.size()); | 574 ASSERT_EQ(0u, requests_.size()); |
458 server_->DidRead(socket, request_text.c_str() + request_text.length() - 2, 2); | 575 socket->DidRead(request_text.c_str() + request_text.length() - 2, 2); |
459 ASSERT_EQ(1u, requests_.size()); | 576 ASSERT_EQ(1u, requests_.size()); |
460 ASSERT_EQ(body, GetRequest(0).data); | 577 ASSERT_EQ(body, GetRequest(0).data); |
461 } | 578 } |
462 | 579 |
463 TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) { | 580 TEST_F(HttpServerTest, MultipleRequestsOnSameConnection) { |
464 // The idea behind this test is that requests with or without bodies should | 581 // The idea behind this test is that requests with or without bodies should |
465 // not break parsing of the next request. | 582 // not break parsing of the next request. |
466 TestHttpClient client; | 583 TestHttpClient client; |
467 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); | 584 ASSERT_EQ(OK, client.ConnectAndWait(server_address_)); |
468 std::string body = "body"; | 585 std::string body = "body"; |
469 client.Send(base::StringPrintf( | 586 client.Send(base::StringPrintf( |
470 "GET /test HTTP/1.1\r\n" | 587 "GET /test HTTP/1.1\r\n" |
471 "Content-Length: %" PRIuS "\r\n\r\n%s", | 588 "Content-Length: %" PRIuS "\r\n\r\n%s", |
472 body.length(), | 589 body.length(), |
473 body.c_str())); | 590 body.c_str())); |
474 ASSERT_TRUE(RunUntilRequestsReceived(1)); | 591 ASSERT_TRUE(RunUntilRequestsReceived(1)); |
475 ASSERT_EQ(body, GetRequest(0).data); | 592 ASSERT_EQ(body, GetRequest(0).data); |
476 | 593 |
477 int client_connection_id = GetConnectionId(0); | 594 int client_connection_id = GetConnectionId(0); |
478 server_->Send200(client_connection_id, "Content for /test", "text/plain"); | 595 server_->Send200(client_connection_id, "Content for /test", "text/plain"); |
479 std::string response1; | 596 std::string response1; |
480 ASSERT_TRUE(client.Read(&response1)); | 597 ASSERT_TRUE(client.ReadResponse(&response1)); |
481 ASSERT_TRUE(StartsWithASCII(response1, "HTTP/1.1 200 OK", true)); | 598 ASSERT_TRUE(StartsWithASCII(response1, "HTTP/1.1 200 OK", true)); |
482 ASSERT_TRUE(EndsWith(response1, "Content for /test", true)); | 599 ASSERT_TRUE(EndsWith(response1, "Content for /test", true)); |
483 | 600 |
484 client.Send("GET /test2 HTTP/1.1\r\n\r\n"); | 601 client.Send("GET /test2 HTTP/1.1\r\n\r\n"); |
485 ASSERT_TRUE(RunUntilRequestsReceived(2)); | 602 ASSERT_TRUE(RunUntilRequestsReceived(2)); |
486 ASSERT_EQ("/test2", GetRequest(1).path); | 603 ASSERT_EQ("/test2", GetRequest(1).path); |
487 | 604 |
488 ASSERT_EQ(client_connection_id, GetConnectionId(1)); | 605 ASSERT_EQ(client_connection_id, GetConnectionId(1)); |
489 server_->Send404(client_connection_id); | 606 server_->Send404(client_connection_id); |
490 std::string response2; | 607 std::string response2; |
491 ASSERT_TRUE(client.Read(&response2)); | 608 ASSERT_TRUE(client.ReadResponse(&response2)); |
492 ASSERT_TRUE(StartsWithASCII(response2, "HTTP/1.1 404 Not Found", true)); | 609 ASSERT_TRUE(StartsWithASCII(response2, "HTTP/1.1 404 Not Found", true)); |
493 | 610 |
494 client.Send("GET /test3 HTTP/1.1\r\n\r\n"); | 611 client.Send("GET /test3 HTTP/1.1\r\n\r\n"); |
495 ASSERT_TRUE(RunUntilRequestsReceived(3)); | 612 ASSERT_TRUE(RunUntilRequestsReceived(3)); |
496 ASSERT_EQ("/test3", GetRequest(2).path); | 613 ASSERT_EQ("/test3", GetRequest(2).path); |
497 | 614 |
498 ASSERT_EQ(client_connection_id, GetConnectionId(2)); | 615 ASSERT_EQ(client_connection_id, GetConnectionId(2)); |
499 server_->Send200(client_connection_id, "Content for /test3", "text/plain"); | 616 server_->Send200(client_connection_id, "Content for /test3", "text/plain"); |
500 std::string response3; | 617 std::string response3; |
501 ASSERT_TRUE(client.Read(&response3)); | 618 ASSERT_TRUE(client.ReadResponse(&response3)); |
502 ASSERT_TRUE(StartsWithASCII(response3, "HTTP/1.1 200 OK", true)); | 619 ASSERT_TRUE(StartsWithASCII(response3, "HTTP/1.1 200 OK", true)); |
503 #if 0 | |
504 // TODO(byungchul): Figure out why it fails in windows build bot. | |
505 ASSERT_TRUE(EndsWith(response3, "Content for /test3", true)); | 620 ASSERT_TRUE(EndsWith(response3, "Content for /test3", true)); |
506 #endif | |
507 } | 621 } |
508 | 622 |
509 } // namespace net | 623 } // namespace net |
OLD | NEW |