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

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

Issue 1326503003: Added a net::BidirectionalStream to expose a bidirectional streaming interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "net/http/bidirectional_stream.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "net/base/request_priority.h"
9 #include "net/spdy/spdy_buffer.h"
10 #include "net/spdy/spdy_header_block.h"
11 #include "net/spdy/spdy_http_utils.h"
12 #include "net/spdy/spdy_stream.h"
13
14 namespace net {
15
16 BidirectionalStream::BidirectionalStream(
17 const base::WeakPtr<SpdySession>& spdy_session)
18 : spdy_session_(spdy_session), weak_factory_(this) {}
19
20 BidirectionalStream::~BidirectionalStream() {}
21
22 void BidirectionalStream::Start(const HttpRequestInfo* request_info,
23 Delegate* delegate) {
24 delegate_ = delegate;
25 DCHECK(!stream_);
26 if (!spdy_session_)
27 delegate_->OnFailed(ERR_CONNECTION_CLOSED);
28
29 request_info_ = request_info;
30
31 // TODO(xunjieli): Incorporate request priority and NetLog.
32 int rv = stream_request_.StartRequest(
33 SPDY_REQUEST_RESPONSE_STREAM, spdy_session_, request_info_->url,
34 net::DEFAULT_PRIORITY, BoundNetLog(),
35 base::Bind(&BidirectionalStream::OnStreamInitialized,
36 weak_factory_.GetWeakPtr()));
37 if (rv != ERR_IO_PENDING)
38 OnStreamInitialized(rv);
39 }
40
41 void BidirectionalStream::SendData(IOBuffer* data,
42 int length,
43 bool end_stream) {
44 stream_->SendData(data, length,
45 end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND);
46 }
47
48 void BidirectionalStream::OnRequestHeadersSent() {
49 delegate_->OnRequestHeadersSent();
50 }
51
52 SpdyResponseHeadersStatus BidirectionalStream::OnResponseHeadersUpdated(
53 const SpdyHeaderBlock& response_headers) {
54 delegate_->OnHeaders(response_headers);
55 return RESPONSE_HEADERS_ARE_COMPLETE;
56 }
57
58 void BidirectionalStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) {
59 delegate_->OnDataReceived(buffer.Pass());
60 }
61
62 void BidirectionalStream::OnDataSent() {
63 delegate_->OnDataSent();
64 }
65
66 void BidirectionalStream::OnTrailers(const SpdyHeaderBlock& trailers) {
67 delegate_->OnTrailers(trailers);
68 }
69
70 void BidirectionalStream::OnClose(int status) {
71 delegate_->OnClose(status);
72 }
73
74 void BidirectionalStream::SendRequestHeaders() {
75 stream_->SetDelegate(this);
76 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
77 CreateSpdyHeadersFromHttpRequest(*request_info_, request_info_->extra_headers,
78 stream_->GetProtocolVersion(), true,
79 headers.get());
80 bool end_stream = (request_info_->method == "GET");
mef 2015/09/30 16:18:16 I wonder what should happen with different request
xunjieli 2015/10/01 18:41:16 I am not sure. Should we limit the use to POST and
mef 2015/10/07 23:44:56 Yeah, I think it is fine to keep this for now.
81 stream_->SendRequestHeaders(
82 headers.Pass(), end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND);
83 }
84
85 void BidirectionalStream::OnStreamInitialized(int rv) {
86 DCHECK_NE(ERR_IO_PENDING, rv);
87 if (rv == OK) {
88 stream_ = stream_request_.ReleaseStream();
89 SendRequestHeaders();
90 return;
91 }
92 delegate_->OnFailed(rv);
93 }
94
95 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698