Page Speed Optimization Libraries  1.4.26.1
net/instaweb/http/public/http_response_parser.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_
00020 #define NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_
00021 
00022 #include <cstdio>                      
00023 #include "net/instaweb/util/public/basictypes.h"
00025 #include "net/instaweb/http/public/response_headers_parser.h"
00026 #include "net/instaweb/util/public/file_system.h"
00027 #include "net/instaweb/util/public/string_util.h"
00028 
00029 namespace net_instaweb {
00030 
00031 class MessageHandler;
00032 class ResponseHeaders;
00033 class Writer;
00034 
00037 class HttpResponseParser {
00038  public:
00039   HttpResponseParser(ResponseHeaders* response_headers, Writer* writer,
00040                      MessageHandler* handler)
00041       : reading_headers_(true),
00042         ok_(true),
00043         response_headers_(response_headers),
00044         writer_(writer),
00045         handler_(handler),
00046         parser_(response_headers) {
00047   }
00048 
00050   bool ParseFile(FileSystem::InputFile* file);
00051 
00054   bool Parse(FILE* stream);
00055 
00058   bool ParseChunk(const StringPiece& data);
00059 
00060   bool ok() const { return ok_; }
00061   bool headers_complete() const { return parser_.headers_complete(); }
00062 
00063  private:
00064   bool reading_headers_;
00065   bool ok_;
00066   ResponseHeaders* response_headers_;
00067   Writer* writer_;
00068   MessageHandler* handler_;
00069   ResponseHeadersParser parser_;
00070 
00071   DISALLOW_COPY_AND_ASSIGN(HttpResponseParser);
00072 };
00073 
00074 }  
00075 
00076 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_HTTP_RESPONSE_PARSER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines