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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 void QuicSpdyServerStream::OnFinRead() { | 49 void QuicSpdyServerStream::OnFinRead() { |
50 ReliableQuicStream::OnFinRead(); | 50 ReliableQuicStream::OnFinRead(); |
51 if (write_side_closed() || fin_buffered()) { | 51 if (write_side_closed() || fin_buffered()) { |
52 return; | 52 return; |
53 } | 53 } |
54 | 54 |
55 if (!request_headers_received_) { | 55 if (!request_headers_received_) { |
56 SendErrorResponse(); // We're not done reading headers. | 56 SendErrorResponse(); // We're not done reading headers. |
57 } else if ((headers().content_length_status() == | 57 } else if ((headers_.content_length_status() == |
58 BalsaHeadersEnums::VALID_CONTENT_LENGTH) && | 58 BalsaHeadersEnums::VALID_CONTENT_LENGTH) && |
59 body_.size() != headers().content_length()) { | 59 body_.size() != headers_.content_length()) { |
60 SendErrorResponse(); // Invalid content length | 60 SendErrorResponse(); // Invalid content length |
61 } else { | 61 } else { |
62 SendResponse(); | 62 SendResponse(); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 void QuicSpdyServerStream::SendHeaders( | |
67 const BalsaHeaders& response_headers) { | |
68 SpdyHeaderBlock header_block = | |
69 SpdyUtils::ResponseHeadersToSpdyHeaders(response_headers); | |
70 | |
71 string headers_string; | |
72 headers_string = session()->compressor()->CompressHeaders(header_block); | |
73 | |
74 WriteOrBufferData(headers_string, false); | |
75 } | |
76 | |
77 int QuicSpdyServerStream::ParseRequestHeaders() { | 66 int QuicSpdyServerStream::ParseRequestHeaders() { |
78 size_t read_buf_len = static_cast<size_t>(read_buf_->offset()); | 67 size_t read_buf_len = static_cast<size_t>(read_buf_->offset()); |
79 SpdyFramer framer(SPDY3); | 68 SpdyFramer framer(SPDY3); |
80 SpdyHeaderBlock headers; | 69 SpdyHeaderBlock headers; |
81 char* data = read_buf_->StartOfBuffer(); | 70 char* data = read_buf_->StartOfBuffer(); |
82 size_t len = framer.ParseHeaderBlockInBuffer(data, read_buf_->offset(), | 71 size_t len = framer.ParseHeaderBlockInBuffer(data, read_buf_->offset(), |
83 &headers); | 72 &headers); |
84 if (len == 0) { | 73 if (len == 0) { |
85 return -1; | 74 return -1; |
86 } | 75 } |
(...skipping 29 matching lines...) Expand all Loading... |
116 DLOG(INFO) << "Sending error response for stream " << id(); | 105 DLOG(INFO) << "Sending error response for stream " << id(); |
117 BalsaHeaders headers; | 106 BalsaHeaders headers; |
118 headers.SetResponseFirstlineFromStringPieces( | 107 headers.SetResponseFirstlineFromStringPieces( |
119 "HTTP/1.1", "500", "Server Error"); | 108 "HTTP/1.1", "500", "Server Error"); |
120 headers.ReplaceOrAppendHeader("content-length", "3"); | 109 headers.ReplaceOrAppendHeader("content-length", "3"); |
121 SendHeadersAndBody(headers, "bad"); | 110 SendHeadersAndBody(headers, "bad"); |
122 } | 111 } |
123 | 112 |
124 void QuicSpdyServerStream:: SendHeadersAndBody( | 113 void QuicSpdyServerStream:: SendHeadersAndBody( |
125 const BalsaHeaders& response_headers, | 114 const BalsaHeaders& response_headers, |
126 StringPiece data) { | 115 StringPiece body) { |
127 // We only support SPDY and HTTP, and neither handles bidirectional streaming. | 116 // We only support SPDY and HTTP, and neither handles bidirectional streaming. |
128 if (!read_side_closed()) { | 117 if (!read_side_closed()) { |
129 CloseReadSide(); | 118 CloseReadSide(); |
130 } | 119 } |
131 SendHeaders(response_headers); | 120 |
132 WriteOrBufferData(data, true); | 121 SpdyHeaderBlock header_block = |
| 122 SpdyUtils::ResponseHeadersToSpdyHeaders(response_headers); |
| 123 |
| 124 string headers_string = |
| 125 session()->compressor()->CompressHeaders(header_block); |
| 126 WriteOrBufferData(headers_string, body.empty()); |
| 127 |
| 128 if (!body.empty()) { |
| 129 WriteOrBufferData(body, true); |
| 130 } |
133 } | 131 } |
134 | 132 |
135 } // namespace tools | 133 } // namespace tools |
136 } // namespace net | 134 } // namespace net |
OLD | NEW |