| OLD | NEW |
| 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 Loading... |
| 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) { |
| 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() < static_cast<int>(data_len)) { |
| 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 20 matching lines...) Expand all Loading... |
| 69 return; | 73 return; |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |