//////////////////////////////////////////////////////////////////////////////// /// @brief plain http request /// /// @file /// /// DISCLAIMER /// /// Copyright 2004-2012 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is triAGENS GmbH, Cologne, Germany /// /// @author Dr. Frank Celler /// @author Achim Brandt /// @author Copyright 2004-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #ifndef TRIAGENS_REST_HTTP_REQUEST_PLAIN_H #define TRIAGENS_REST_HTTP_REQUEST_PLAIN_H 1 #include "Basics/Common.h" #include "Basics/Dictionary.h" #include "BasicsC/strings.h" #include "Rest/ConnectionInfo.h" // ----------------------------------------------------------------------------- // --SECTION-- forward declarations // ----------------------------------------------------------------------------- namespace triagens { namespace basics { class StringBuffer; } namespace rest { // ----------------------------------------------------------------------------- // --SECTION-- class ArangoServer // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /// @brief http request /// /// The http server reads the request string from the client and converts it /// into an instance of this class. An http request object provides methods to /// inspect the header and parameter fields. //////////////////////////////////////////////////////////////////////////////// class HttpRequest { private: HttpRequest (HttpRequest const&); HttpRequest& operator= (HttpRequest const&); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public types // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief http request type //////////////////////////////////////////////////////////////////////////////// enum HttpRequestType { HTTP_REQUEST_DELETE, HTTP_REQUEST_GET, HTTP_REQUEST_HEAD, HTTP_REQUEST_POST, HTTP_REQUEST_PUT, HTTP_REQUEST_ILLEGAL }; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- constructors and destructors // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief http request constructor /// /// Constructs a http request given the header string. A client request /// consists of two parts: the header and the body. For a GET request the /// body is always empty and all information about the request is delivered /// in the header. For a POST or PUT request some information is also /// delivered in the body. However, it is necessary to parse the header /// information, before the body can be read. //////////////////////////////////////////////////////////////////////////////// explicit HttpRequest (string const& header); //////////////////////////////////////////////////////////////////////////////// /// @brief http request constructor /// /// Constructs a http request given the header string. A client request /// consists of two parts: the header and the body. For a GET request the /// body is always empty and all information about the request is delivered /// in the header. For a POST or PUT request some information is also /// delivered in the body. However, it is necessary to parse the header /// information, before the body can be read. //////////////////////////////////////////////////////////////////////////////// HttpRequest (char const* header, size_t length); //////////////////////////////////////////////////////////////////////////////// /// @brief http request constructor /// /// Constructs a http request given nothing. You can add the values, /// the header information, and the path later. //////////////////////////////////////////////////////////////////////////////// HttpRequest (); //////////////////////////////////////////////////////////////////////////////// /// @brief destructor //////////////////////////////////////////////////////////////////////////////// virtual ~HttpRequest (); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief returns the http request type //////////////////////////////////////////////////////////////////////////////// HttpRequestType requestType () const; //////////////////////////////////////////////////////////////////////////////// /// @brief sets the http request type //////////////////////////////////////////////////////////////////////////////// void setRequestType (HttpRequestType newType); //////////////////////////////////////////////////////////////////////////////// /// @brief returns the path of the request /// /// The path consists of the URL without the host and without any parameters. //////////////////////////////////////////////////////////////////////////////// char const* requestPath () const; //////////////////////////////////////////////////////////////////////////////// /// @brief sets the path of the request //////////////////////////////////////////////////////////////////////////////// void setRequestPath (char const* path); //////////////////////////////////////////////////////////////////////////////// /// @brief returns the content length //////////////////////////////////////////////////////////////////////////////// size_t contentLength () const; //////////////////////////////////////////////////////////////////////////////// /// @brief returns the server IP //////////////////////////////////////////////////////////////////////////////// ConnectionInfo const& connectionInfo () const; //////////////////////////////////////////////////////////////////////////////// /// @brief sets the server IP //////////////////////////////////////////////////////////////////////////////// void setConnectionInfo (ConnectionInfo const& info); //////////////////////////////////////////////////////////////////////////////// /// @brief writes representation to string buffer //////////////////////////////////////////////////////////////////////////////// void write (basics::StringBuffer*) const; //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public header methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief returns a header field /// /// Returns the value of a header field with given name. If no header field /// with the given name was specified by the client, the empty string is /// returned. //////////////////////////////////////////////////////////////////////////////// char const* header (char const* field) const; //////////////////////////////////////////////////////////////////////////////// /// @brief returns a header field /// /// Returns the value of a header field with given name. If no header field /// with the given name was specified by the client, the empty string is /// returned. found is try if the client specified the header field. //////////////////////////////////////////////////////////////////////////////// char const* header (char const* field, bool& found) const; //////////////////////////////////////////////////////////////////////////////// /// @brief returns all header fields /// /// Returns all header fields //////////////////////////////////////////////////////////////////////////////// map headers () const; //////////////////////////////////////////////////////////////////////////////// /// @brief set a header field /// /// Set the value of a header field with given name. //////////////////////////////////////////////////////////////////////////////// void setHeader (string const& field, string const& value); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public suffix methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief returns all suffix parts //////////////////////////////////////////////////////////////////////////////// vector const& suffix () const; //////////////////////////////////////////////////////////////////////////////// /// @brief adds a suffix part //////////////////////////////////////////////////////////////////////////////// void addSuffix (string const& part); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public value methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief returns the value of a key /// /// Returns the value of a key. The empty string is returned if key was not /// specified by the client. //////////////////////////////////////////////////////////////////////////////// char const* value (string const& key) const; //////////////////////////////////////////////////////////////////////////////// /// @brief returns the value of a key /// /// Returns the value of a key. The empty string is returned if key was not /// specified by the client. found is true if the client specified the key. //////////////////////////////////////////////////////////////////////////////// char const* value (string const& key, bool& found) const; //////////////////////////////////////////////////////////////////////////////// /// @brief returns all values /// /// Returns all key/value pairs of the request. //////////////////////////////////////////////////////////////////////////////// map values () const; //////////////////////////////////////////////////////////////////////////////// /// @brief sets the key/values from an url encoded string //////////////////////////////////////////////////////////////////////////////// void setValues (string const& params); //////////////////////////////////////////////////////////////////////////////// /// @brief sets a key/value pair //////////////////////////////////////////////////////////////////////////////// void setValue (string const& key, string const& value); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- public body methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// public: //////////////////////////////////////////////////////////////////////////////// /// @brief gets the body //////////////////////////////////////////////////////////////////////////////// char const* body () const; //////////////////////////////////////////////////////////////////////////////// /// @brief gets the body size //////////////////////////////////////////////////////////////////////////////// size_t bodySize () const; //////////////////////////////////////////////////////////////////////////////// /// @brief sets the body //////////////////////////////////////////////////////////////////////////////// void setBody (char const* newBody); //////////////////////////////////////////////////////////////////////////////// /// @brief sets the body //////////////////////////////////////////////////////////////////////////////// void setBody (char const* newBody, size_t length); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- private methods // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// private: //////////////////////////////////////////////////////////////////////////////// /// @brief parses the http header //////////////////////////////////////////////////////////////////////////////// void parseHeader (char* ptr, size_t length); //////////////////////////////////////////////////////////////////////////////// /// @brief sets the header values //////////////////////////////////////////////////////////////////////////////// void setValues (char* begin, char* end); //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// // ----------------------------------------------------------------------------- // --SECTION-- private variables // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Rest /// @{ //////////////////////////////////////////////////////////////////////////////// private: HttpRequestType _type; string _requestPath; vector _suffix; basics::Dictionary _headers; basics::Dictionary _values; char* _body; size_t _bodySize; ConnectionInfo _connectionInfo; vector _freeables; }; } } //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// #endif // ----------------------------------------------------------------------------- // --SECTION-- END-OF-FILE // ----------------------------------------------------------------------------- // Local Variables: // mode: outline-minor // outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}\\)" // End: