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

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

Issue 2093553004: Reduce SpdyHeaderBlock copies with move semantics in shared code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove non-shared files (into a separate CL). Created 4 years, 5 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
« no previous file with comments | « net/tools/quic/quic_simple_server_stream.h ('k') | net/tools/quic/quic_spdy_client_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
13 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
14 #include "net/quic/quic_bug_tracker.h" 15 #include "net/quic/quic_bug_tracker.h"
15 #include "net/quic/quic_flags.h" 16 #include "net/quic/quic_flags.h"
16 #include "net/quic/quic_spdy_stream.h" 17 #include "net/quic/quic_spdy_stream.h"
17 #include "net/quic/spdy_utils.h" 18 #include "net/quic/spdy_utils.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 DVLOG(1) << "Sending response for stream " << id(); 205 DVLOG(1) << "Sending response for stream " << id();
205 SendHeadersAndBodyAndTrailers(response->headers(), response->body(), 206 SendHeadersAndBodyAndTrailers(response->headers(), response->body(),
206 response->trailers()); 207 response->trailers());
207 } 208 }
208 209
209 void QuicSimpleServerStream::SendNotFoundResponse() { 210 void QuicSimpleServerStream::SendNotFoundResponse() {
210 DVLOG(1) << "Sending not found response for stream " << id(); 211 DVLOG(1) << "Sending not found response for stream " << id();
211 SpdyHeaderBlock headers; 212 SpdyHeaderBlock headers;
212 headers[":status"] = "404"; 213 headers[":status"] = "404";
213 headers["content-length"] = base::IntToString(strlen(kNotFoundResponseBody)); 214 headers["content-length"] = base::IntToString(strlen(kNotFoundResponseBody));
214 SendHeadersAndBody(headers, kNotFoundResponseBody); 215 SendHeadersAndBody(std::move(headers), kNotFoundResponseBody);
215 } 216 }
216 217
217 void QuicSimpleServerStream::SendErrorResponse() { 218 void QuicSimpleServerStream::SendErrorResponse() {
218 DVLOG(1) << "Sending error response for stream " << id(); 219 DVLOG(1) << "Sending error response for stream " << id();
219 SpdyHeaderBlock headers; 220 SpdyHeaderBlock headers;
220 headers[":status"] = "500"; 221 headers[":status"] = "500";
221 headers["content-length"] = base::UintToString(strlen(kErrorResponseBody)); 222 headers["content-length"] = base::UintToString(strlen(kErrorResponseBody));
222 SendHeadersAndBody(headers, kErrorResponseBody); 223 SendHeadersAndBody(std::move(headers), kErrorResponseBody);
223 } 224 }
224 225
225 void QuicSimpleServerStream::SendHeadersAndBody( 226 void QuicSimpleServerStream::SendHeadersAndBody(
226 const SpdyHeaderBlock& response_headers, 227 SpdyHeaderBlock response_headers,
227 StringPiece body) { 228 StringPiece body) {
228 SendHeadersAndBodyAndTrailers(response_headers, body, SpdyHeaderBlock()); 229 SendHeadersAndBodyAndTrailers(std::move(response_headers), body,
230 SpdyHeaderBlock());
229 } 231 }
230 232
231 void QuicSimpleServerStream::SendHeadersAndBodyAndTrailers( 233 void QuicSimpleServerStream::SendHeadersAndBodyAndTrailers(
232 const SpdyHeaderBlock& response_headers, 234 SpdyHeaderBlock response_headers,
233 StringPiece body, 235 StringPiece body,
234 const SpdyHeaderBlock& response_trailers) { 236 SpdyHeaderBlock response_trailers) {
235 // This server only supports SPDY and HTTP, and neither handles bidirectional 237 // This server only supports SPDY and HTTP, and neither handles bidirectional
236 // streaming. 238 // streaming.
237 if (!reading_stopped()) { 239 if (!reading_stopped()) {
238 StopReading(); 240 StopReading();
239 } 241 }
240 242
241 // Send the headers, with a FIN if there's nothing else to send. 243 // Send the headers, with a FIN if there's nothing else to send.
242 bool send_fin = (body.empty() && response_trailers.empty()); 244 bool send_fin = (body.empty() && response_trailers.empty());
243 DVLOG(1) << "Writing headers (fin = " << send_fin 245 DVLOG(1) << "Writing headers (fin = " << send_fin
244 << ") : " << response_headers.DebugString(); 246 << ") : " << response_headers.DebugString();
245 WriteHeaders(response_headers, send_fin, nullptr); 247 WriteHeaders(std::move(response_headers), send_fin, nullptr);
246 if (send_fin) { 248 if (send_fin) {
247 // Nothing else to send. 249 // Nothing else to send.
248 return; 250 return;
249 } 251 }
250 252
251 // Send the body, with a FIN if there's nothing else to send. 253 // Send the body, with a FIN if there's nothing else to send.
252 send_fin = response_trailers.empty(); 254 send_fin = response_trailers.empty();
253 DVLOG(1) << "Writing body (fin = " << send_fin 255 DVLOG(1) << "Writing body (fin = " << send_fin
254 << ") with size: " << body.size(); 256 << ") with size: " << body.size();
255 WriteOrBufferData(body, send_fin, nullptr); 257 WriteOrBufferData(body, send_fin, nullptr);
256 if (send_fin) { 258 if (send_fin) {
257 // Nothing else to send. 259 // Nothing else to send.
258 return; 260 return;
259 } 261 }
260 262
261 // Send the trailers. A FIN is always sent with trailers. 263 // Send the trailers. A FIN is always sent with trailers.
262 DVLOG(1) << "Writing trailers (fin = true): " 264 DVLOG(1) << "Writing trailers (fin = true): "
263 << response_trailers.DebugString(); 265 << response_trailers.DebugString();
264 WriteTrailers(response_trailers, nullptr); 266 WriteTrailers(std::move(response_trailers), nullptr);
265 } 267 }
266 268
267 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad"; 269 const char* const QuicSimpleServerStream::kErrorResponseBody = "bad";
268 const char* const QuicSimpleServerStream::kNotFoundResponseBody = 270 const char* const QuicSimpleServerStream::kNotFoundResponseBody =
269 "file not found"; 271 "file not found";
270 272
271 } // namespace net 273 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_server_stream.h ('k') | net/tools/quic/quic_spdy_client_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698