| 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 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_STREAM_H_ | 5 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_STREAM_H_ |
| 6 #define NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_STREAM_H_ | 6 #define NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_STREAM_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "net/quic/quic_protocol.h" | 13 #include "net/quic/quic_protocol.h" |
| 14 #include "net/quic/quic_spdy_stream.h" | 14 #include "net/quic/quic_spdy_stream.h" |
| 15 #include "net/spdy/spdy_framer.h" | 15 #include "net/spdy/spdy_framer.h" |
| 16 #include "net/tools/quic/quic_in_memory_cache.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 | 20 |
| 20 namespace test { | 21 namespace test { |
| 21 class QuicSimpleServerStreamPeer; | 22 class QuicSimpleServerStreamPeer; |
| 22 } // namespace test | 23 } // namespace test |
| 23 | 24 |
| 24 // All this does right now is aggregate data, and on fin, send an HTTP | 25 // All this does right now is aggregate data, and on fin, send an HTTP |
| 25 // response. | 26 // response. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 // Make this stream start from as if it just finished parsing an incoming | 40 // Make this stream start from as if it just finished parsing an incoming |
| 40 // request whose headers are equivalent to |push_request_headers|. | 41 // request whose headers are equivalent to |push_request_headers|. |
| 41 // Doing so will trigger this toy stream to fetch response and send it back. | 42 // Doing so will trigger this toy stream to fetch response and send it back. |
| 42 virtual void PushResponse(SpdyHeaderBlock push_request_headers); | 43 virtual void PushResponse(SpdyHeaderBlock push_request_headers); |
| 43 | 44 |
| 44 // The response body of error responses. | 45 // The response body of error responses. |
| 45 static const char* const kErrorResponseBody; | 46 static const char* const kErrorResponseBody; |
| 46 static const char* const kNotFoundResponseBody; | 47 static const char* const kNotFoundResponseBody; |
| 47 | 48 |
| 48 protected: | 49 protected: |
| 49 // Sends a basic 200 response using SendHeaders for the headers and WriteData | 50 enum State { |
| 50 // for the body. | 51 INIT, |
| 51 virtual void SendResponse(); | 52 SEND_HEADERS, |
| 53 SEND_BODY, |
| 54 SEND_TRAILERS, |
| 55 NONE, |
| 56 }; |
| 52 | 57 |
| 53 // Sends a basic 500 response using SendHeaders for the headers and WriteData | 58 // Sends a basic 500 response using SendHeaders for the headers and WriteData |
| 54 // for the body. | 59 // for the body. |
| 55 virtual void SendErrorResponse(); | 60 virtual void SendErrorResponse(); |
| 56 | 61 |
| 57 // Sends a basic 404 response using SendHeaders for the headers and WriteData | 62 // Sends a basic 404 response using SendHeaders for the headers and WriteData |
| 58 // for the body. | 63 // for the body. |
| 59 void SendNotFoundResponse(); | 64 void SendNotFoundResponse(); |
| 60 | 65 |
| 61 void SendHeadersAndBody(const SpdyHeaderBlock& response_headers, | 66 // Starts or resumes the response as indicated |next_state_|. |
| 62 base::StringPiece body); | 67 void DoLoop(); |
| 63 void SendHeadersAndBodyAndTrailers(const SpdyHeaderBlock& response_headers, | |
| 64 base::StringPiece body, | |
| 65 const SpdyHeaderBlock& response_trailers); | |
| 66 | 68 |
| 67 SpdyHeaderBlock* request_headers() { return &request_headers_; } | 69 SpdyHeaderBlock* request_headers() { return &request_headers_; } |
| 68 | 70 |
| 69 const std::string& body() { return body_; } | 71 const std::string& body() { return body_; } |
| 70 | 72 |
| 73 State next_state_; |
| 74 QuicInMemoryCache::Response response_; |
| 75 |
| 71 private: | 76 private: |
| 77 void Init(); |
| 78 void SendHeaders(); |
| 79 void SendBody(); |
| 80 void SendTrailers(); |
| 81 |
| 72 friend class test::QuicSimpleServerStreamPeer; | 82 friend class test::QuicSimpleServerStreamPeer; |
| 73 | 83 |
| 74 // The parsed headers received from the client. | 84 // The parsed headers received from the client. |
| 75 SpdyHeaderBlock request_headers_; | 85 SpdyHeaderBlock request_headers_; |
| 76 int content_length_; | 86 int content_length_; |
| 77 std::string body_; | 87 std::string body_; |
| 78 | 88 |
| 89 // How many body chunks have been sent. Only relevant to |
| 90 // QuicInMemoryCache::BIDIRECTIONAL. |
| 91 size_t body_chunks_consumed_; |
| 92 |
| 79 DISALLOW_COPY_AND_ASSIGN(QuicSimpleServerStream); | 93 DISALLOW_COPY_AND_ASSIGN(QuicSimpleServerStream); |
| 80 }; | 94 }; |
| 81 | 95 |
| 82 } // namespace net | 96 } // namespace net |
| 83 | 97 |
| 84 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_STREAM_H_ | 98 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_STREAM_H_ |
| OLD | NEW |