1
// Copyright 2011 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_COMMON_HTTP_RESPONSE_PARSER_H_
16
#define MOD_SPDY_COMMON_HTTP_RESPONSE_PARSER_H_
20
#include "base/basictypes.h"
21
#include "base/string_piece.h"
25
class HttpResponseVisitorInterface;
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
34
class HttpResponseParser {
36
explicit HttpResponseParser(HttpResponseVisitorInterface* visitor);
37
~HttpResponseParser();
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));
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_; }
54
LEADING_HEADERS_CHECK_NEXT_LINE,
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);
74
bool ParseStatusLine(const base::StringPiece& text);
75
bool ParseLeadingHeader(const base::StringPiece& text);
76
bool ParseChunkStart(const base::StringPiece& text);
78
HttpResponseVisitorInterface* const visitor_;
81
uint64 remaining_bytes_;
84
DISALLOW_COPY_AND_ASSIGN(HttpResponseParser);
87
} // namespace mod_spdy
89
#endif // MOD_SPDY_COMMON_HTTP_RESPONSE_PARSER_H_