1
// Copyright 2011 Google Inc.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
15
#ifndef MOD_SPDY_COMMON_HTTP_TO_SPDY_CONVERTER_H_
16
#define MOD_SPDY_COMMON_HTTP_TO_SPDY_CONVERTER_H_
20
#include "base/basictypes.h"
21
#include "base/memory/scoped_ptr.h"
22
#include "base/string_piece.h"
23
#include "mod_spdy/common/http_response_parser.h"
24
#include "net/spdy/spdy_framer.h" // for SpdyHeaderBlock
28
// Parses incoming HTTP response data and converts it into equivalent SPDY
30
class HttpToSpdyConverter {
32
// Interface for the class that will receive frame data from the converter.
36
virtual ~SpdyReceiver();
38
// Receive a SYN_REPLY frame with the given headers. The callee is free to
39
// mutate the headers map (e.g. to add an extra header) before forwarding
40
// it on, but the pointer will not remain valid after this method returns.
41
virtual void ReceiveSynReply(net::SpdyHeaderBlock* headers,
44
// Receive a DATA frame with the given payload. The data pointer will not
45
// remain valid after this method returns.
46
virtual void ReceiveData(base::StringPiece data, bool flag_fin) = 0;
49
DISALLOW_COPY_AND_ASSIGN(SpdyReceiver);
52
// Create a converter that will send frame data to the given receiver. The
53
// converter does *not* gain ownership of the receiver.
54
HttpToSpdyConverter(int spdy_version, SpdyReceiver* receiver);
55
~HttpToSpdyConverter();
57
// Parse and process the next chunk of input; return true on success, false
59
bool ProcessInput(base::StringPiece input_data);
60
bool ProcessInput(const char* data, size_t size) {
61
return ProcessInput(base::StringPiece(data, size));
64
// Flush out any buffered data.
69
scoped_ptr<ConverterImpl> impl_;
70
HttpResponseParser parser_;
72
DISALLOW_COPY_AND_ASSIGN(HttpToSpdyConverter);
75
} // namespace mod_spdy
77
#endif // MOD_SPDY_COMMON_HTTP_TO_SPDY_CONVERTER_H_