| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 void QuicSpdyServerStream::SendHeaders( | 66 void QuicSpdyServerStream::SendHeaders( |
| 67 const BalsaHeaders& response_headers) { | 67 const BalsaHeaders& response_headers) { |
| 68 SpdyHeaderBlock header_block = | 68 SpdyHeaderBlock header_block = |
| 69 SpdyUtils::ResponseHeadersToSpdyHeaders(response_headers); | 69 SpdyUtils::ResponseHeadersToSpdyHeaders(response_headers); |
| 70 | 70 |
| 71 string headers_string; | 71 string headers_string; |
| 72 headers_string = session()->compressor()->CompressHeaders(header_block); | 72 headers_string = session()->compressor()->CompressHeaders(header_block); |
| 73 | 73 |
| 74 WriteData(headers_string, false); | 74 WriteOrBufferData(headers_string, false); |
| 75 } | 75 } |
| 76 | 76 |
| 77 int QuicSpdyServerStream::ParseRequestHeaders() { | 77 int QuicSpdyServerStream::ParseRequestHeaders() { |
| 78 size_t read_buf_len = static_cast<size_t>(read_buf_->offset()); | 78 size_t read_buf_len = static_cast<size_t>(read_buf_->offset()); |
| 79 SpdyFramer framer(SPDY3); | 79 SpdyFramer framer(SPDY3); |
| 80 SpdyHeaderBlock headers; | 80 SpdyHeaderBlock headers; |
| 81 char* data = read_buf_->StartOfBuffer(); | 81 char* data = read_buf_->StartOfBuffer(); |
| 82 size_t len = framer.ParseHeaderBlockInBuffer(data, read_buf_->offset(), | 82 size_t len = framer.ParseHeaderBlockInBuffer(data, read_buf_->offset(), |
| 83 &headers); | 83 &headers); |
| 84 if (len == 0) { | 84 if (len == 0) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 102 void QuicSpdyServerStream::SendResponse() { | 102 void QuicSpdyServerStream::SendResponse() { |
| 103 // Find response in cache. If not found, send error response. | 103 // Find response in cache. If not found, send error response. |
| 104 const QuicInMemoryCache::Response* response = | 104 const QuicInMemoryCache::Response* response = |
| 105 QuicInMemoryCache::GetInstance()->GetResponse(headers_); | 105 QuicInMemoryCache::GetInstance()->GetResponse(headers_); |
| 106 if (response == NULL) { | 106 if (response == NULL) { |
| 107 SendErrorResponse(); | 107 SendErrorResponse(); |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 | 110 |
| 111 DLOG(INFO) << "Sending response for stream " << id(); | 111 DLOG(INFO) << "Sending response for stream " << id(); |
| 112 SendHeaders(response->headers()); | 112 SendHeadersAndBody(response->headers(), response->body()); |
| 113 WriteData(response->body(), true); | |
| 114 } | 113 } |
| 115 | 114 |
| 116 void QuicSpdyServerStream::SendErrorResponse() { | 115 void QuicSpdyServerStream::SendErrorResponse() { |
| 117 DLOG(INFO) << "Sending error response for stream " << id(); | 116 DLOG(INFO) << "Sending error response for stream " << id(); |
| 118 BalsaHeaders headers; | 117 BalsaHeaders headers; |
| 119 headers.SetResponseFirstlineFromStringPieces( | 118 headers.SetResponseFirstlineFromStringPieces( |
| 120 "HTTP/1.1", "500", "Server Error"); | 119 "HTTP/1.1", "500", "Server Error"); |
| 121 headers.ReplaceOrAppendHeader("content-length", "3"); | 120 headers.ReplaceOrAppendHeader("content-length", "3"); |
| 122 SendHeaders(headers); | 121 SendHeadersAndBody(headers, "bad"); |
| 123 WriteData("bad", true); | |
| 124 } | 122 } |
| 125 | 123 |
| 126 QuicConsumedData QuicSpdyServerStream::WriteData(StringPiece data, bool fin) { | 124 void QuicSpdyServerStream:: SendHeadersAndBody( |
| 125 const BalsaHeaders& response_headers, |
| 126 StringPiece data) { |
| 127 // We only support SPDY and HTTP, and neither handles bidirectional streaming. | 127 // We only support SPDY and HTTP, and neither handles bidirectional streaming. |
| 128 if (!read_side_closed()) { | 128 if (!read_side_closed()) { |
| 129 CloseReadSide(); | 129 CloseReadSide(); |
| 130 } | 130 } |
| 131 return ReliableQuicStream::WriteData(data, fin); | 131 SendHeaders(response_headers); |
| 132 WriteOrBufferData(data, true); |
| 132 } | 133 } |
| 133 | 134 |
| 134 } // namespace tools | 135 } // namespace tools |
| 135 } // namespace net | 136 } // namespace net |
| OLD | NEW |