~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/http_response_parser.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 2011 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_COMMON_HTTP_RESPONSE_PARSER_H_
16
 
#define MOD_SPDY_COMMON_HTTP_RESPONSE_PARSER_H_
17
 
 
18
 
#include <string>
19
 
 
20
 
#include "base/basictypes.h"
21
 
#include "base/string_piece.h"
22
 
 
23
 
namespace mod_spdy {
24
 
 
25
 
class HttpResponseVisitorInterface;
26
 
 
27
 
// Parses incoming HTTP response data.  Data is fed in piece by piece with the
28
 
// ProcessInput method, and appropriate methods are called on the visitor.
29
 
// There is no need to indicate the end of the input, as this is inferred from
30
 
// the Content-Length or Transfer-Encoding headers.  If the response uses
31
 
// chunked encoding, the parser will de-chunk it.  Note that all data after the
32
 
// end of the response body, including trailing headers, will be completely
33
 
// ignored.
34
 
class HttpResponseParser {
35
 
 public:
36
 
  explicit HttpResponseParser(HttpResponseVisitorInterface* visitor);
37
 
  ~HttpResponseParser();
38
 
 
39
 
  // Return true on success, false on failure.
40
 
  bool ProcessInput(const base::StringPiece& input_data);
41
 
  bool ProcessInput(const char* data, size_t size) {
42
 
    return ProcessInput(base::StringPiece(data, size));
43
 
  }
44
 
 
45
 
  // For unit testing only: Get the remaining number of bytes expected (in the
46
 
  // whole response, if we used Content-Length, or just in the current chunk,
47
 
  // if we used Transfer-Encoding: chunked).
48
 
  uint64 GetRemainingBytesForTest() const { return remaining_bytes_; }
49
 
 
50
 
 private:
51
 
  enum ParserState {
52
 
    STATUS_LINE,
53
 
    LEADING_HEADERS,
54
 
    LEADING_HEADERS_CHECK_NEXT_LINE,
55
 
    CHUNK_START,
56
 
    BODY_DATA,
57
 
    CHUNK_ENDING,
58
 
    COMPLETE
59
 
  };
60
 
 
61
 
  enum BodyType {
62
 
    NO_BODY,
63
 
    UNCHUNKED_BODY,
64
 
    CHUNKED_BODY
65
 
  };
66
 
 
67
 
  bool ProcessStatusLine(base::StringPiece* data);
68
 
  bool CheckStartOfHeaderLine(const base::StringPiece& data);
69
 
  bool ProcessLeadingHeaders(base::StringPiece* data);
70
 
  bool ProcessChunkStart(base::StringPiece* data);
71
 
  bool ProcessBodyData(base::StringPiece* data);
72
 
  bool ProcessChunkEnding(base::StringPiece* data);
73
 
 
74
 
  bool ParseStatusLine(const base::StringPiece& text);
75
 
  bool ParseLeadingHeader(const base::StringPiece& text);
76
 
  bool ParseChunkStart(const base::StringPiece& text);
77
 
 
78
 
  HttpResponseVisitorInterface* const visitor_;
79
 
  ParserState state_;
80
 
  BodyType body_type_;
81
 
  uint64 remaining_bytes_;
82
 
  std::string buffer_;
83
 
 
84
 
  DISALLOW_COPY_AND_ASSIGN(HttpResponseParser);
85
 
};
86
 
 
87
 
}  // namespace mod_spdy
88
 
 
89
 
#endif  // MOD_SPDY_COMMON_HTTP_RESPONSE_PARSER_H_