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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 } | 168 } |
169 | 169 |
170 bool SpdyHttpStream::IsConnectionReused() const { | 170 bool SpdyHttpStream::IsConnectionReused() const { |
171 return spdy_session_->IsReused(); | 171 return spdy_session_->IsReused(); |
172 } | 172 } |
173 | 173 |
174 void SpdyHttpStream::SetConnectionReused() { | 174 void SpdyHttpStream::SetConnectionReused() { |
175 // SPDY doesn't need an indicator here. | 175 // SPDY doesn't need an indicator here. |
176 } | 176 } |
177 | 177 |
178 void SpdyHttpStream::set_chunk_callback(ChunkCallback* callback) { | |
179 if (request_body_stream_ != NULL) | |
180 request_body_stream_->set_chunk_callback(callback); | |
181 } | |
182 | |
178 int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, | 183 int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, |
179 UploadDataStream* request_body, | 184 UploadDataStream* request_body, |
180 HttpResponseInfo* response, | 185 HttpResponseInfo* response, |
181 CompletionCallback* callback) { | 186 CompletionCallback* callback) { |
182 base::Time request_time = base::Time::Now(); | 187 base::Time request_time = base::Time::Now(); |
183 CHECK(stream_.get()); | 188 CHECK(stream_.get()); |
184 | 189 |
185 stream_->SetDelegate(this); | 190 stream_->SetDelegate(this); |
186 | 191 |
187 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); | 192 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); |
188 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, | 193 CreateSpdyHeadersFromHttpRequest(*request_info_, request_headers, |
189 headers.get(), direct_); | 194 headers.get(), direct_); |
190 stream_->set_spdy_headers(headers); | 195 stream_->set_spdy_headers(headers); |
191 | 196 |
192 stream_->SetRequestTime(request_time); | 197 stream_->SetRequestTime(request_time); |
193 // This should only get called in the case of a request occurring | 198 // This should only get called in the case of a request occurring |
194 // during server push that has already begun but hasn't finished, | 199 // 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 | 200 // so we set the response's request time to be the actual one |
196 if (response_info_) | 201 if (response_info_) |
197 response_info_->request_time = request_time; | 202 response_info_->request_time = request_time; |
198 | 203 |
199 CHECK(!request_body_stream_.get()); | 204 CHECK(!request_body_stream_.get()); |
200 if (request_body) { | 205 if (request_body) { |
201 if (request_body->size()) | 206 if (request_body->size() || request_body->is_chunked()) |
202 request_body_stream_.reset(request_body); | 207 request_body_stream_.reset(request_body); |
203 else | 208 else |
204 delete request_body; | 209 delete request_body; |
205 } | 210 } |
206 | 211 |
207 CHECK(callback); | 212 CHECK(callback); |
208 CHECK(!stream_->cancelled()); | 213 CHECK(!stream_->cancelled()); |
209 CHECK(response); | 214 CHECK(response); |
210 | 215 |
211 if (!stream_->pushed() && stream_->closed()) { | 216 if (!stream_->pushed() && stream_->closed()) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 if (user_callback_) | 256 if (user_callback_) |
252 DoCallback(status); | 257 DoCallback(status); |
253 return request_body_stream_.get() == NULL; | 258 return request_body_stream_.get() == NULL; |
254 } | 259 } |
255 | 260 |
256 int SpdyHttpStream::OnSendBody() { | 261 int SpdyHttpStream::OnSendBody() { |
257 CHECK(request_body_stream_.get()); | 262 CHECK(request_body_stream_.get()); |
258 int buf_len = static_cast<int>(request_body_stream_->buf_len()); | 263 int buf_len = static_cast<int>(request_body_stream_->buf_len()); |
259 if (!buf_len) | 264 if (!buf_len) |
260 return OK; | 265 return OK; |
266 bool is_chunked = request_body_stream_->is_chunked(); | |
261 return stream_->WriteStreamData(request_body_stream_->buf(), buf_len, | 267 return stream_->WriteStreamData(request_body_stream_->buf(), buf_len, |
262 spdy::DATA_FLAG_FIN); | 268 is_chunked ? spdy::DATA_FLAG_NONE : spdy::DATA_FLAG_FIN); |
263 } | 269 } |
264 | 270 |
265 bool SpdyHttpStream::OnSendBodyComplete(int status) { | 271 bool SpdyHttpStream::OnSendBodyComplete(int* status) { |
willchan no longer on Chromium
2011/01/27 18:47:49
You're reusing the same parameter for input and ou
Satish
2011/01/27 20:42:09
The function needs the status code as input and re
willchan no longer on Chromium
2011/01/28 00:56:17
OK, I see what's going on here. You should probabl
| |
266 CHECK(request_body_stream_.get()); | 272 CHECK(request_body_stream_.get()); |
267 request_body_stream_->MarkConsumedAndFillBuffer(status); | 273 request_body_stream_->MarkConsumedAndFillBuffer(*status); |
268 return request_body_stream_->eof(); | 274 |
275 bool is_chunked = request_body_stream_->is_chunked(); | |
276 bool eof = request_body_stream_->eof(); | |
277 if (is_chunked && eof) { | |
278 *status = stream_->WriteStreamData(request_body_stream_->buf(), 0, | |
279 spdy::DATA_FLAG_FIN); | |
280 } else { | |
281 *status = (!is_chunked || request_body_stream_->buf_len()) ? | |
282 OK : ERR_IO_PENDING; | |
283 } | |
284 | |
285 return eof; | |
269 } | 286 } |
270 | 287 |
271 int SpdyHttpStream::OnResponseReceived(const spdy::SpdyHeaderBlock& response, | 288 int SpdyHttpStream::OnResponseReceived(const spdy::SpdyHeaderBlock& response, |
272 base::Time response_time, | 289 base::Time response_time, |
273 int status) { | 290 int status) { |
274 if (!response_info_) { | 291 if (!response_info_) { |
275 DCHECK(stream_->pushed()); | 292 DCHECK(stream_->pushed()); |
276 push_response_info_.reset(new HttpResponseInfo); | 293 push_response_info_.reset(new HttpResponseInfo); |
277 response_info_ = push_response_info_.get(); | 294 response_info_ = push_response_info_.get(); |
278 } | 295 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 stream_->GetSSLInfo(ssl_info, &using_npn); | 444 stream_->GetSSLInfo(ssl_info, &using_npn); |
428 } | 445 } |
429 | 446 |
430 void SpdyHttpStream::GetSSLCertRequestInfo( | 447 void SpdyHttpStream::GetSSLCertRequestInfo( |
431 SSLCertRequestInfo* cert_request_info) { | 448 SSLCertRequestInfo* cert_request_info) { |
432 DCHECK(stream_); | 449 DCHECK(stream_); |
433 stream_->GetSSLCertRequestInfo(cert_request_info); | 450 stream_->GetSSLCertRequestInfo(cert_request_info); |
434 } | 451 } |
435 | 452 |
436 } // namespace net | 453 } // namespace net |
OLD | NEW |