00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #ifndef SFML_HTTP_HPP
00026 #define SFML_HTTP_HPP
00027
00029
00031 #include <SFML/System/NonCopyable.hpp>
00032 #include <SFML/Network/IpAddress.hpp>
00033 #include <SFML/Network/TcpSocket.hpp>
00034 #include <map>
00035 #include <string>
00036
00037
00038 namespace sf
00039 {
00044 class SFML_API Http : NonCopyable
00045 {
00046 public :
00047
00052 class SFML_API Request
00053 {
00054 public :
00055
00060 enum Method
00061 {
00062 Get,
00063 Post,
00064 Head
00065 };
00066
00078 Request(const std::string& uri = "/", Method method = Get, const std::string& body = "");
00079
00093 void SetField(const std::string& field, const std::string& value);
00094
00105 void SetMethod(Method method);
00106
00117 void SetUri(const std::string& uri);
00118
00128 void SetHttpVersion(unsigned int major, unsigned int minor);
00129
00140 void SetBody(const std::string& body);
00141
00142 private :
00143
00144 friend class Http;
00145
00155 std::string Prepare() const;
00156
00167 bool HasField(const std::string& field) const;
00168
00170
00172 typedef std::map<std::string, std::string> FieldTable;
00173
00175
00177 FieldTable myFields;
00178 Method myMethod;
00179 std::string myURI;
00180 unsigned int myMajorVersion;
00181 unsigned int myMinorVersion;
00182 std::string myBody;
00183 };
00184
00189 class SFML_API Response
00190 {
00191 public :
00192
00197 enum Status
00198 {
00199
00200 Ok = 200,
00201 Created = 201,
00202 Accepted = 202,
00203 NoContent = 204,
00204 ResetContent = 205,
00205 PartialContent = 206,
00206
00207
00208 MultipleChoices = 300,
00209 MovedPermanently = 301,
00210 MovedTemporarily = 302,
00211 NotModified = 304,
00212
00213
00214 BadRequest = 400,
00215 Unauthorized = 401,
00216 Forbidden = 403,
00217 NotFound = 404,
00218 RangeNotSatisfiable = 407,
00219
00220
00221 InternalServerError = 500,
00222 NotImplemented = 501,
00223 BadGateway = 502,
00224 ServiceNotAvailable = 503,
00225 GatewayTimeout = 504,
00226 VersionNotSupported = 505,
00227
00228
00229 InvalidResponse = 1000,
00230 ConnectionFailed = 1001
00231 };
00232
00239 Response();
00240
00253 const std::string& GetField(const std::string& field) const;
00254
00266 Status GetStatus() const;
00267
00276 unsigned int GetMajorHttpVersion() const;
00277
00286 unsigned int GetMinorHttpVersion() const;
00287
00300 const std::string& GetBody() const;
00301
00302 private :
00303
00304 friend class Http;
00305
00315 void Parse(const std::string& data);
00316
00318
00320 typedef std::map<std::string, std::string> FieldTable;
00321
00323
00325 FieldTable myFields;
00326 Status myStatus;
00327 unsigned int myMajorVersion;
00328 unsigned int myMinorVersion;
00329 std::string myBody;
00330 };
00331
00336 Http();
00337
00352 Http(const std::string& host, unsigned short port = 0);
00353
00369 void SetHost(const std::string& host, unsigned short port = 0);
00370
00389 Response SendRequest(const Request& request, Uint32 timeout = 0);
00390
00391 private :
00392
00394
00396 TcpSocket myConnection;
00397 IpAddress myHost;
00398 std::string myHostName;
00399 unsigned short myPort;
00400 };
00401
00402 }
00403
00404
00405 #endif // SFML_HTTP_HPP
00406
00407