HTTPInputStream.h
Go to the documentation of this file.00001 #ifndef HTTP_INPUT_STREAM_H
00002 #define HTTP_INPUT_STREAM_H
00003
00004 #include <string>
00005 #include "InputStream.h"
00006
00007 enum tHTTPResponse
00008 {
00009 kHTTPSuccess,
00010 kHTTPRedirect,
00011 kHTTPUnknown
00012 };
00013
00014
00015
00016 class HTTPInputStream : public InputStream {
00017 public:
00018 HTTPInputStream(const std::string & url);
00019 virtual ~HTTPInputStream();
00020
00021 virtual char Peek();
00022 virtual char Read();
00023 virtual void Close();
00024
00025 virtual bool IsOpen() const;
00026 virtual bool IsDone() const;
00027 virtual std::string GetLocation() const
00028 {
00029 return location;
00030 }
00031
00032 private:
00033 void Init();
00034 void ParseURL(const std::string & url);
00035 void OpenConnection();
00036 void SendRequest();
00037 tHTTPResponse ParseHTTPStatusLine(std::string & reasonPhrase);
00038 void ParseHTTPHeaders();
00039 void ParseContentLength(const std::string & line);
00040 void ParseLocation(const std::string & line);
00041 void ReadHeaderLine(std::string & line);
00042 void ReadByte();
00043 bool IsSuccessfulResponse(int statusCode);
00044 bool IsRedirectResponse(int statusCode);
00045 void DumpResponse();
00046
00047 std::string host;
00048 int port;
00049 std::string path;
00050 int sockfd;
00051 int contentLength;
00052 std::string location;
00053 int numRead;
00054 bool done;
00055 char nextByte;
00056 };
00057
00058
00059 #endif