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

Side by Side Diff: net/quic/quic_spdy_server_stream.cc

Issue 361083002: Small cleanups to ported QuicServer and dependencies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bring back quic_tools (formerly quic_ported_server) Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/quic/quic_spdy_server_stream.h" 5 #include "net/quic/quic_spdy_server_stream.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "net/quic/quic_in_memory_cache.h" 9 #include "net/quic/quic_in_memory_cache.h"
10 #include "net/quic/quic_session.h" 10 #include "net/quic/quic_session.h"
(...skipping 14 matching lines...) Expand all
25 : QuicDataStream(id, session), 25 : QuicDataStream(id, session),
26 read_buf_(new GrowableIOBuffer()), 26 read_buf_(new GrowableIOBuffer()),
27 request_headers_received_(false) { 27 request_headers_received_(false) {
28 read_buf_->SetCapacity(kHeaderBufInitialSize); 28 read_buf_->SetCapacity(kHeaderBufInitialSize);
29 } 29 }
30 30
31 QuicSpdyServerStream::~QuicSpdyServerStream() { 31 QuicSpdyServerStream::~QuicSpdyServerStream() {
32 } 32 }
33 33
34 uint32 QuicSpdyServerStream::ProcessData(const char* data, uint32 data_len) { 34 uint32 QuicSpdyServerStream::ProcessData(const char* data, uint32 data_len) {
35 if (data_len > INT_MAX) {
Ryan Hamilton 2014/07/02 19:31:31 Is INT_MAX the right type here, since int *might*
wtc 2014/07/02 19:39:08 This protects the cast of 'data_len' to 'int' on l
36 LOG(DFATAL) << "Data length too long: " << data_len;
37 return 0;
38 }
35 // Are we still reading the request headers. 39 // Are we still reading the request headers.
36 if (!request_headers_received_) { 40 if (!request_headers_received_) {
37 // Grow the read buffer if necessary. 41 // Grow the read buffer if necessary.
38 while (read_buf_->RemainingCapacity() < (int)data_len) { 42 while (read_buf_->RemainingCapacity() < (int)data_len) {
wtc 2014/07/02 19:39:08 Please take the opportunity to change this to stat
dmz 2014/07/02 20:58:39 Done.
39 read_buf_->SetCapacity(read_buf_->capacity() * 2); 43 read_buf_->SetCapacity(read_buf_->capacity() * 2);
40 } 44 }
41 memcpy(read_buf_->data(), data, data_len); 45 memcpy(read_buf_->data(), data, data_len);
42 read_buf_->set_offset(read_buf_->offset() + data_len); 46 read_buf_->set_offset(read_buf_->offset() + data_len);
43 // Try parsing the request headers. This will set request_headers_received_ 47 // Try parsing the request headers. This will set request_headers_received_
44 // if successful; if not, it will be tried again with more data. 48 // if successful; if not, it will be tried again with more data.
45 ParseRequestHeaders(); 49 ParseRequestHeaders();
46 } else { 50 } else {
47 body_.append(data, data_len); 51 body_.append(data, data_len);
48 } 52 }
(...skipping 21 matching lines...) Expand all
70 } 74 }
71 75
72 SendResponse(); 76 SendResponse();
73 } 77 }
74 78
75 // Try parsing the request headers. If successful, sets 79 // Try parsing the request headers. If successful, sets
76 // request_headers_received_. If not successful, it can just be tried again once 80 // request_headers_received_. If not successful, it can just be tried again once
77 // there's more data. 81 // there's more data.
78 void QuicSpdyServerStream::ParseRequestHeaders() { 82 void QuicSpdyServerStream::ParseRequestHeaders() {
79 SpdyFramer framer((kDefaultSpdyMajorVersion)); 83 SpdyFramer framer((kDefaultSpdyMajorVersion));
80 char* data = read_buf_->StartOfBuffer(); 84 const char* data = read_buf_->StartOfBuffer();
81 size_t read_buf_len = static_cast<size_t>(read_buf_->offset()); 85 size_t read_buf_len = static_cast<size_t>(read_buf_->offset());
82 size_t len = framer.ParseHeaderBlockInBuffer(data, read_buf_len, &headers_); 86 size_t len = framer.ParseHeaderBlockInBuffer(data, read_buf_len, &headers_);
83 if (len == 0) { 87 if (len == 0) {
84 // Not enough data yet, presumably. (If we still don't succeed by the end of 88 // Not enough data yet, presumably. (If we still don't succeed by the end of
85 // the stream, then we'll error above.) 89 // the stream, then we'll error in OnFinRead().)
86 return; 90 return;
87 } 91 }
88 92
89 // Headers received and parsed: extract the request URL. 93 // Headers received and parsed: extract the request URL.
90 request_url_ = GetUrlFromHeaderBlock(headers_, 94 request_url_ = GetUrlFromHeaderBlock(headers_,
91 kDefaultSpdyMajorVersion, 95 kDefaultSpdyMajorVersion,
92 false); 96 false);
93 if (!request_url_.is_valid()) { 97 if (!request_url_.is_valid()) {
94 SendErrorResponse(); 98 SendErrorResponse();
95 return; 99 return;
(...skipping 22 matching lines...) Expand all
118 CloseConnection(QUIC_NO_ERROR); 122 CloseConnection(QUIC_NO_ERROR);
119 return; 123 return;
120 } 124 }
121 125
122 if (response->response_type() == QuicInMemoryCache::IGNORE_REQUEST) { 126 if (response->response_type() == QuicInMemoryCache::IGNORE_REQUEST) {
123 DVLOG(1) << "Special response: ignoring request."; 127 DVLOG(1) << "Special response: ignoring request.";
124 return; 128 return;
125 } 129 }
126 130
127 DVLOG(1) << "Sending response for stream " << id(); 131 DVLOG(1) << "Sending response for stream " << id();
128 SendHeadersAndBody(response->headers(), response->body()); 132 SendHeadersAndBody(*response->headers(), response->body());
wtc 2014/07/02 19:39:08 Hmm... If we are still dereferencing response->hea
dmz 2014/07/02 20:58:39 Alright, I've undone the change.
129 } 133 }
130 134
131 void QuicSpdyServerStream::SendErrorResponse() { 135 void QuicSpdyServerStream::SendErrorResponse() {
132 DVLOG(1) << "Sending error response for stream " << id(); 136 DVLOG(1) << "Sending error response for stream " << id();
133 scoped_refptr<HttpResponseHeaders> headers 137 scoped_refptr<HttpResponseHeaders> headers
134 = new HttpResponseHeaders(string("HTTP/1.1 500 Server Error") + '\0' + 138 = new HttpResponseHeaders(string("HTTP/1.1 500 Server Error") + '\0' +
135 "content-length: 3" + '\0' + '\0'); 139 "content-length: 3" + '\0' + '\0');
136 SendHeadersAndBody(*headers, "bad"); 140 SendHeadersAndBody(*headers, "bad");
137 } 141 }
138 142
(...skipping 11 matching lines...) Expand all
150 &header_block); 154 &header_block);
151 155
152 WriteHeaders(header_block, body.empty(), NULL); 156 WriteHeaders(header_block, body.empty(), NULL);
153 157
154 if (!body.empty()) { 158 if (!body.empty()) {
155 WriteOrBufferData(body, true, NULL); 159 WriteOrBufferData(body, true, NULL);
156 } 160 }
157 } 161 }
158 162
159 } // namespace net 163 } // namespace net
OLDNEW
« net/quic/quic_in_memory_cache.h ('K') | « net/quic/quic_in_memory_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698