~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/third_party/mod_spdy/src/mod_spdy/common/spdy_to_http_converter.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2010 Google Inc.
2
 
//
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
6
 
//
7
 
//      http://www.apache.org/licenses/LICENSE-2.0
8
 
//
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.
14
 
 
15
 
#ifndef MOD_SPDY_SPDY_TO_HTTP_CONVERTER_H_
16
 
#define MOD_SPDY_SPDY_TO_HTTP_CONVERTER_H_
17
 
 
18
 
#include "base/basictypes.h"
19
 
#include "net/spdy/spdy_framer.h"
20
 
#include "net/spdy/spdy_protocol.h"
21
 
 
22
 
namespace mod_spdy {
23
 
 
24
 
class HttpRequestVisitorInterface;
25
 
 
26
 
// Incrementally converts SPDY frames to HTTP streams, and passes the HTTP
27
 
// stream to the specified HttpRequestVisitorInterface.
28
 
class SpdyToHttpConverter {
29
 
 public:
30
 
  SpdyToHttpConverter(int spdy_version,
31
 
                      HttpRequestVisitorInterface* visitor);
32
 
  ~SpdyToHttpConverter();
33
 
 
34
 
  enum Status {
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
41
 
  };
42
 
 
43
 
  static const char* StatusString(Status status);
44
 
 
45
 
  // Return the SPDY version from which we are converting.
46
 
  int spdy_version() const { return framer_.protocol_version(); }
47
 
 
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);
54
 
 
55
 
private:
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.
64
 
  void FinishRequest();
65
 
 
66
 
  enum State {
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.
71
 
  };
72
 
 
73
 
  HttpRequestVisitorInterface* const visitor_;
74
 
  net::SpdyFramer framer_;
75
 
  net::SpdyHeaderBlock trailing_headers_;
76
 
  State state_;
77
 
  bool use_chunking_;
78
 
  bool seen_accept_encoding_;
79
 
 
80
 
  DISALLOW_COPY_AND_ASSIGN(SpdyToHttpConverter);
81
 
};
82
 
 
83
 
}  // namespace mod_spdy
84
 
 
85
 
#endif  // MOD_SPDY_SPDY_TO_HTTP_CONVERTER_H_