1
// Copyright 2010 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_SPDY_TO_HTTP_CONVERTER_H_
16
#define MOD_SPDY_SPDY_TO_HTTP_CONVERTER_H_
18
#include "base/basictypes.h"
19
#include "net/spdy/spdy_framer.h"
20
#include "net/spdy/spdy_protocol.h"
24
class HttpRequestVisitorInterface;
26
// Incrementally converts SPDY frames to HTTP streams, and passes the HTTP
27
// stream to the specified HttpRequestVisitorInterface.
28
class SpdyToHttpConverter {
30
SpdyToHttpConverter(int spdy_version,
31
HttpRequestVisitorInterface* visitor);
32
~SpdyToHttpConverter();
35
SPDY_CONVERTER_SUCCESS,
36
FRAME_BEFORE_SYN_STREAM, // first frame was not a SYN_STREAM
37
FRAME_AFTER_FIN, // received another frame after a FLAG_FIN
38
EXTRA_SYN_STREAM, // received an additional SYN_STREAM after the first
39
INVALID_HEADER_BLOCK, // the headers could not be parsed
40
BAD_REQUEST // the headers didn't constitute a valid HTTP request
43
static const char* StatusString(Status status);
45
// Return the SPDY version from which we are converting.
46
int spdy_version() const { return framer_.protocol_version(); }
48
// Convert the SPDY frame to HTTP and make appropriate calls to the visitor.
49
// In some cases data may be buffered, but everything will get flushed out to
50
// the visitor by the time the final frame (with FLAG_FIN set) is done.
51
Status ConvertSynStreamFrame(const net::SpdySynStreamControlFrame& frame);
52
Status ConvertHeadersFrame(const net::SpdyHeadersControlFrame& frame);
53
Status ConvertDataFrame(const net::SpdyDataFrame& frame);
56
// Called to generate leading headers from a SYN_STREAM or HEADERS frame.
57
void GenerateLeadingHeaders(const net::SpdyHeaderBlock& block);
58
// Called when there are no more leading headers, because we've received
59
// either data or a FLAG_FIN. This adds any last-minute needed headers
60
// before closing the leading headers section.
61
void EndOfLeadingHeaders();
62
// Called when we see a FLAG_FIN. This terminates the request and appends
63
// whatever trailing headers (if any) we have buffered.
67
NO_FRAMES_YET, // We haven't seen any frames yet.
68
RECEIVED_SYN_STREAM, // We've seen the SYN_STREAM, but no DATA yet.
69
RECEIVED_DATA, // We've seen at least one DATA frame.
70
RECEIVED_FLAG_FIN // We've seen the FLAG_FIN; no more frames allowed.
73
HttpRequestVisitorInterface* const visitor_;
74
net::SpdyFramer framer_;
75
net::SpdyHeaderBlock trailing_headers_;
78
bool seen_accept_encoding_;
80
DISALLOW_COPY_AND_ASSIGN(SpdyToHttpConverter);
83
} // namespace mod_spdy
85
#endif // MOD_SPDY_SPDY_TO_HTTP_CONVERTER_H_