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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_number_conversions.h" | |
13 #include "base/strings/string_piece.h" | |
14 #include "base/strings/string_split.h" | |
15 #include "net/quic/core/quic_bug_tracker.h" | 12 #include "net/quic/core/quic_bug_tracker.h" |
16 #include "net/quic/core/quic_flags.h" | 13 #include "net/quic/core/quic_flags.h" |
17 #include "net/quic/core/quic_spdy_stream.h" | 14 #include "net/quic/core/quic_spdy_stream.h" |
18 #include "net/quic/core/spdy_utils.h" | 15 #include "net/quic/core/spdy_utils.h" |
| 16 #include "net/quic/platform/api/quic_text_utils.h" |
19 #include "net/spdy/spdy_protocol.h" | 17 #include "net/spdy/spdy_protocol.h" |
20 #include "net/tools/quic/quic_http_response_cache.h" | 18 #include "net/tools/quic/quic_http_response_cache.h" |
21 #include "net/tools/quic/quic_simple_server_session.h" | 19 #include "net/tools/quic/quic_simple_server_session.h" |
22 | 20 |
23 using base::StringPiece; | 21 using base::StringPiece; |
24 using base::StringToInt; | |
25 using std::string; | 22 using std::string; |
26 | 23 |
27 namespace net { | 24 namespace net { |
28 | 25 |
29 QuicSimpleServerStream::QuicSimpleServerStream( | 26 QuicSimpleServerStream::QuicSimpleServerStream( |
30 QuicStreamId id, | 27 QuicStreamId id, |
31 QuicSpdySession* session, | 28 QuicSpdySession* session, |
32 QuicHttpResponseCache* response_cache) | 29 QuicHttpResponseCache* response_cache) |
33 : QuicSpdyServerStreamBase(id, session), | 30 : QuicSpdyServerStreamBase(id, session), |
34 content_length_(-1), | 31 content_length_(-1), |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 195 |
199 DVLOG(1) << "Sending response for stream " << id(); | 196 DVLOG(1) << "Sending response for stream " << id(); |
200 SendHeadersAndBodyAndTrailers(response->headers().Clone(), response->body(), | 197 SendHeadersAndBodyAndTrailers(response->headers().Clone(), response->body(), |
201 response->trailers().Clone()); | 198 response->trailers().Clone()); |
202 } | 199 } |
203 | 200 |
204 void QuicSimpleServerStream::SendNotFoundResponse() { | 201 void QuicSimpleServerStream::SendNotFoundResponse() { |
205 DVLOG(1) << "Sending not found response for stream " << id(); | 202 DVLOG(1) << "Sending not found response for stream " << id(); |
206 SpdyHeaderBlock headers; | 203 SpdyHeaderBlock headers; |
207 headers[":status"] = "404"; | 204 headers[":status"] = "404"; |
208 headers["content-length"] = base::IntToString(strlen(kNotFoundResponseBody)); | 205 headers["content-length"] = |
| 206 QuicTextUtils::Uint64ToString(strlen(kNotFoundResponseBody)); |
209 SendHeadersAndBody(std::move(headers), kNotFoundResponseBody); | 207 SendHeadersAndBody(std::move(headers), kNotFoundResponseBody); |
210 } | 208 } |
211 | 209 |
212 void QuicSimpleServerStream::SendErrorResponse() { | 210 void QuicSimpleServerStream::SendErrorResponse() { |
213 DVLOG(1) << "Sending error response for stream " << id(); | 211 DVLOG(1) << "Sending error response for stream " << id(); |
214 SpdyHeaderBlock headers; | 212 SpdyHeaderBlock headers; |
215 headers[":status"] = "500"; | 213 headers[":status"] = "500"; |
216 headers["content-length"] = base::UintToString(strlen(kErrorResponseBody)); | 214 headers["content-length"] = |
| 215 QuicTextUtils::Uint64ToString(strlen(kErrorResponseBody)); |
217 SendHeadersAndBody(std::move(headers), kErrorResponseBody); | 216 SendHeadersAndBody(std::move(headers), kErrorResponseBody); |
218 } | 217 } |
219 | 218 |
220 void QuicSimpleServerStream::SendHeadersAndBody( | 219 void QuicSimpleServerStream::SendHeadersAndBody( |
221 SpdyHeaderBlock response_headers, | 220 SpdyHeaderBlock response_headers, |
222 StringPiece body) { | 221 StringPiece body) { |
223 SendHeadersAndBodyAndTrailers(std::move(response_headers), body, | 222 SendHeadersAndBodyAndTrailers(std::move(response_headers), body, |
224 SpdyHeaderBlock()); | 223 SpdyHeaderBlock()); |
225 } | 224 } |
226 | 225 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 DVLOG(1) << "Writing trailers (fin = true): " | 257 DVLOG(1) << "Writing trailers (fin = true): " |
259 << response_trailers.DebugString(); | 258 << response_trailers.DebugString(); |
260 WriteTrailers(std::move(response_trailers), nullptr); | 259 WriteTrailers(std::move(response_trailers), nullptr); |
261 } | 260 } |
262 | 261 |
263 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; | 262 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; |
264 const char* const QuicSimpleServerStream::kNotFoundResponseBody = | 263 const char* const QuicSimpleServerStream::kNotFoundResponseBody = |
265 "file not found"; | 264 "file not found"; |
266 | 265 |
267 } // namespace net | 266 } // namespace net |
OLD | NEW |