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_spdy_server_stream.h" | 5 #include "net/tools/quic/quic_spdy_server_stream.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "net/quic/quic_session.h" | 8 #include "net/quic/quic_session.h" |
9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
10 #include "net/tools/quic/quic_in_memory_cache.h" | 10 #include "net/tools/quic/quic_in_memory_cache.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 SendErrorResponse(); // We're not done reading headers. | 57 SendErrorResponse(); // We're not done reading headers. |
58 } else if ((headers_.content_length_status() == | 58 } else if ((headers_.content_length_status() == |
59 BalsaHeadersEnums::VALID_CONTENT_LENGTH) && | 59 BalsaHeadersEnums::VALID_CONTENT_LENGTH) && |
60 body_.size() != headers_.content_length()) { | 60 body_.size() != headers_.content_length()) { |
61 SendErrorResponse(); // Invalid content length | 61 SendErrorResponse(); // Invalid content length |
62 } else { | 62 } else { |
63 SendResponse(); | 63 SendResponse(); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 int QuicSpdyServerStream::ParseRequestHeaders() { | 67 void QuicSpdyServerStream::ParseRequestHeaders() { |
68 size_t read_buf_len = static_cast<size_t>(read_buf_->offset()); | 68 size_t read_buf_len = static_cast<size_t>(read_buf_->offset()); |
69 SpdyFramer framer(SPDY3); | 69 SpdyFramer framer(SPDY3); |
70 SpdyHeaderBlock headers; | 70 SpdyHeaderBlock headers; |
71 char* data = read_buf_->StartOfBuffer(); | 71 char* data = read_buf_->StartOfBuffer(); |
72 size_t len = framer.ParseHeaderBlockInBuffer(data, read_buf_->offset(), | 72 size_t len = framer.ParseHeaderBlockInBuffer(data, read_buf_->offset(), |
73 &headers); | 73 &headers); |
74 if (len == 0) { | 74 if (len == 0) { |
75 return -1; | 75 return; |
76 } | 76 } |
77 | 77 |
78 if (!SpdyUtils::FillBalsaRequestHeaders(headers, &headers_)) { | 78 if (!SpdyUtils::FillBalsaRequestHeaders(headers, &headers_)) { |
79 SendErrorResponse(); | 79 SendErrorResponse(); |
80 return -1; | 80 return; |
81 } | 81 } |
82 | 82 |
83 size_t delta = read_buf_len - len; | 83 size_t delta = read_buf_len - len; |
84 if (delta > 0) { | 84 if (delta > 0) { |
85 body_.append(data + len, delta); | 85 body_.append(data + len, delta); |
86 } | 86 } |
87 | 87 |
88 request_headers_received_ = true; | 88 request_headers_received_ = true; |
89 return len; | |
90 } | 89 } |
91 | 90 |
92 void QuicSpdyServerStream::SendResponse() { | 91 void QuicSpdyServerStream::SendResponse() { |
93 // Find response in cache. If not found, send error response. | 92 // Find response in cache. If not found, send error response. |
94 const QuicInMemoryCache::Response* response = | 93 const QuicInMemoryCache::Response* response = |
95 QuicInMemoryCache::GetInstance()->GetResponse(headers_); | 94 QuicInMemoryCache::GetInstance()->GetResponse(headers_); |
96 if (response == NULL) { | 95 if (response == NULL) { |
97 SendErrorResponse(); | 96 SendErrorResponse(); |
98 return; | 97 return; |
99 } | 98 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 134 |
136 WriteHeaders(header_block, body.empty(), NULL); | 135 WriteHeaders(header_block, body.empty(), NULL); |
137 | 136 |
138 if (!body.empty()) { | 137 if (!body.empty()) { |
139 WriteOrBufferData(body, true, NULL); | 138 WriteOrBufferData(body, true, NULL); |
140 } | 139 } |
141 } | 140 } |
142 | 141 |
143 } // namespace tools | 142 } // namespace tools |
144 } // namespace net | 143 } // namespace net |
OLD | NEW |