net/include/pion/net/HTTPTypes.hpp

00001 // ------------------------------------------------------------------
00002 // pion-net: a C++ framework for building lightweight HTTP interfaces
00003 // ------------------------------------------------------------------
00004 // Copyright (C) 2007-2008 Atomic Labs, Inc.  (http://www.atomiclabs.com)
00005 //
00006 // Distributed under the Boost Software License, Version 1.0.
00007 // See http://www.boost.org/LICENSE_1_0.txt
00008 //
00009 
00010 #ifndef __PION_HTTPTYPES_HEADER__
00011 #define __PION_HTTPTYPES_HEADER__
00012 
00013 #include <string>
00014 #include <pion/PionConfig.hpp>
00015 #include <pion/PionHashMap.hpp>
00016 
00017 
00018 namespace pion {    // begin namespace pion
00019 namespace net {     // begin namespace net (Pion Network Library)
00020 
00024 struct PION_NET_API HTTPTypes
00025 {
00027     virtual ~HTTPTypes() {}
00028     
00029     // generic strings used by HTTP
00030     static const std::string    STRING_EMPTY;
00031     static const std::string    STRING_CRLF;
00032     static const std::string    STRING_HTTP_VERSION;
00033     static const std::string    HEADER_NAME_VALUE_DELIMITER;
00034     
00035     // common HTTP header names
00036     static const std::string    HEADER_HOST;
00037     static const std::string    HEADER_COOKIE;
00038     static const std::string    HEADER_SET_COOKIE;
00039     static const std::string    HEADER_CONNECTION;
00040     static const std::string    HEADER_CONTENT_TYPE;
00041     static const std::string    HEADER_CONTENT_LENGTH;
00042     static const std::string    HEADER_CONTENT_LOCATION;
00043     static const std::string    HEADER_CONTENT_ENCODING;
00044     static const std::string    HEADER_LAST_MODIFIED;
00045     static const std::string    HEADER_IF_MODIFIED_SINCE;
00046     static const std::string    HEADER_TRANSFER_ENCODING;
00047     static const std::string    HEADER_LOCATION;
00048     static const std::string    HEADER_AUTHORIZATION;
00049     static const std::string    HEADER_REFERER;
00050     static const std::string    HEADER_USER_AGENT;
00051     static const std::string    HEADER_X_FORWARDED_FOR;
00052 
00053     // common HTTP content types
00054     static const std::string    CONTENT_TYPE_HTML;
00055     static const std::string    CONTENT_TYPE_TEXT;
00056     static const std::string    CONTENT_TYPE_XML;
00057     static const std::string    CONTENT_TYPE_URLENCODED;
00058     
00059     // common HTTP request methods
00060     static const std::string    REQUEST_METHOD_HEAD;
00061     static const std::string    REQUEST_METHOD_GET;
00062     static const std::string    REQUEST_METHOD_PUT;
00063     static const std::string    REQUEST_METHOD_POST;
00064     static const std::string    REQUEST_METHOD_DELETE;
00065     
00066     // common HTTP response messages
00067     static const std::string    RESPONSE_MESSAGE_OK;
00068     static const std::string    RESPONSE_MESSAGE_CREATED;
00069     static const std::string    RESPONSE_MESSAGE_NO_CONTENT;
00070     static const std::string    RESPONSE_MESSAGE_FOUND;
00071     static const std::string    RESPONSE_MESSAGE_UNAUTHORIZED;
00072     static const std::string    RESPONSE_MESSAGE_FORBIDDEN;
00073     static const std::string    RESPONSE_MESSAGE_NOT_FOUND;
00074     static const std::string    RESPONSE_MESSAGE_METHOD_NOT_ALLOWED;
00075     static const std::string    RESPONSE_MESSAGE_NOT_MODIFIED;
00076     static const std::string    RESPONSE_MESSAGE_BAD_REQUEST;
00077     static const std::string    RESPONSE_MESSAGE_SERVER_ERROR;
00078     static const std::string    RESPONSE_MESSAGE_NOT_IMPLEMENTED;
00079     static const std::string    RESPONSE_MESSAGE_CONTINUE;
00080 
00081     // common HTTP response codes
00082     static const unsigned int   RESPONSE_CODE_OK;
00083     static const unsigned int   RESPONSE_CODE_CREATED;
00084     static const unsigned int   RESPONSE_CODE_NO_CONTENT;
00085     static const unsigned int   RESPONSE_CODE_FOUND;
00086     static const unsigned int   RESPONSE_CODE_UNAUTHORIZED;
00087     static const unsigned int   RESPONSE_CODE_FORBIDDEN;
00088     static const unsigned int   RESPONSE_CODE_NOT_FOUND;
00089     static const unsigned int   RESPONSE_CODE_METHOD_NOT_ALLOWED;
00090     static const unsigned int   RESPONSE_CODE_NOT_MODIFIED;
00091     static const unsigned int   RESPONSE_CODE_BAD_REQUEST;
00092     static const unsigned int   RESPONSE_CODE_SERVER_ERROR;
00093     static const unsigned int   RESPONSE_CODE_NOT_IMPLEMENTED;
00094     static const unsigned int   RESPONSE_CODE_CONTINUE;
00095     
00097     typedef StringDictionary    Headers;
00098 
00100     typedef StringDictionary    CookieParams;
00101 
00103     typedef StringDictionary    QueryParams;
00104 
00105     
00112     static bool base64_decode(std::string const &input, std::string & output);
00113 
00120     static bool base64_encode(std::string const &input, std::string & output);
00121 
00123     static std::string url_decode(const std::string& str);
00124 
00126     static std::string url_encode(const std::string& str);
00127     
00129     static std::string get_date_string(const time_t t);
00130 
00132     static std::string make_query_string(const QueryParams& query_params);
00133     
00145     static std::string make_set_cookie_header(const std::string& name,
00146                                               const std::string& value,
00147                                               const std::string& path,
00148                                               const bool has_max_age = false,
00149                                               const unsigned long max_age = 0);     
00150 };
00151 
00152 }   // end namespace net
00153 }   // end namespace pion
00154 
00155 #endif

Generated on Fri Apr 30 14:48:53 2010 for pion-net by  doxygen 1.4.7