pion-net  4.0.9
net/include/pion/net/HTTPTypes.hpp
00001 // ------------------------------------------------------------------
00002 // pion-net: a C++ framework for building lightweight HTTP interfaces
00003 // ------------------------------------------------------------------
00004 // Copyright (C) 2007-2011 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     static const std::string    HEADER_CLIENT_IP;
00053 
00054     // common HTTP content types
00055     static const std::string    CONTENT_TYPE_HTML;
00056     static const std::string    CONTENT_TYPE_TEXT;
00057     static const std::string    CONTENT_TYPE_XML;
00058     static const std::string    CONTENT_TYPE_URLENCODED;
00059     
00060     // common HTTP request methods
00061     static const std::string    REQUEST_METHOD_HEAD;
00062     static const std::string    REQUEST_METHOD_GET;
00063     static const std::string    REQUEST_METHOD_PUT;
00064     static const std::string    REQUEST_METHOD_POST;
00065     static const std::string    REQUEST_METHOD_DELETE;
00066     
00067     // common HTTP response messages
00068     static const std::string    RESPONSE_MESSAGE_OK;
00069     static const std::string    RESPONSE_MESSAGE_CREATED;
00070     static const std::string    RESPONSE_MESSAGE_ACCEPTED;
00071     static const std::string    RESPONSE_MESSAGE_NO_CONTENT;
00072     static const std::string    RESPONSE_MESSAGE_FOUND;
00073     static const std::string    RESPONSE_MESSAGE_UNAUTHORIZED;
00074     static const std::string    RESPONSE_MESSAGE_FORBIDDEN;
00075     static const std::string    RESPONSE_MESSAGE_NOT_FOUND;
00076     static const std::string    RESPONSE_MESSAGE_METHOD_NOT_ALLOWED;
00077     static const std::string    RESPONSE_MESSAGE_NOT_MODIFIED;
00078     static const std::string    RESPONSE_MESSAGE_BAD_REQUEST;
00079     static const std::string    RESPONSE_MESSAGE_SERVER_ERROR;
00080     static const std::string    RESPONSE_MESSAGE_NOT_IMPLEMENTED;
00081     static const std::string    RESPONSE_MESSAGE_CONTINUE;
00082 
00083     // common HTTP response codes
00084     static const unsigned int   RESPONSE_CODE_OK;
00085     static const unsigned int   RESPONSE_CODE_CREATED;
00086     static const unsigned int   RESPONSE_CODE_ACCEPTED;
00087     static const unsigned int   RESPONSE_CODE_NO_CONTENT;
00088     static const unsigned int   RESPONSE_CODE_FOUND;
00089     static const unsigned int   RESPONSE_CODE_UNAUTHORIZED;
00090     static const unsigned int   RESPONSE_CODE_FORBIDDEN;
00091     static const unsigned int   RESPONSE_CODE_NOT_FOUND;
00092     static const unsigned int   RESPONSE_CODE_METHOD_NOT_ALLOWED;
00093     static const unsigned int   RESPONSE_CODE_NOT_MODIFIED;
00094     static const unsigned int   RESPONSE_CODE_BAD_REQUEST;
00095     static const unsigned int   RESPONSE_CODE_SERVER_ERROR;
00096     static const unsigned int   RESPONSE_CODE_NOT_IMPLEMENTED;
00097     static const unsigned int   RESPONSE_CODE_CONTINUE;
00098     
00100     typedef StringDictionary    Headers;
00101 
00103     typedef StringDictionary    CookieParams;
00104 
00106     typedef StringDictionary    QueryParams;
00107 
00108     
00110     static std::string get_date_string(const time_t t);
00111 
00113     static std::string make_query_string(const QueryParams& query_params);
00114     
00126     static std::string make_set_cookie_header(const std::string& name,
00127                                               const std::string& value,
00128                                               const std::string& path,
00129                                               const bool has_max_age = false,
00130                                               const unsigned long max_age = 0);     
00131 };
00132 
00133 }   // end namespace net
00134 }   // end namespace pion
00135 
00136 #endif