OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "headless/test/test_url_request_job.h" |
| 6 |
| 7 #include "net/base/io_buffer.h" |
| 8 #include "net/http/http_response_headers.h" |
| 9 |
| 10 namespace headless { |
| 11 |
| 12 TestURLRequestJob::TestURLRequestJob(net::URLRequest* request, |
| 13 net::NetworkDelegate* network_delegate, |
| 14 const std::string& body) |
| 15 : net::URLRequestJob(request, network_delegate), |
| 16 body_(new net::StringIOBuffer(body)), |
| 17 src_buf_(new net::DrainableIOBuffer(body_.get(), body_->size())) {} |
| 18 |
| 19 TestURLRequestJob::~TestURLRequestJob() {} |
| 20 |
| 21 void TestURLRequestJob::Start() { |
| 22 NotifyHeadersComplete(); |
| 23 } |
| 24 |
| 25 void TestURLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { |
| 26 info->headers = |
| 27 new net::HttpResponseHeaders("Content-Type: text/html\r\n\r\n"); |
| 28 } |
| 29 |
| 30 int TestURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size) { |
| 31 scoped_refptr<net::DrainableIOBuffer> dest_buf( |
| 32 new net::DrainableIOBuffer(buf, buf_size)); |
| 33 while (src_buf_->BytesRemaining() > 0 && dest_buf->BytesRemaining() > 0) { |
| 34 *dest_buf->data() = *src_buf_->data(); |
| 35 src_buf_->DidConsume(1); |
| 36 dest_buf->DidConsume(1); |
| 37 } |
| 38 return dest_buf->BytesConsumed(); |
| 39 } |
| 40 |
| 41 } // namespace headless |
OLD | NEW |