| OLD | NEW |
| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool SpdyHttpStream::IsConnectionReused() const { | 172 bool SpdyHttpStream::IsConnectionReused() const { |
| 173 return spdy_session_->IsReused(); | 173 return spdy_session_->IsReused(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void SpdyHttpStream::SetConnectionReused() { | 176 void SpdyHttpStream::SetConnectionReused() { |
| 177 // SPDY doesn't need an indicator here. | 177 // SPDY doesn't need an indicator here. |
| 178 } | 178 } |
| 179 | 179 |
| 180 void SpdyHttpStream::set_chunk_callback(ChunkCallback* callback) { |
| 181 if (request_body_stream_ != NULL) |
| 182 request_body_stream_->set_chunk_callback(callback); |
| 183 } |
| 184 |
| 180 int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, | 185 int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, |
| 181 UploadDataStream* request_body, | 186 UploadDataStream* request_body, |
| 182 HttpResponseInfo* response, | 187 HttpResponseInfo* response, |
| 183 CompletionCallback* callback) { | 188 CompletionCallback* callback) { |
| 184 base::Time request_time = base::Time::Now(); | 189 base::Time request_time = base::Time::Now(); |
| 185 CHECK(stream_.get()); | 190 CHECK(stream_.get()); |
| 186 | 191 |
| 187 stream_->SetDelegate(this); | 192 stream_->SetDelegate(this); |
| 188 | 193 |
| 189 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); | 194 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); |
| 190 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, | 195 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, |
| 191 headers.get(), direct_); | 196 headers.get(), direct_); |
| 192 stream_->set_spdy_headers(headers); | 197 stream_->set_spdy_headers(headers); |
| 193 | 198 |
| 194 stream_->SetRequestTime(request_time); | 199 stream_->SetRequestTime(request_time); |
| 195 // This should only get called in the case of a request occurring | 200 // This should only get called in the case of a request occurring |
| 196 // during server push that has already begun but hasn't finished, | 201 // during server push that has already begun but hasn't finished, |
| 197 // so we set the response's request time to be the actual one | 202 // so we set the response's request time to be the actual one |
| 198 if (response_info_) | 203 if (response_info_) |
| 199 response_info_->request_time = request_time; | 204 response_info_->request_time = request_time; |
| 200 | 205 |
| 201 CHECK(!request_body_stream_.get()); | 206 CHECK(!request_body_stream_.get()); |
| 202 if (request_body) { | 207 if (request_body) { |
| 203 if (request_body->size()) | 208 if (request_body->size() || request_body->is_chunked()) |
| 204 request_body_stream_.reset(request_body); | 209 request_body_stream_.reset(request_body); |
| 205 else | 210 else |
| 206 delete request_body; | 211 delete request_body; |
| 207 } | 212 } |
| 208 | 213 |
| 209 CHECK(callback); | 214 CHECK(callback); |
| 210 CHECK(!stream_->cancelled()); | 215 CHECK(!stream_->cancelled()); |
| 211 CHECK(response); | 216 CHECK(response); |
| 212 | 217 |
| 213 if (!stream_->pushed() && stream_->closed()) { | 218 if (!stream_->pushed() && stream_->closed()) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 262 } |
| 258 | 263 |
| 259 bool SpdyHttpStream::OnSendHeadersComplete(int status) { | 264 bool SpdyHttpStream::OnSendHeadersComplete(int status) { |
| 260 if (user_callback_) | 265 if (user_callback_) |
| 261 DoCallback(status); | 266 DoCallback(status); |
| 262 return request_body_stream_.get() == NULL; | 267 return request_body_stream_.get() == NULL; |
| 263 } | 268 } |
| 264 | 269 |
| 265 int SpdyHttpStream::OnSendBody() { | 270 int SpdyHttpStream::OnSendBody() { |
| 266 CHECK(request_body_stream_.get()); | 271 CHECK(request_body_stream_.get()); |
| 272 |
| 267 int buf_len = static_cast<int>(request_body_stream_->buf_len()); | 273 int buf_len = static_cast<int>(request_body_stream_->buf_len()); |
| 268 if (!buf_len) | 274 if (!buf_len) |
| 269 return OK; | 275 return OK; |
| 270 return stream_->WriteStreamData(request_body_stream_->buf(), buf_len, | 276 bool is_chunked = request_body_stream_->is_chunked(); |
| 271 spdy::DATA_FLAG_FIN); | 277 // TODO(satish): For non-chunked POST data, we set DATA_FLAG_FIN for all |
| 278 // blocks of data written out. This is wrong if the POST data was larger than |
| 279 // UploadDataStream::kBufSize as that is the largest buffer that |
| 280 // UploadDataStream returns at a time and we'll be setting the FIN flag for |
| 281 // each block of data written out. |
| 282 bool eof = !is_chunked || request_body_stream_->IsOnLastChunk(); |
| 283 return stream_->WriteStreamData( |
| 284 request_body_stream_->buf(), buf_len, |
| 285 eof ? spdy::DATA_FLAG_FIN : spdy::DATA_FLAG_NONE); |
| 272 } | 286 } |
| 273 | 287 |
| 274 bool SpdyHttpStream::OnSendBodyComplete(int status) { | 288 int SpdyHttpStream::OnSendBodyComplete(int status, bool* eof) { |
| 275 CHECK(request_body_stream_.get()); | 289 CHECK(request_body_stream_.get()); |
| 290 |
| 276 request_body_stream_->MarkConsumedAndFillBuffer(status); | 291 request_body_stream_->MarkConsumedAndFillBuffer(status); |
| 277 return request_body_stream_->eof(); | 292 *eof = request_body_stream_->eof(); |
| 293 if (!*eof && |
| 294 request_body_stream_->is_chunked() && |
| 295 !request_body_stream_->buf_len()) |
| 296 return ERR_IO_PENDING; |
| 297 |
| 298 return OK; |
| 278 } | 299 } |
| 279 | 300 |
| 280 int SpdyHttpStream::OnResponseReceived(const spdy::SpdyHeaderBlock& response, | 301 int SpdyHttpStream::OnResponseReceived(const spdy::SpdyHeaderBlock& response, |
| 281 base::Time response_time, | 302 base::Time response_time, |
| 282 int status) { | 303 int status) { |
| 283 if (!response_info_) { | 304 if (!response_info_) { |
| 284 DCHECK(stream_->pushed()); | 305 DCHECK(stream_->pushed()); |
| 285 push_response_info_.reset(new HttpResponseInfo); | 306 push_response_info_.reset(new HttpResponseInfo); |
| 286 response_info_ = push_response_info_.get(); | 307 response_info_ = push_response_info_.get(); |
| 287 } | 308 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 stream_->GetSSLInfo(ssl_info, &using_npn); | 457 stream_->GetSSLInfo(ssl_info, &using_npn); |
| 437 } | 458 } |
| 438 | 459 |
| 439 void SpdyHttpStream::GetSSLCertRequestInfo( | 460 void SpdyHttpStream::GetSSLCertRequestInfo( |
| 440 SSLCertRequestInfo* cert_request_info) { | 461 SSLCertRequestInfo* cert_request_info) { |
| 441 DCHECK(stream_); | 462 DCHECK(stream_); |
| 442 stream_->GetSSLCertRequestInfo(cert_request_info); | 463 stream_->GetSSLCertRequestInfo(cert_request_info); |
| 443 } | 464 } |
| 444 | 465 |
| 445 } // namespace net | 466 } // namespace net |
| OLD | NEW |