Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: net/http/http_stream_parser.cc

Issue 6134003: Prototype of chunked transfer encoded POST. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "net/base/auth.h" 9 #include "net/base/auth.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
11 #include "net/base/ssl_cert_request_info.h" 11 #include "net/base/ssl_cert_request_info.h"
12 #include "net/http/http_net_log_params.h" 12 #include "net/http/http_net_log_params.h"
13 #include "net/http/http_request_headers.h" 13 #include "net/http/http_request_headers.h"
14 #include "net/base/load_flags.h"
wtc 2011/01/14 03:09:31 Nit: remove this header.
Satish 2011/01/14 18:09:29 Done.
14 #include "net/http/http_request_info.h" 15 #include "net/http/http_request_info.h"
15 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
16 #include "net/http/http_util.h" 17 #include "net/http/http_util.h"
17 #include "net/socket/ssl_client_socket.h" 18 #include "net/socket/ssl_client_socket.h"
18 #include "net/socket/client_socket_handle.h" 19 #include "net/socket/client_socket_handle.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, 23 HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection,
23 const HttpRequestInfo* request, 24 const HttpRequestInfo* request,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, 61 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS,
61 make_scoped_refptr(new NetLogHttpRequestParameter( 62 make_scoped_refptr(new NetLogHttpRequestParameter(
62 request_line, headers))); 63 request_line, headers)));
63 } 64 }
64 response_ = response; 65 response_ = response;
65 std::string request = request_line + headers.ToString(); 66 std::string request = request_line + headers.ToString();
66 scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request)); 67 scoped_refptr<StringIOBuffer> headers_io_buf(new StringIOBuffer(request));
67 request_headers_ = new DrainableIOBuffer(headers_io_buf, 68 request_headers_ = new DrainableIOBuffer(headers_io_buf,
68 headers_io_buf->size()); 69 headers_io_buf->size());
69 request_body_.reset(request_body); 70 request_body_.reset(request_body);
71 if (request_body)
wtc 2011/01/14 03:09:31 Nit: request_body => request_body_
Satish 2011/01/14 18:09:29 Done.
72 request_body_->set_chunk_callback(this);
vandebo (ex-Chrome) 2011/01/14 05:53:44 set_chunk_callback will be called even when not us
Satish 2011/01/14 18:09:29 Changed now to only set for chunked streams
70 73
71 io_state_ = STATE_SENDING_HEADERS; 74 io_state_ = STATE_SENDING_HEADERS;
72 int result = DoLoop(OK); 75 int result = DoLoop(OK);
73 if (result == ERR_IO_PENDING) 76 if (result == ERR_IO_PENDING)
74 user_callback_ = callback; 77 user_callback_ = callback;
75 78
76 return result > 0 ? OK : result; 79 return result > 0 ? OK : result;
77 } 80 }
78 81
79 int HttpStreamParser::ReadResponseHeaders(CompletionCallback* callback) { 82 int HttpStreamParser::ReadResponseHeaders(CompletionCallback* callback) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 139
137 // The client callback can do anything, including destroying this class, 140 // The client callback can do anything, including destroying this class,
138 // so any pending callback must be issued after everything else is done. 141 // so any pending callback must be issued after everything else is done.
139 if (result != ERR_IO_PENDING && user_callback_) { 142 if (result != ERR_IO_PENDING && user_callback_) {
140 CompletionCallback* c = user_callback_; 143 CompletionCallback* c = user_callback_;
141 user_callback_ = NULL; 144 user_callback_ = NULL;
142 c->Run(result); 145 c->Run(result);
143 } 146 }
144 } 147 }
145 148
149 void HttpStreamParser::OnChunkAvailable() {
150 OnIOComplete(0);
wtc 2011/01/14 03:09:31 IMPORTANT: this should do nothing unless we're in
vandebo (ex-Chrome) 2011/01/14 05:53:44 Indeed, this mustn't do anything unless io_state =
Satish 2011/01/14 18:09:29 Done.
Satish 2011/01/14 18:09:29 Done.
151 }
152
146 int HttpStreamParser::DoLoop(int result) { 153 int HttpStreamParser::DoLoop(int result) {
147 bool can_do_more = true; 154 bool can_do_more = true;
148 do { 155 do {
149 switch (io_state_) { 156 switch (io_state_) {
150 case STATE_SENDING_HEADERS: 157 case STATE_SENDING_HEADERS:
151 if (result < 0) 158 if (result < 0)
152 can_do_more = false; 159 can_do_more = false;
153 else 160 else
154 result = DoSendHeaders(result); 161 result = DoSendHeaders(result);
155 break; 162 break;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } else { 236 } else {
230 coalesce = NO_ADVANTAGE; 237 coalesce = NO_ADVANTAGE;
231 } 238 }
232 } 239 }
233 UMA_HISTOGRAM_ENUMERATION("Net.CoalescePotential", coalesce, 240 UMA_HISTOGRAM_ENUMERATION("Net.CoalescePotential", coalesce,
234 COALESCE_POTENTIAL_MAX); 241 COALESCE_POTENTIAL_MAX);
235 } 242 }
236 result = connection_->socket()->Write(request_headers_, 243 result = connection_->socket()->Write(request_headers_,
237 bytes_remaining, 244 bytes_remaining,
238 &io_callback_); 245 &io_callback_);
239 } else if (request_body_ != NULL && request_body_->size()) { 246 } else if (request_body_ != NULL &&
247 (request_body_->is_chunked() || request_body_->size())) {
240 io_state_ = STATE_SENDING_BODY; 248 io_state_ = STATE_SENDING_BODY;
241 result = OK; 249 result = OK;
242 } else { 250 } else {
243 io_state_ = STATE_REQUEST_SENT; 251 io_state_ = STATE_REQUEST_SENT;
244 } 252 }
245 return result; 253 return result;
246 } 254 }
247 255
248 int HttpStreamParser::DoSendBody(int result) { 256 int HttpStreamParser::DoSendBody(int result) {
249 if (result > 0) 257 if (result > 0)
250 request_body_->DidConsume(result); 258 request_body_->DidConsume(result);
251 259
252 if (!request_body_->eof()) { 260 if (!request_body_->eof()) {
253 int buf_len = static_cast<int>(request_body_->buf_len()); 261 int buf_len = static_cast<int>(request_body_->buf_len());
254 result = connection_->socket()->Write(request_body_->buf(), buf_len, 262 if (buf_len) {
255 &io_callback_); 263 result = connection_->socket()->Write(request_body_->buf(), buf_len,
264 &io_callback_);
265 } else {
266 // More POST data is to come hence wait for the callback.
267 result = ERR_IO_PENDING;
268 }
256 } else { 269 } else {
257 io_state_ = STATE_REQUEST_SENT; 270 io_state_ = STATE_REQUEST_SENT;
258 } 271 }
259 return result; 272 return result;
260 } 273 }
261 274
262 int HttpStreamParser::DoReadHeaders() { 275 int HttpStreamParser::DoReadHeaders() {
263 io_state_ = STATE_READ_HEADERS_COMPLETE; 276 io_state_ = STATE_READ_HEADERS_COMPLETE;
264 277
265 // Grow the read buffer if necessary. 278 // Grow the read buffer if necessary.
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 void HttpStreamParser::GetSSLCertRequestInfo( 643 void HttpStreamParser::GetSSLCertRequestInfo(
631 SSLCertRequestInfo* cert_request_info) { 644 SSLCertRequestInfo* cert_request_info) {
632 if (request_->url.SchemeIs("https") && connection_->socket()) { 645 if (request_->url.SchemeIs("https") && connection_->socket()) {
633 SSLClientSocket* ssl_socket = 646 SSLClientSocket* ssl_socket =
634 static_cast<SSLClientSocket*>(connection_->socket()); 647 static_cast<SSLClientSocket*>(connection_->socket());
635 ssl_socket->GetSSLCertRequestInfo(cert_request_info); 648 ssl_socket->GetSSLCertRequestInfo(cert_request_info);
636 } 649 }
637 } 650 }
638 651
639 } // namespace net 652 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698