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

Side by Side Diff: net/spdy/spdy_http_stream.cc

Issue 6292013: Add chunked uploads support to SPDY (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/spdy/spdy_http_stream.h" 5 #include "net/spdy/spdy_http_stream.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 10
(...skipping 15 matching lines...) Expand all
26 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), 26 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)),
27 stream_(NULL), 27 stream_(NULL),
28 spdy_session_(spdy_session), 28 spdy_session_(spdy_session),
29 response_info_(NULL), 29 response_info_(NULL),
30 download_finished_(false), 30 download_finished_(false),
31 response_headers_received_(false), 31 response_headers_received_(false),
32 user_callback_(NULL), 32 user_callback_(NULL),
33 user_buffer_len_(0), 33 user_buffer_len_(0),
34 buffered_read_callback_pending_(false), 34 buffered_read_callback_pending_(false),
35 more_read_data_pending_(false), 35 more_read_data_pending_(false),
36 direct_(direct) { } 36 direct_(direct),
37 send_last_chunk_(false) { }
37 38
38 void SpdyHttpStream::InitializeWithExistingStream(SpdyStream* spdy_stream) { 39 void SpdyHttpStream::InitializeWithExistingStream(SpdyStream* spdy_stream) {
39 stream_ = spdy_stream; 40 stream_ = spdy_stream;
40 stream_->SetDelegate(this); 41 stream_->SetDelegate(this);
41 response_headers_received_ = true; 42 response_headers_received_ = true;
42 } 43 }
43 44
44 SpdyHttpStream::~SpdyHttpStream() { 45 SpdyHttpStream::~SpdyHttpStream() {
45 if (stream_) 46 if (stream_)
46 stream_->DetachDelegate(); 47 stream_->DetachDelegate();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 169 }
169 170
170 bool SpdyHttpStream::IsConnectionReused() const { 171 bool SpdyHttpStream::IsConnectionReused() const {
171 return spdy_session_->IsReused(); 172 return spdy_session_->IsReused();
172 } 173 }
173 174
174 void SpdyHttpStream::SetConnectionReused() { 175 void SpdyHttpStream::SetConnectionReused() {
175 // SPDY doesn't need an indicator here. 176 // SPDY doesn't need an indicator here.
176 } 177 }
177 178
179 void SpdyHttpStream::set_chunk_callback(ChunkCallback* callback) {
180 if (request_body_stream_ != NULL)
181 request_body_stream_->set_chunk_callback(callback);
182 }
183
178 int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, 184 int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers,
179 UploadDataStream* request_body, 185 UploadDataStream* request_body,
180 HttpResponseInfo* response, 186 HttpResponseInfo* response,
181 CompletionCallback* callback) { 187 CompletionCallback* callback) {
182 base::Time request_time = base::Time::Now(); 188 base::Time request_time = base::Time::Now();
183 CHECK(stream_.get()); 189 CHECK(stream_.get());
184 190
185 stream_->SetDelegate(this); 191 stream_->SetDelegate(this);
186 192
187 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); 193 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock);
188 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, 194 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers,
189 headers.get(), direct_); 195 headers.get(), direct_);
190 stream_->set_spdy_headers(headers); 196 stream_->set_spdy_headers(headers);
191 197
192 stream_->SetRequestTime(request_time); 198 stream_->SetRequestTime(request_time);
193 // This should only get called in the case of a request occurring 199 // This should only get called in the case of a request occurring
194 // during server push that has already begun but hasn't finished, 200 // during server push that has already begun but hasn't finished,
195 // so we set the response's request time to be the actual one 201 // so we set the response's request time to be the actual one
196 if (response_info_) 202 if (response_info_)
197 response_info_->request_time = request_time; 203 response_info_->request_time = request_time;
198 204
199 CHECK(!request_body_stream_.get()); 205 CHECK(!request_body_stream_.get());
200 if (request_body) { 206 if (request_body) {
201 if (request_body->size()) 207 if (request_body->size() || request_body->is_chunked())
202 request_body_stream_.reset(request_body); 208 request_body_stream_.reset(request_body);
203 else 209 else
204 delete request_body; 210 delete request_body;
205 } 211 }
206 212
207 CHECK(callback); 213 CHECK(callback);
208 CHECK(!stream_->cancelled()); 214 CHECK(!stream_->cancelled());
209 CHECK(response); 215 CHECK(response);
210 216
211 if (!stream_->pushed() && stream_->closed()) { 217 if (!stream_->pushed() && stream_->closed()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 254 }
249 255
250 bool SpdyHttpStream::OnSendHeadersComplete(int status) { 256 bool SpdyHttpStream::OnSendHeadersComplete(int status) {
251 if (user_callback_) 257 if (user_callback_)
252 DoCallback(status); 258 DoCallback(status);
253 return request_body_stream_.get() == NULL; 259 return request_body_stream_.get() == NULL;
254 } 260 }
255 261
256 int SpdyHttpStream::OnSendBody() { 262 int SpdyHttpStream::OnSendBody() {
257 CHECK(request_body_stream_.get()); 263 CHECK(request_body_stream_.get());
264 if (send_last_chunk_) {
265 return stream_->WriteStreamData(request_body_stream_->buf(), 0,
266 spdy::DATA_FLAG_FIN);
267 }
268
258 int buf_len = static_cast<int>(request_body_stream_->buf_len()); 269 int buf_len = static_cast<int>(request_body_stream_->buf_len());
259 if (!buf_len) 270 if (!buf_len)
260 return OK; 271 return OK;
272 bool is_chunked = request_body_stream_->is_chunked();
261 return stream_->WriteStreamData(request_body_stream_->buf(), buf_len, 273 return stream_->WriteStreamData(request_body_stream_->buf(), buf_len,
willchan no longer on Chromium 2011/02/01 23:35:59 http://google-styleguide.googlecode.com/svn/trunk/
Satish 2011/02/22 14:25:44 Done.
262 spdy::DATA_FLAG_FIN); 274 is_chunked ? spdy::DATA_FLAG_NONE : spdy::DATA_FLAG_FIN);
263 } 275 }
264 276
265 bool SpdyHttpStream::OnSendBodyComplete(int status) { 277 bool SpdyHttpStream::OnSendBodyComplete(int* status) {
266 CHECK(request_body_stream_.get()); 278 CHECK(request_body_stream_.get());
267 request_body_stream_->MarkConsumedAndFillBuffer(status); 279
268 return request_body_stream_->eof(); 280 *status = OK;
281 if (send_last_chunk_) // Indicates that the last chunk was SENT here.
282 return true;
283
284 request_body_stream_->MarkConsumedAndFillBuffer(*status);
willchan no longer on Chromium 2011/02/01 23:35:59 I'm confused how this works. OK == 0. You set *sta
Satish 2011/02/22 14:25:44 This was a last minute copy/paste error, fixed now
285
286 bool eof = request_body_stream_->eof();
287 if (request_body_stream_->is_chunked()) {
288 if (eof) {
289 send_last_chunk_ = true;
290 eof = false;
291 } else {
292 if (!request_body_stream_->buf_len())
293 *status = ERR_IO_PENDING;
294 }
295 }
296
297 return eof;
269 } 298 }
270 299
271 int SpdyHttpStream::OnResponseReceived(const spdy::SpdyHeaderBlock& response, 300 int SpdyHttpStream::OnResponseReceived(const spdy::SpdyHeaderBlock& response,
272 base::Time response_time, 301 base::Time response_time,
273 int status) { 302 int status) {
274 if (!response_info_) { 303 if (!response_info_) {
275 DCHECK(stream_->pushed()); 304 DCHECK(stream_->pushed());
276 push_response_info_.reset(new HttpResponseInfo); 305 push_response_info_.reset(new HttpResponseInfo);
277 response_info_ = push_response_info_.get(); 306 response_info_ = push_response_info_.get();
278 } 307 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 stream_->GetSSLInfo(ssl_info, &using_npn); 456 stream_->GetSSLInfo(ssl_info, &using_npn);
428 } 457 }
429 458
430 void SpdyHttpStream::GetSSLCertRequestInfo( 459 void SpdyHttpStream::GetSSLCertRequestInfo(
431 SSLCertRequestInfo* cert_request_info) { 460 SSLCertRequestInfo* cert_request_info) {
432 DCHECK(stream_); 461 DCHECK(stream_);
433 stream_->GetSSLCertRequestInfo(cert_request_info); 462 stream_->GetSSLCertRequestInfo(cert_request_info);
434 } 463 }
435 464
436 } // namespace net 465 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698