2
* Copyright 2010 Google Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
// Author: sligocki@google.com (Shawn Ligocki)
19
#ifndef NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_
20
#define NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_
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"
29
namespace net_instaweb {
32
class ResponseHeaders;
35
// Helper class to facilitate parsing a raw streaming HTTP response including
37
class HttpResponseParser {
39
HttpResponseParser(ResponseHeaders* response_headers, Writer* writer,
40
MessageHandler* handler)
41
: reading_headers_(true),
43
response_headers_(response_headers),
46
parser_(response_headers) {
49
// Parse complete HTTP response from a file.
50
bool ParseFile(FileSystem::InputFile* file);
52
// Parse complete HTTP response from a FILE stream.
53
// TODO(sligocki): We need a Readable abstraction (like Writer)
54
bool Parse(FILE* stream);
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);
60
bool ok() const { return ok_; }
61
bool headers_complete() const { return parser_.headers_complete(); }
64
bool reading_headers_;
66
ResponseHeaders* response_headers_;
68
MessageHandler* handler_;
69
ResponseHeadersParser parser_;
71
DISALLOW_COPY_AND_ASSIGN(HttpResponseParser);
74
} // namespace net_instaweb
76
#endif // NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_