| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/http_stream_parser.h" | 5 #include "net/http/http_stream_parser.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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 public: | 72 public: |
| 73 enum class FailureMode { SYNC, ASYNC }; | 73 enum class FailureMode { SYNC, ASYNC }; |
| 74 | 74 |
| 75 explicit ReadErrorUploadDataStream(FailureMode mode) | 75 explicit ReadErrorUploadDataStream(FailureMode mode) |
| 76 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} | 76 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } | 79 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } |
| 80 | 80 |
| 81 // UploadDataStream implementation: | 81 // UploadDataStream implementation: |
| 82 int InitInternal() override { return OK; } | 82 int InitInternal(const BoundNetLog& net_log) override { return OK; } |
| 83 | 83 |
| 84 int ReadInternal(IOBuffer* buf, int buf_len) override { | 84 int ReadInternal(IOBuffer* buf, int buf_len) override { |
| 85 if (async_ == FailureMode::ASYNC) { | 85 if (async_ == FailureMode::ASYNC) { |
| 86 base::ThreadTaskRunnerHandle::Get()->PostTask( | 86 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 87 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, | 87 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, |
| 88 weak_factory_.GetWeakPtr())); | 88 weak_factory_.GetWeakPtr())); |
| 89 return ERR_IO_PENDING; | 89 return ERR_IO_PENDING; |
| 90 } | 90 } |
| 91 return ERR_FAILED; | 91 return ERR_FAILED; |
| 92 } | 92 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 MockWrite(SYNCHRONOUS, 0, "POST / HTTP/1.1\r\n"), | 105 MockWrite(SYNCHRONOUS, 0, "POST / HTTP/1.1\r\n"), |
| 106 MockWrite(SYNCHRONOUS, 1, "Content-Length: 12\r\n\r\n"), | 106 MockWrite(SYNCHRONOUS, 1, "Content-Length: 12\r\n\r\n"), |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 SequencedSocketData data(nullptr, 0, writes, arraysize(writes)); | 109 SequencedSocketData data(nullptr, 0, writes, arraysize(writes)); |
| 110 std::unique_ptr<ClientSocketHandle> socket_handle = | 110 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 111 CreateConnectedSocketHandle(&data); | 111 CreateConnectedSocketHandle(&data); |
| 112 | 112 |
| 113 ReadErrorUploadDataStream upload_data_stream( | 113 ReadErrorUploadDataStream upload_data_stream( |
| 114 ReadErrorUploadDataStream::FailureMode::SYNC); | 114 ReadErrorUploadDataStream::FailureMode::SYNC); |
| 115 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), | 115 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback(), |
| 116 BoundNetLog()), |
| 116 IsOk()); | 117 IsOk()); |
| 117 | 118 |
| 118 HttpRequestInfo request; | 119 HttpRequestInfo request; |
| 119 request.method = "POST"; | 120 request.method = "POST"; |
| 120 request.url = GURL("http://localhost"); | 121 request.url = GURL("http://localhost"); |
| 121 request.upload_data_stream = &upload_data_stream; | 122 request.upload_data_stream = &upload_data_stream; |
| 122 | 123 |
| 123 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); | 124 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); |
| 124 HttpStreamParser parser(socket_handle.get(), &request, read_buffer.get(), | 125 HttpStreamParser parser(socket_handle.get(), &request, read_buffer.get(), |
| 125 BoundNetLog()); | 126 BoundNetLog()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 141 MockWrite(ASYNC, 0, "POST / HTTP/1.1\r\n"), | 142 MockWrite(ASYNC, 0, "POST / HTTP/1.1\r\n"), |
| 142 MockWrite(ASYNC, 1, "Content-Length: 12\r\n\r\n"), | 143 MockWrite(ASYNC, 1, "Content-Length: 12\r\n\r\n"), |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 SequencedSocketData data(nullptr, 0, writes, arraysize(writes)); | 146 SequencedSocketData data(nullptr, 0, writes, arraysize(writes)); |
| 146 std::unique_ptr<ClientSocketHandle> socket_handle = | 147 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 147 CreateConnectedSocketHandle(&data); | 148 CreateConnectedSocketHandle(&data); |
| 148 | 149 |
| 149 ReadErrorUploadDataStream upload_data_stream( | 150 ReadErrorUploadDataStream upload_data_stream( |
| 150 ReadErrorUploadDataStream::FailureMode::ASYNC); | 151 ReadErrorUploadDataStream::FailureMode::ASYNC); |
| 151 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), | 152 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback(), |
| 153 BoundNetLog()), |
| 152 IsOk()); | 154 IsOk()); |
| 153 | 155 |
| 154 HttpRequestInfo request; | 156 HttpRequestInfo request; |
| 155 request.method = "POST"; | 157 request.method = "POST"; |
| 156 request.url = GURL("http://localhost"); | 158 request.url = GURL("http://localhost"); |
| 157 request.upload_data_stream = &upload_data_stream; | 159 request.upload_data_stream = &upload_data_stream; |
| 158 | 160 |
| 159 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); | 161 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); |
| 160 HttpStreamParser parser(socket_handle.get(), &request, read_buffer.get(), | 162 HttpStreamParser parser(socket_handle.get(), &request, read_buffer.get(), |
| 161 BoundNetLog()); | 163 BoundNetLog()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_NoBody) { | 236 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_NoBody) { |
| 235 // Shouldn't be merged if upload data is non-existent. | 237 // Shouldn't be merged if upload data is non-existent. |
| 236 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( | 238 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 237 "some header", NULL)); | 239 "some header", NULL)); |
| 238 } | 240 } |
| 239 | 241 |
| 240 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_EmptyBody) { | 242 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_EmptyBody) { |
| 241 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 243 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 242 std::unique_ptr<UploadDataStream> body(base::WrapUnique( | 244 std::unique_ptr<UploadDataStream> body(base::WrapUnique( |
| 243 new ElementsUploadDataStream(std::move(element_readers), 0))); | 245 new ElementsUploadDataStream(std::move(element_readers), 0))); |
| 244 ASSERT_THAT(body->Init(CompletionCallback()), IsOk()); | 246 ASSERT_THAT(body->Init(CompletionCallback(), BoundNetLog()), IsOk()); |
| 245 // Shouldn't be merged if upload data is empty. | 247 // Shouldn't be merged if upload data is empty. |
| 246 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( | 248 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 247 "some header", body.get())); | 249 "some header", body.get())); |
| 248 } | 250 } |
| 249 | 251 |
| 250 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_ChunkedBody) { | 252 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_ChunkedBody) { |
| 251 const std::string payload = "123"; | 253 const std::string payload = "123"; |
| 252 std::unique_ptr<ChunkedUploadDataStream> body(new ChunkedUploadDataStream(0)); | 254 std::unique_ptr<ChunkedUploadDataStream> body(new ChunkedUploadDataStream(0)); |
| 253 body->AppendData(payload.data(), payload.size(), true); | 255 body->AppendData(payload.data(), payload.size(), true); |
| 254 ASSERT_THAT(body->Init(TestCompletionCallback().callback()), IsOk()); | 256 ASSERT_THAT(body->Init(TestCompletionCallback().callback(), BoundNetLog()), |
| 257 IsOk()); |
| 255 // Shouldn't be merged if upload data carries chunked data. | 258 // Shouldn't be merged if upload data carries chunked data. |
| 256 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( | 259 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 257 "some header", body.get())); | 260 "some header", body.get())); |
| 258 } | 261 } |
| 259 | 262 |
| 260 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_FileBody) { | 263 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_FileBody) { |
| 261 // Create an empty temporary file. | 264 // Create an empty temporary file. |
| 262 base::ScopedTempDir temp_dir; | 265 base::ScopedTempDir temp_dir; |
| 263 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 266 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 264 base::FilePath temp_file_path; | 267 base::FilePath temp_file_path; |
| 265 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file_path)); | 268 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file_path)); |
| 266 | 269 |
| 267 { | 270 { |
| 268 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 271 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 269 | 272 |
| 270 element_readers.push_back(base::WrapUnique( | 273 element_readers.push_back(base::WrapUnique( |
| 271 new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), | 274 new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), |
| 272 temp_file_path, 0, 0, base::Time()))); | 275 temp_file_path, 0, 0, base::Time()))); |
| 273 | 276 |
| 274 std::unique_ptr<UploadDataStream> body( | 277 std::unique_ptr<UploadDataStream> body( |
| 275 new ElementsUploadDataStream(std::move(element_readers), 0)); | 278 new ElementsUploadDataStream(std::move(element_readers), 0)); |
| 276 TestCompletionCallback callback; | 279 TestCompletionCallback callback; |
| 277 ASSERT_THAT(body->Init(callback.callback()), IsError(ERR_IO_PENDING)); | 280 ASSERT_THAT(body->Init(callback.callback(), BoundNetLog()), |
| 281 IsError(ERR_IO_PENDING)); |
| 278 ASSERT_THAT(callback.WaitForResult(), IsOk()); | 282 ASSERT_THAT(callback.WaitForResult(), IsOk()); |
| 279 // Shouldn't be merged if upload data carries a file, as it's not in-memory. | 283 // Shouldn't be merged if upload data carries a file, as it's not in-memory. |
| 280 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( | 284 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 281 "some header", body.get())); | 285 "some header", body.get())); |
| 282 } | 286 } |
| 283 | 287 |
| 284 // UploadFileElementReaders may post clean-up tasks on destruction. | 288 // UploadFileElementReaders may post clean-up tasks on destruction. |
| 285 base::RunLoop().RunUntilIdle(); | 289 base::RunLoop().RunUntilIdle(); |
| 286 } | 290 } |
| 287 | 291 |
| 288 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) { | 292 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_SmallBodyInMemory) { |
| 289 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 293 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 290 const std::string payload = "123"; | 294 const std::string payload = "123"; |
| 291 element_readers.push_back(base::WrapUnique( | 295 element_readers.push_back(base::WrapUnique( |
| 292 new UploadBytesElementReader(payload.data(), payload.size()))); | 296 new UploadBytesElementReader(payload.data(), payload.size()))); |
| 293 | 297 |
| 294 std::unique_ptr<UploadDataStream> body( | 298 std::unique_ptr<UploadDataStream> body( |
| 295 new ElementsUploadDataStream(std::move(element_readers), 0)); | 299 new ElementsUploadDataStream(std::move(element_readers), 0)); |
| 296 ASSERT_THAT(body->Init(CompletionCallback()), IsOk()); | 300 ASSERT_THAT(body->Init(CompletionCallback(), BoundNetLog()), IsOk()); |
| 297 // Yes, should be merged if the in-memory body is small here. | 301 // Yes, should be merged if the in-memory body is small here. |
| 298 ASSERT_TRUE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( | 302 ASSERT_TRUE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 299 "some header", body.get())); | 303 "some header", body.get())); |
| 300 } | 304 } |
| 301 | 305 |
| 302 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_LargeBodyInMemory) { | 306 TEST(HttpStreamParser, ShouldMergeRequestHeadersAndBody_LargeBodyInMemory) { |
| 303 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 307 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 304 const std::string payload(10000, 'a'); // 'a' x 10000. | 308 const std::string payload(10000, 'a'); // 'a' x 10000. |
| 305 element_readers.push_back(base::WrapUnique( | 309 element_readers.push_back(base::WrapUnique( |
| 306 new UploadBytesElementReader(payload.data(), payload.size()))); | 310 new UploadBytesElementReader(payload.data(), payload.size()))); |
| 307 | 311 |
| 308 std::unique_ptr<UploadDataStream> body( | 312 std::unique_ptr<UploadDataStream> body( |
| 309 new ElementsUploadDataStream(std::move(element_readers), 0)); | 313 new ElementsUploadDataStream(std::move(element_readers), 0)); |
| 310 ASSERT_THAT(body->Init(CompletionCallback()), IsOk()); | 314 ASSERT_THAT(body->Init(CompletionCallback(), BoundNetLog()), IsOk()); |
| 311 // Shouldn't be merged if the in-memory body is large here. | 315 // Shouldn't be merged if the in-memory body is large here. |
| 312 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( | 316 ASSERT_FALSE(HttpStreamParser::ShouldMergeRequestHeadersAndBody( |
| 313 "some header", body.get())); | 317 "some header", body.get())); |
| 314 } | 318 } |
| 315 | 319 |
| 316 TEST(HttpStreamParser, SentBytesNoHeaders) { | 320 TEST(HttpStreamParser, SentBytesNoHeaders) { |
| 317 MockWrite writes[] = { | 321 MockWrite writes[] = { |
| 318 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n\r\n"), | 322 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n\r\n"), |
| 319 }; | 323 }; |
| 320 | 324 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 }; | 446 }; |
| 443 | 447 |
| 444 SequencedSocketData data(nullptr, 0, writes, arraysize(writes)); | 448 SequencedSocketData data(nullptr, 0, writes, arraysize(writes)); |
| 445 std::unique_ptr<ClientSocketHandle> socket_handle = | 449 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 446 CreateConnectedSocketHandle(&data); | 450 CreateConnectedSocketHandle(&data); |
| 447 | 451 |
| 448 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 452 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 449 element_readers.push_back( | 453 element_readers.push_back( |
| 450 base::WrapUnique(new UploadBytesElementReader("hello world!", 12))); | 454 base::WrapUnique(new UploadBytesElementReader("hello world!", 12))); |
| 451 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); | 455 ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
| 452 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), | 456 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback(), |
| 457 BoundNetLog()), |
| 453 IsOk()); | 458 IsOk()); |
| 454 | 459 |
| 455 HttpRequestInfo request; | 460 HttpRequestInfo request; |
| 456 request.method = "POST"; | 461 request.method = "POST"; |
| 457 request.url = GURL("http://localhost"); | 462 request.url = GURL("http://localhost"); |
| 458 request.upload_data_stream = &upload_data_stream; | 463 request.upload_data_stream = &upload_data_stream; |
| 459 | 464 |
| 460 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); | 465 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); |
| 461 HttpStreamParser parser(socket_handle.get(), &request, read_buffer.get(), | 466 HttpStreamParser parser(socket_handle.get(), &request, read_buffer.get(), |
| 462 BoundNetLog()); | 467 BoundNetLog()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 480 MockWrite(ASYNC, 1, "Transfer-Encoding: chunked\r\n\r\n"), | 485 MockWrite(ASYNC, 1, "Transfer-Encoding: chunked\r\n\r\n"), |
| 481 MockWrite(ASYNC, 2, "7\r\nChunk 1\r\n"), | 486 MockWrite(ASYNC, 2, "7\r\nChunk 1\r\n"), |
| 482 MockWrite(SYNCHRONOUS, ERR_FAILED, 3), | 487 MockWrite(SYNCHRONOUS, ERR_FAILED, 3), |
| 483 }; | 488 }; |
| 484 | 489 |
| 485 SequencedSocketData data(nullptr, 0, writes, arraysize(writes)); | 490 SequencedSocketData data(nullptr, 0, writes, arraysize(writes)); |
| 486 std::unique_ptr<ClientSocketHandle> socket_handle = | 491 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 487 CreateConnectedSocketHandle(&data); | 492 CreateConnectedSocketHandle(&data); |
| 488 | 493 |
| 489 ChunkedUploadDataStream upload_data_stream(0); | 494 ChunkedUploadDataStream upload_data_stream(0); |
| 490 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback()), | 495 ASSERT_THAT(upload_data_stream.Init(TestCompletionCallback().callback(), |
| 496 BoundNetLog()), |
| 491 IsOk()); | 497 IsOk()); |
| 492 | 498 |
| 493 HttpRequestInfo request; | 499 HttpRequestInfo request; |
| 494 request.method = "POST"; | 500 request.method = "POST"; |
| 495 request.url = GURL("http://localhost"); | 501 request.url = GURL("http://localhost"); |
| 496 request.upload_data_stream = &upload_data_stream; | 502 request.upload_data_stream = &upload_data_stream; |
| 497 | 503 |
| 498 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); | 504 scoped_refptr<GrowableIOBuffer> read_buffer(new GrowableIOBuffer); |
| 499 HttpStreamParser parser(socket_handle.get(), &request, read_buffer.get(), | 505 HttpStreamParser parser(socket_handle.get(), &request, read_buffer.get(), |
| 500 BoundNetLog()); | 506 BoundNetLog()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 static const int kBodySize = 8; | 543 static const int kBodySize = 8; |
| 538 | 544 |
| 539 MockRead reads[] = { | 545 MockRead reads[] = { |
| 540 MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n"), | 546 MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n"), |
| 541 MockRead(ASYNC, 4, "Content-Length: 8\r\n\r\n"), | 547 MockRead(ASYNC, 4, "Content-Length: 8\r\n\r\n"), |
| 542 MockRead(ASYNC, 5, "one.html"), | 548 MockRead(ASYNC, 5, "one.html"), |
| 543 MockRead(SYNCHRONOUS, 0, 6), // EOF | 549 MockRead(SYNCHRONOUS, 0, 6), // EOF |
| 544 }; | 550 }; |
| 545 | 551 |
| 546 ChunkedUploadDataStream upload_stream(0); | 552 ChunkedUploadDataStream upload_stream(0); |
| 547 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk()); | 553 ASSERT_THAT( |
| 554 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), |
| 555 IsOk()); |
| 548 | 556 |
| 549 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 557 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 550 std::unique_ptr<ClientSocketHandle> socket_handle = | 558 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 551 CreateConnectedSocketHandle(&data); | 559 CreateConnectedSocketHandle(&data); |
| 552 | 560 |
| 553 HttpRequestInfo request_info; | 561 HttpRequestInfo request_info; |
| 554 request_info.method = "GET"; | 562 request_info.method = "GET"; |
| 555 request_info.url = GURL("http://localhost"); | 563 request_info.url = GURL("http://localhost"); |
| 556 request_info.upload_data_stream = &upload_stream; | 564 request_info.upload_data_stream = &upload_stream; |
| 557 | 565 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 static const int kBodySize = 8; | 621 static const int kBodySize = 8; |
| 614 | 622 |
| 615 MockRead reads[] = { | 623 MockRead reads[] = { |
| 616 MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n"), | 624 MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n"), |
| 617 MockRead(ASYNC, 4, "Content-Length: 8\r\n\r\n"), | 625 MockRead(ASYNC, 4, "Content-Length: 8\r\n\r\n"), |
| 618 MockRead(ASYNC, 5, "one.html"), | 626 MockRead(ASYNC, 5, "one.html"), |
| 619 MockRead(SYNCHRONOUS, 0, 6), // EOF | 627 MockRead(SYNCHRONOUS, 0, 6), // EOF |
| 620 }; | 628 }; |
| 621 | 629 |
| 622 ChunkedUploadDataStream upload_stream(0); | 630 ChunkedUploadDataStream upload_stream(0); |
| 623 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk()); | 631 ASSERT_THAT( |
| 632 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), |
| 633 IsOk()); |
| 624 // Append the only chunk. | 634 // Append the only chunk. |
| 625 upload_stream.AppendData(kChunk, arraysize(kChunk) - 1, true); | 635 upload_stream.AppendData(kChunk, arraysize(kChunk) - 1, true); |
| 626 | 636 |
| 627 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 637 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 628 std::unique_ptr<ClientSocketHandle> socket_handle = | 638 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 629 CreateConnectedSocketHandle(&data); | 639 CreateConnectedSocketHandle(&data); |
| 630 | 640 |
| 631 HttpRequestInfo request_info; | 641 HttpRequestInfo request_info; |
| 632 request_info.method = "GET"; | 642 request_info.method = "GET"; |
| 633 request_info.url = GURL("http://localhost"); | 643 request_info.url = GURL("http://localhost"); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 | 703 |
| 694 MockRead reads[] = { | 704 MockRead reads[] = { |
| 695 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), | 705 MockRead(ASYNC, 5, "HTTP/1.1 200 OK\r\n"), |
| 696 MockRead(ASYNC, 6, "Content-Length: 8\r\n\r\n"), | 706 MockRead(ASYNC, 6, "Content-Length: 8\r\n\r\n"), |
| 697 MockRead(ASYNC, 7, "one.html"), | 707 MockRead(ASYNC, 7, "one.html"), |
| 698 MockRead(SYNCHRONOUS, 0, 8), // EOF | 708 MockRead(SYNCHRONOUS, 0, 8), // EOF |
| 699 }; | 709 }; |
| 700 | 710 |
| 701 ChunkedUploadDataStream upload_stream(0); | 711 ChunkedUploadDataStream upload_stream(0); |
| 702 upload_stream.AppendData(kChunk1, arraysize(kChunk1) - 1, false); | 712 upload_stream.AppendData(kChunk1, arraysize(kChunk1) - 1, false); |
| 703 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk()); | 713 ASSERT_THAT( |
| 714 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), |
| 715 IsOk()); |
| 704 | 716 |
| 705 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 717 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 706 std::unique_ptr<ClientSocketHandle> socket_handle = | 718 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 707 CreateConnectedSocketHandle(&data); | 719 CreateConnectedSocketHandle(&data); |
| 708 | 720 |
| 709 HttpRequestInfo request_info; | 721 HttpRequestInfo request_info; |
| 710 request_info.method = "GET"; | 722 request_info.method = "GET"; |
| 711 request_info.url = GURL("http://localhost"); | 723 request_info.url = GURL("http://localhost"); |
| 712 request_info.upload_data_stream = &upload_stream; | 724 request_info.upload_data_stream = &upload_stream; |
| 713 | 725 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 const int kBodySize = 8; | 787 const int kBodySize = 8; |
| 776 | 788 |
| 777 MockRead reads[] = { | 789 MockRead reads[] = { |
| 778 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n"), | 790 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n"), |
| 779 MockRead(ASYNC, 3, "Content-Length: 8\r\n\r\n"), | 791 MockRead(ASYNC, 3, "Content-Length: 8\r\n\r\n"), |
| 780 MockRead(ASYNC, 4, "one.html"), | 792 MockRead(ASYNC, 4, "one.html"), |
| 781 MockRead(SYNCHRONOUS, 0, 5), // EOF | 793 MockRead(SYNCHRONOUS, 0, 5), // EOF |
| 782 }; | 794 }; |
| 783 | 795 |
| 784 ChunkedUploadDataStream upload_stream(0); | 796 ChunkedUploadDataStream upload_stream(0); |
| 785 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk()); | 797 ASSERT_THAT( |
| 798 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), |
| 799 IsOk()); |
| 786 | 800 |
| 787 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 801 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 788 std::unique_ptr<ClientSocketHandle> socket_handle = | 802 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 789 CreateConnectedSocketHandle(&data); | 803 CreateConnectedSocketHandle(&data); |
| 790 | 804 |
| 791 HttpRequestInfo request_info; | 805 HttpRequestInfo request_info; |
| 792 request_info.method = "GET"; | 806 request_info.method = "GET"; |
| 793 request_info.url = GURL("http://localhost"); | 807 request_info.url = GURL("http://localhost"); |
| 794 request_info.upload_data_stream = &upload_stream; | 808 request_info.upload_data_stream = &upload_stream; |
| 795 | 809 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 const int kBodySize = 8; | 860 const int kBodySize = 8; |
| 847 | 861 |
| 848 MockRead reads[] = { | 862 MockRead reads[] = { |
| 849 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n"), | 863 MockRead(ASYNC, 2, "HTTP/1.1 200 OK\r\n"), |
| 850 MockRead(ASYNC, 3, "Content-Length: 8\r\n\r\n"), | 864 MockRead(ASYNC, 3, "Content-Length: 8\r\n\r\n"), |
| 851 MockRead(ASYNC, 4, "one.html"), | 865 MockRead(ASYNC, 4, "one.html"), |
| 852 MockRead(SYNCHRONOUS, 0, 5), // EOF | 866 MockRead(SYNCHRONOUS, 0, 5), // EOF |
| 853 }; | 867 }; |
| 854 | 868 |
| 855 ChunkedUploadDataStream upload_stream(0); | 869 ChunkedUploadDataStream upload_stream(0); |
| 856 ASSERT_THAT(upload_stream.Init(TestCompletionCallback().callback()), IsOk()); | 870 ASSERT_THAT( |
| 871 upload_stream.Init(TestCompletionCallback().callback(), BoundNetLog()), |
| 872 IsOk()); |
| 857 // Append final empty chunk. | 873 // Append final empty chunk. |
| 858 upload_stream.AppendData(nullptr, 0, true); | 874 upload_stream.AppendData(nullptr, 0, true); |
| 859 | 875 |
| 860 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 876 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 861 std::unique_ptr<ClientSocketHandle> socket_handle = | 877 std::unique_ptr<ClientSocketHandle> socket_handle = |
| 862 CreateConnectedSocketHandle(&data); | 878 CreateConnectedSocketHandle(&data); |
| 863 | 879 |
| 864 HttpRequestInfo request_info; | 880 HttpRequestInfo request_info; |
| 865 request_info.method = "GET"; | 881 request_info.method = "GET"; |
| 866 request_info.url = GURL("http://localhost"); | 882 request_info.url = GURL("http://localhost"); |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 ASSERT_EQ(kBodySize, parser.ReadResponseBody( | 1439 ASSERT_EQ(kBodySize, parser.ReadResponseBody( |
| 1424 body_buffer.get(), kBodySize, callback.callback())); | 1440 body_buffer.get(), kBodySize, callback.callback())); |
| 1425 | 1441 |
| 1426 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), parser.sent_bytes()); | 1442 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), parser.sent_bytes()); |
| 1427 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), parser.received_bytes()); | 1443 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), parser.received_bytes()); |
| 1428 } | 1444 } |
| 1429 | 1445 |
| 1430 } // namespace | 1446 } // namespace |
| 1431 | 1447 |
| 1432 } // namespace net | 1448 } // namespace net |
| OLD | NEW |