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

Side by Side Diff: net/tools/quic/quic_simple_server_stream.cc

Issue 1521993006: Rename QuicSpdyServerStream to QuicSimpleServerStream. No behavior change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@109918216
Patch Set: correct NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_STREAM_H_ Created 5 years 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
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_spdy_server_stream.h" 5 #include "net/tools/quic/quic_simple_server_stream.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "net/quic/quic_flags.h" 12 #include "net/quic/quic_flags.h"
13 #include "net/quic/quic_spdy_session.h" 13 #include "net/quic/quic_spdy_session.h"
14 #include "net/quic/quic_spdy_stream.h" 14 #include "net/quic/quic_spdy_stream.h"
15 #include "net/quic/spdy_utils.h" 15 #include "net/quic/spdy_utils.h"
16 #include "net/spdy/spdy_protocol.h" 16 #include "net/spdy/spdy_protocol.h"
17 #include "net/tools/quic/quic_in_memory_cache.h" 17 #include "net/tools/quic/quic_in_memory_cache.h"
18 18
19 using base::StringPiece; 19 using base::StringPiece;
20 using base::StringToInt; 20 using base::StringToInt;
21 using std::string; 21 using std::string;
22 22
23 namespace net { 23 namespace net {
24 namespace tools { 24 namespace tools {
25 25
26 QuicSpdyServerStream::QuicSpdyServerStream(QuicStreamId id, 26 QuicSimpleServerStream::QuicSimpleServerStream(QuicStreamId id,
27 QuicSpdySession* session) 27 QuicSpdySession* session)
28 : QuicSpdyStream(id, session), content_length_(-1) {} 28 : QuicSpdyStream(id, session), content_length_(-1) {}
29 29
30 QuicSpdyServerStream::~QuicSpdyServerStream() { 30 QuicSimpleServerStream::~QuicSimpleServerStream() {}
31 }
32 31
33 void QuicSpdyServerStream::OnInitialHeadersComplete(bool fin, 32 void QuicSimpleServerStream::OnInitialHeadersComplete(bool fin,
34 size_t frame_len) { 33 size_t frame_len) {
35 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len); 34 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len);
36 if (!SpdyUtils::ParseHeaders(decompressed_headers().data(), 35 if (!SpdyUtils::ParseHeaders(decompressed_headers().data(),
37 decompressed_headers().length(), 36 decompressed_headers().length(),
38 &content_length_, &request_headers_)) { 37 &content_length_, &request_headers_)) {
39 DVLOG(1) << "Invalid headers"; 38 DVLOG(1) << "Invalid headers";
40 SendErrorResponse(); 39 SendErrorResponse();
41 } 40 }
42 MarkHeadersConsumed(decompressed_headers().length()); 41 MarkHeadersConsumed(decompressed_headers().length());
43 } 42 }
44 43
45 void QuicSpdyServerStream::OnTrailingHeadersComplete(bool fin, 44 void QuicSimpleServerStream::OnTrailingHeadersComplete(bool fin,
46 size_t frame_len) { 45 size_t frame_len) {
47 LOG(DFATAL) << "Server does not support receiving Trailers."; 46 LOG(DFATAL) << "Server does not support receiving Trailers.";
48 SendErrorResponse(); 47 SendErrorResponse();
49 } 48 }
50 49
51 void QuicSpdyServerStream::OnDataAvailable() { 50 void QuicSimpleServerStream::OnDataAvailable() {
52 while (HasBytesToRead()) { 51 while (HasBytesToRead()) {
53 struct iovec iov; 52 struct iovec iov;
54 if (GetReadableRegions(&iov, 1) == 0) { 53 if (GetReadableRegions(&iov, 1) == 0) {
55 // No more data to read. 54 // No more data to read.
56 break; 55 break;
57 } 56 }
58 DVLOG(1) << "Processed " << iov.iov_len << " bytes for stream " << id(); 57 DVLOG(1) << "Processed " << iov.iov_len << " bytes for stream " << id();
59 body_.append(static_cast<char*>(iov.iov_base), iov.iov_len); 58 body_.append(static_cast<char*>(iov.iov_base), iov.iov_len);
60 59
61 if (content_length_ >= 0 && 60 if (content_length_ >= 0 &&
(...skipping 28 matching lines...) Expand all
90 content_length_ != static_cast<int>(body_.size())) { 89 content_length_ != static_cast<int>(body_.size())) {
91 DVLOG(1) << "Content length (" << content_length_ << ") != body size (" 90 DVLOG(1) << "Content length (" << content_length_ << ") != body size ("
92 << body_.size() << ")."; 91 << body_.size() << ").";
93 SendErrorResponse(); 92 SendErrorResponse();
94 return; 93 return;
95 } 94 }
96 95
97 SendResponse(); 96 SendResponse();
98 } 97 }
99 98
100 void QuicSpdyServerStream::SendResponse() { 99 void QuicSimpleServerStream::SendResponse() {
101 if (!ContainsKey(request_headers_, ":authority") || 100 if (!ContainsKey(request_headers_, ":authority") ||
102 !ContainsKey(request_headers_, ":path")) { 101 !ContainsKey(request_headers_, ":path")) {
103 DVLOG(1) << "Request headers do not contain :authority or :path."; 102 DVLOG(1) << "Request headers do not contain :authority or :path.";
104 SendErrorResponse(); 103 SendErrorResponse();
105 return; 104 return;
106 } 105 }
107 106
108 // Find response in cache. If not found, send error response. 107 // Find response in cache. If not found, send error response.
109 const QuicInMemoryCache::Response* response = 108 const QuicInMemoryCache::Response* response =
110 QuicInMemoryCache::GetInstance()->GetResponse( 109 QuicInMemoryCache::GetInstance()->GetResponse(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 << " result in response code " << response_code; 150 << " result in response code " << response_code;
152 Reset(QUIC_STREAM_CANCELLED); 151 Reset(QUIC_STREAM_CANCELLED);
153 return; 152 return;
154 } 153 }
155 } 154 }
156 DVLOG(1) << "Sending response for stream " << id(); 155 DVLOG(1) << "Sending response for stream " << id();
157 SendHeadersAndBodyAndTrailers(response->headers(), response->body(), 156 SendHeadersAndBodyAndTrailers(response->headers(), response->body(),
158 response->trailers()); 157 response->trailers());
159 } 158 }
160 159
161 void QuicSpdyServerStream::SendErrorResponse() { 160 void QuicSimpleServerStream::SendErrorResponse() {
162 DVLOG(1) << "Sending error response for stream " << id(); 161 DVLOG(1) << "Sending error response for stream " << id();
163 SpdyHeaderBlock headers; 162 SpdyHeaderBlock headers;
164 headers[":status"] = "500"; 163 headers[":status"] = "500";
165 headers["content-length"] = base::UintToString(strlen(kErrorResponseBody)); 164 headers["content-length"] = base::UintToString(strlen(kErrorResponseBody));
166 SendHeadersAndBody(headers, kErrorResponseBody); 165 SendHeadersAndBody(headers, kErrorResponseBody);
167 } 166 }
168 167
169 void QuicSpdyServerStream::SendHeadersAndBody( 168 void QuicSimpleServerStream::SendHeadersAndBody(
170 const SpdyHeaderBlock& response_headers, 169 const SpdyHeaderBlock& response_headers,
171 StringPiece body) { 170 StringPiece body) {
172 SendHeadersAndBodyAndTrailers(response_headers, body, SpdyHeaderBlock()); 171 SendHeadersAndBodyAndTrailers(response_headers, body, SpdyHeaderBlock());
173 } 172 }
174 173
175 void QuicSpdyServerStream::SendHeadersAndBodyAndTrailers( 174 void QuicSimpleServerStream::SendHeadersAndBodyAndTrailers(
176 const SpdyHeaderBlock& response_headers, 175 const SpdyHeaderBlock& response_headers,
177 StringPiece body, 176 StringPiece body,
178 const SpdyHeaderBlock& response_trailers) { 177 const SpdyHeaderBlock& response_trailers) {
179 // This server only supports SPDY and HTTP, and neither handles bidirectional 178 // This server only supports SPDY and HTTP, and neither handles bidirectional
180 // streaming. 179 // streaming.
181 if (!reading_stopped()) { 180 if (!reading_stopped()) {
182 StopReading(); 181 StopReading();
183 } 182 }
184 183
185 // Send the headers, with a FIN if there's nothing else to send. 184 // Send the headers, with a FIN if there's nothing else to send.
(...skipping 15 matching lines...) Expand all
201 // Nothing else to send. 200 // Nothing else to send.
202 return; 201 return;
203 } 202 }
204 203
205 // Send the trailers. A FIN is always sent with trailers. 204 // Send the trailers. A FIN is always sent with trailers.
206 DVLOG(1) << "Writing trailers (fin = true): " 205 DVLOG(1) << "Writing trailers (fin = true): "
207 << response_trailers.DebugString(); 206 << response_trailers.DebugString();
208 WriteTrailers(response_trailers, nullptr); 207 WriteTrailers(response_trailers, nullptr);
209 } 208 }
210 209
211 const char* const QuicSpdyServerStream::kErrorResponseBody = "bad"; 210 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad";
212 211
213 } // namespace tools 212 } // namespace tools
214 } // namespace net 213 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_server_stream.h ('k') | net/tools/quic/quic_simple_server_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698