| 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/quic/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 headers[":scheme"] = "http"; | 198 headers[":scheme"] = "http"; |
| 199 headers[":version"] = "HTTP/1.1"; | 199 headers[":version"] = "HTTP/1.1"; |
| 200 request_data_ = SerializeHeaderBlock(headers); | 200 request_data_ = SerializeHeaderBlock(headers); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void SetResponseString(const std::string& status, const std::string& body) { | 203 void SetResponseString(const std::string& status, const std::string& body) { |
| 204 SpdyHeaderBlock headers; | 204 SpdyHeaderBlock headers; |
| 205 headers[":status"] = status; | 205 headers[":status"] = status; |
| 206 headers[":version"] = "HTTP/1.1"; | 206 headers[":version"] = "HTTP/1.1"; |
| 207 headers["content-type"] = "text/plain"; | 207 headers["content-type"] = "text/plain"; |
| 208 response_data_ = SerializeHeaderBlock(headers) + body; | 208 response_data_ = session_->compressor()->CompressHeaders(headers) + body; |
| 209 } | 209 } |
| 210 | 210 |
| 211 std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers) { | 211 std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers) { |
| 212 size_t len = SpdyFramer::GetSerializedLength(3, &headers); | 212 size_t len = SpdyFramer::GetSerializedLength(3, &headers); |
| 213 SpdyFrameBuilder builder(len); | 213 SpdyFrameBuilder builder(len); |
| 214 SpdyFramer::WriteHeaderBlock(&builder, 3, &headers); | 214 SpdyFramer::WriteHeaderBlock(&builder, 3, &headers); |
| 215 scoped_ptr<SpdyFrame> frame(builder.take()); | 215 scoped_ptr<SpdyFrame> frame(builder.take()); |
| 216 return std::string(frame->data(), len); | 216 return std::string(frame->data(), len); |
| 217 } | 217 } |
| 218 | 218 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 callback_.callback())); | 547 callback_.callback())); |
| 548 EXPECT_EQ(&response_, stream_->GetResponseInfo()); | 548 EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
| 549 | 549 |
| 550 // Ack the request. | 550 // Ack the request. |
| 551 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0, 0)); | 551 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0, 0)); |
| 552 ProcessPacket(*ack); | 552 ProcessPacket(*ack); |
| 553 EXPECT_EQ(ERR_IO_PENDING, | 553 EXPECT_EQ(ERR_IO_PENDING, |
| 554 stream_->ReadResponseHeaders(callback_.callback())); | 554 stream_->ReadResponseHeaders(callback_.callback())); |
| 555 | 555 |
| 556 // Send the response with a body. | 556 // Send the response with a body. |
| 557 const char kResponseHeaders[] = "HTTP/1.1 404 OK\r\n" | 557 SetResponseString("404 OK", "hello world!"); |
| 558 "Content-Type: text/plain\r\n\r\nhello world!"; | |
| 559 scoped_ptr<QuicEncryptedPacket> resp( | 558 scoped_ptr<QuicEncryptedPacket> resp( |
| 560 ConstructDataPacket(2, false, kFin, 0, kResponseHeaders)); | 559 ConstructDataPacket(2, false, kFin, 0, response_data_)); |
| 561 | 560 |
| 562 // In the course of processing this packet, the QuicHttpStream close itself. | 561 // In the course of processing this packet, the QuicHttpStream close itself. |
| 563 ProcessPacket(*resp); | 562 ProcessPacket(*resp); |
| 564 | 563 |
| 565 EXPECT_TRUE(AtEof()); | 564 EXPECT_TRUE(AtEof()); |
| 566 } | 565 } |
| 567 | 566 |
| 568 } // namespace test | 567 } // namespace test |
| 569 | 568 |
| 570 } // namespace net | 569 } // namespace net |
| OLD | NEW |