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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 void QuicSpdyServerStream::OnFinRead() { | 50 void QuicSpdyServerStream::OnFinRead() { |
51 ReliableQuicStream::OnFinRead(); | 51 ReliableQuicStream::OnFinRead(); |
52 if (write_side_closed() || fin_buffered()) { | 52 if (write_side_closed() || fin_buffered()) { |
53 return; | 53 return; |
54 } | 54 } |
55 | 55 |
56 if (!request_headers_received_) { | 56 if (!request_headers_received_) { |
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 int 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 = |
73 &headers); | 73 framer.ParseHeaderBlockInBuffer(data, read_buf_->offset(), &headers); |
74 if (len == 0) { | 74 if (len == 0) { |
75 return -1; | 75 return -1; |
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 -1; |
81 } | 81 } |
82 | 82 |
83 size_t delta = read_buf_len - len; | 83 size_t delta = read_buf_len - len; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 void QuicSpdyServerStream::SendErrorResponse() { | 116 void QuicSpdyServerStream::SendErrorResponse() { |
117 DVLOG(1) << "Sending error response for stream " << id(); | 117 DVLOG(1) << "Sending error response for stream " << id(); |
118 BalsaHeaders headers; | 118 BalsaHeaders headers; |
119 headers.SetResponseFirstlineFromStringPieces( | 119 headers.SetResponseFirstlineFromStringPieces( |
120 "HTTP/1.1", "500", "Server Error"); | 120 "HTTP/1.1", "500", "Server Error"); |
121 headers.ReplaceOrAppendHeader("content-length", "3"); | 121 headers.ReplaceOrAppendHeader("content-length", "3"); |
122 SendHeadersAndBody(headers, "bad"); | 122 SendHeadersAndBody(headers, "bad"); |
123 } | 123 } |
124 | 124 |
125 void QuicSpdyServerStream:: SendHeadersAndBody( | 125 void QuicSpdyServerStream::SendHeadersAndBody( |
126 const BalsaHeaders& response_headers, | 126 const BalsaHeaders& response_headers, |
127 StringPiece body) { | 127 StringPiece body) { |
128 // We only support SPDY and HTTP, and neither handles bidirectional streaming. | 128 // We only support SPDY and HTTP, and neither handles bidirectional streaming. |
129 if (!read_side_closed()) { | 129 if (!read_side_closed()) { |
130 CloseReadSide(); | 130 CloseReadSide(); |
131 } | 131 } |
132 | 132 |
133 SpdyHeaderBlock header_block = | 133 SpdyHeaderBlock header_block = |
134 SpdyUtils::ResponseHeadersToSpdyHeaders(response_headers); | 134 SpdyUtils::ResponseHeadersToSpdyHeaders(response_headers); |
135 | 135 |
136 WriteHeaders(header_block, body.empty(), NULL); | 136 WriteHeaders(header_block, body.empty(), NULL); |
137 | 137 |
138 if (!body.empty()) { | 138 if (!body.empty()) { |
139 WriteOrBufferData(body, true, NULL); | 139 WriteOrBufferData(body, true, NULL); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 } // namespace tools | 143 } // namespace tools |
144 } // namespace net | 144 } // namespace net |
OLD | NEW |