OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tools/quic/quic_simple_server_stream.h" | 5 #include "net/tools/quic/quic_simple_server_stream.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/tools/quic/quic_simple_server_session.h" | 21 #include "net/tools/quic/quic_simple_server_session.h" |
22 | 22 |
23 using base::StringPiece; | 23 using base::StringPiece; |
24 using base::StringToInt; | 24 using base::StringToInt; |
25 using std::string; | 25 using std::string; |
26 | 26 |
27 namespace net { | 27 namespace net { |
28 | 28 |
29 QuicSimpleServerStream::QuicSimpleServerStream(QuicStreamId id, | 29 QuicSimpleServerStream::QuicSimpleServerStream(QuicStreamId id, |
30 QuicSpdySession* session) | 30 QuicSpdySession* session) |
31 : QuicSpdyStream(id, session), | 31 : QuicSpdyStream(id, session), content_length_(-1) {} |
32 content_length_(-1), | |
33 response_started_(false) {} | |
34 | 32 |
35 QuicSimpleServerStream::~QuicSimpleServerStream() {} | 33 QuicSimpleServerStream::~QuicSimpleServerStream() {} |
36 | 34 |
37 void QuicSimpleServerStream::OnInitialHeadersComplete(bool fin, | 35 void QuicSimpleServerStream::OnInitialHeadersComplete(bool fin, |
38 size_t frame_len) { | 36 size_t frame_len) { |
39 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len); | 37 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len); |
40 if (!SpdyUtils::ParseHeaders(decompressed_headers().data(), | 38 if (!SpdyUtils::ParseHeaders(decompressed_headers().data(), |
41 decompressed_headers().length(), | 39 decompressed_headers().length(), |
42 &content_length_, &request_headers_)) { | 40 &content_length_, &request_headers_)) { |
43 DVLOG(1) << "Invalid headers"; | 41 DVLOG(1) << "Invalid headers"; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 96 } |
99 | 97 |
100 // If the sequencer is closed, then all the body, including the fin, has been | 98 // If the sequencer is closed, then all the body, including the fin, has been |
101 // consumed. | 99 // consumed. |
102 OnFinRead(); | 100 OnFinRead(); |
103 | 101 |
104 if (write_side_closed() || fin_buffered()) { | 102 if (write_side_closed() || fin_buffered()) { |
105 return; | 103 return; |
106 } | 104 } |
107 | 105 |
108 // Subclass could have manually invoked SendResponse earlier. | 106 SendResponse(); |
109 if (!response_started_) { | |
110 SendResponse(); | |
111 } | |
112 } | 107 } |
113 | 108 |
114 void QuicSimpleServerStream::PushResponse( | 109 void QuicSimpleServerStream::PushResponse( |
115 SpdyHeaderBlock push_request_headers) { | 110 SpdyHeaderBlock push_request_headers) { |
116 if (id() % 2 != 0) { | 111 if (id() % 2 != 0) { |
117 QUIC_BUG << "Client initiated stream shouldn't be used as promised stream."; | 112 QUIC_BUG << "Client initiated stream shouldn't be used as promised stream."; |
118 return; | 113 return; |
119 } | 114 } |
120 // Change the stream state to emulate a client request. | 115 // Change the stream state to emulate a client request. |
121 request_headers_ = std::move(push_request_headers); | 116 request_headers_ = std::move(push_request_headers); |
122 content_length_ = 0; | 117 content_length_ = 0; |
123 DVLOG(1) << "Stream " << id() << ": Ready to receive server push response."; | 118 DVLOG(1) << "Stream " << id() << ": Ready to receive server push response."; |
124 | 119 |
125 // Set as if stream decompresed the headers and received fin. | 120 // Set as if stream decompresed the headers and received fin. |
126 QuicSpdyStream::OnInitialHeadersComplete(/*fin=*/true, 0); | 121 QuicSpdyStream::OnInitialHeadersComplete(/*fin=*/true, 0); |
127 } | 122 } |
128 | 123 |
129 void QuicSimpleServerStream::SendResponse() { | 124 void QuicSimpleServerStream::SendResponse() { |
130 DCHECK(!response_started_); | |
131 response_started_ = true; | |
132 | |
133 if (request_headers_.empty()) { | 125 if (request_headers_.empty()) { |
134 DVLOG(1) << "Request headers empty."; | 126 DVLOG(1) << "Request headers empty."; |
135 SendErrorResponse(); | 127 SendErrorResponse(); |
136 return; | 128 return; |
137 } | 129 } |
138 | 130 |
139 if (content_length_ > 0 && | 131 if (content_length_ > 0 && |
140 static_cast<uint64_t>(content_length_) != body_.size()) { | 132 static_cast<uint64_t>(content_length_) != body_.size()) { |
141 DVLOG(1) << "Content length (" << content_length_ << ") != body size (" | 133 DVLOG(1) << "Content length (" << content_length_ << ") != body size (" |
142 << body_.size() << ")."; | 134 << body_.size() << ")."; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 DVLOG(1) << "Writing trailers (fin = true): " | 264 DVLOG(1) << "Writing trailers (fin = true): " |
273 << response_trailers.DebugString(); | 265 << response_trailers.DebugString(); |
274 WriteTrailers(std::move(response_trailers), nullptr); | 266 WriteTrailers(std::move(response_trailers), nullptr); |
275 } | 267 } |
276 | 268 |
277 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; | 269 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; |
278 const char* const QuicSimpleServerStream::kNotFoundResponseBody = | 270 const char* const QuicSimpleServerStream::kNotFoundResponseBody = |
279 "file not found"; | 271 "file not found"; |
280 | 272 |
281 } // namespace net | 273 } // namespace net |
OLD | NEW |