~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/http/public/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
 
/*
2
 
 * Copyright 2010 Google Inc.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
// Author: sligocki@google.com (Shawn Ligocki)
18
 
 
19
 
#ifndef NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_
20
 
#define NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_
21
 
 
22
 
#include <cstdio>                      // for FILE
23
 
#include "net/instaweb/util/public/basictypes.h"
24
 
// TODO(sligocki): Find a way to forward declare FileSystem::InputFile.
25
 
#include "net/instaweb/http/public/response_headers_parser.h"
26
 
#include "net/instaweb/util/public/file_system.h"
27
 
#include "net/instaweb/util/public/string_util.h"
28
 
 
29
 
namespace net_instaweb {
30
 
 
31
 
class MessageHandler;
32
 
class ResponseHeaders;
33
 
class Writer;
34
 
 
35
 
// Helper class to facilitate parsing a raw streaming HTTP response including
36
 
// headers and body.
37
 
class HttpResponseParser {
38
 
 public:
39
 
  HttpResponseParser(ResponseHeaders* response_headers, Writer* writer,
40
 
                     MessageHandler* handler)
41
 
      : reading_headers_(true),
42
 
        ok_(true),
43
 
        response_headers_(response_headers),
44
 
        writer_(writer),
45
 
        handler_(handler),
46
 
        parser_(response_headers) {
47
 
  }
48
 
 
49
 
  // Parse complete HTTP response from a file.
50
 
  bool ParseFile(FileSystem::InputFile* file);
51
 
 
52
 
  // Parse complete HTTP response from a FILE stream.
53
 
  // TODO(sligocki): We need a Readable abstraction (like Writer)
54
 
  bool Parse(FILE* stream);
55
 
 
56
 
  // Read a chunk of HTTP response, populating response_headers and call
57
 
  // writer on output body, returning true if the status is ok.
58
 
  bool ParseChunk(const StringPiece& data);
59
 
 
60
 
  bool ok() const { return ok_; }
61
 
  bool headers_complete() const { return parser_.headers_complete(); }
62
 
 
63
 
 private:
64
 
  bool reading_headers_;
65
 
  bool ok_;
66
 
  ResponseHeaders* response_headers_;
67
 
  Writer* writer_;
68
 
  MessageHandler* handler_;
69
 
  ResponseHeadersParser parser_;
70
 
 
71
 
  DISALLOW_COPY_AND_ASSIGN(HttpResponseParser);
72
 
};
73
 
 
74
 
}  // namespace net_instaweb
75
 
 
76
 
#endif  // NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_