Spinning Topp Logo BlackTopp Studios
inc
httprequest.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _networkhttprequest_h
42 #define _networkhttprequest_h
43 
44 #include "Network/networkenumerations.h"
45 #include "Network/httpmessage.h"
46 #include "Network/uri.h"
47 
48 namespace Mezzanine
49 {
50  namespace Network
51  {
52  ///////////////////////////////////////////////////////////////////////////////
53  /// @brief A simple class to facilitate the creation of HTTP requests.
54  /// @details Some of the data that can be set is mandatory, some of it is optional. The URI, major and minor versions, as well as
55  /// the request method to be used are mandatory in all cases. If you are using HTTP 1.1 or higher, then adding a "Host" header field
56  /// is also mandatory. The host should be the domain name of the server you want to request from. Some request methods make use of
57  /// the body, most don't. If the body is used then a header field may be required, such as sending a shoutbox message with a POST
58  /// request, which may require the message be put in the request body, and a "Content-Length" header be supplied with the size of
59  /// the body. Many more nuances exist, and we can't cover all use cases. So take care when using this class.
60  ///////////////////////////////////////
62  {
63  protected:
64  /// @internal
65  /// @brief The HTTP method to use for the request.
67  /// @internal
68  /// @brief The URI of the resource to request.
70 
71  /// @copydoc HTTPMessage::ParseHTTPHeader(StringIterator&,const StringIterator)
72  Boole ParseHTTPHeader(StringIterator& CurrIt, const StringIterator EndIt);
73  public:
74  /// @brief Blank constructor.
75  HTTPRequest();
76  /// @brief String constructor.
77  /// @param ToDecompose The String to construct this request from.
78  /// @remarks For normal operation this constructor should seldom be used, since this class is intended to aid in building the string.
79  HTTPRequest(const String& ToDecompose);
80  /// @brief Descriptive constructor.
81  HTTPRequest(const String& URI, const Network::HTTPRequestMethod Method, const String& Body);
82  /// @brief Class destructor.
83  ~HTTPRequest();
84 
85  ///////////////////////////////////////////////////////////////////////////////
86  // Core Operations
87 
88  /// @copydoc HTTPMessage::Compose() const
89  String Compose() const;
90  /// @copydoc HTTPMessage::Decompose(const String&)
91  /// @warning A request can be partially decomposed when it fails and have that data saved to members of this class. For that
92  /// reason you should only utilize the data in this class if the decompose was successful, or completely re-written.
93  Boole Decompose(const String& Message);
94  /// @copydoc HTTPMessage::Decompose(StringIterator&, const StringIterator)
95  /// @warning A request can be partially decomposed when it fails and have that data saved to members of this class. For that
96  /// reason you should only utilize the data in this class if the decompose was successful, or completely re-written.
97  Boole Decompose(StringIterator& CurrIt, const StringIterator EndIt);
98 
99  ///////////////////////////////////////////////////////////////////////////////
100  // Utility
101 
102  /// @brief Converts a HTTPRequestMethod enum value to it's text representation.
103  /// @param Method The HTTPRequestMethod enum value to be converted.
104  /// @return Returns a String containing the converted enum value.
105  static String ConvertRequestMethod(const Network::HTTPRequestMethod Method);
106  /// @brief Converts a text request method to it's HTTPRequestMethod enum value.
107  /// @param Method The text representation of the request method to be converted.
108  /// @return Returns a HTTPRequestMethod enum value representing the converted String.
109  static Network::HTTPRequestMethod ConvertRequestMethod(const String& Method);
110 
111  /// @brief Sets the URI of the resource being requested.
112  /// @param URI The Uniform Resource Identifier of the resource to request.
113  void SetURI(const URI& URI);
114  /// @brief Gets the URI of the resource being requested.
115  /// @return Returns a String containing the Uniform Resource Identifier of the resource being requested.
116  const URI& GetURI() const;
117  /// @brief Sets the method to be used for the request.
118  /// @param Method The HTTP method to use for the request. Initial Value: HRM_GET.
119  void SetMethod(const Network::HTTPRequestMethod Method);
120  /// @brief Gets the method to be used for the request.
121  /// @return Returns a HTTPRequestMethod enum value of the request method to be used.
122  Network::HTTPRequestMethod GetMethod() const;
123 
124  ///////////////////////////////////////////////////////////////////////////////
125  // Recommended Header Field Convenience Methods
126 
127  /// @brief Sets the Expect Header.
128  /// @remarks An optional header that most commonly is used when the expectation is "100-continue". When that expectation is set a partial request (without a body)
129  /// can be sent to the HTTP server and will check the headers to see if anything is malformed there. If nothing is it will succeed and the client can then send
130  /// a full request with the body. Useful for requests with very large bodies.
131  /// @param Expect Used to describe to the server one or more expectations being made on it by the client.
132  void SetExpectHeader(const String& Expect);
133  /// @brief Gets the Expect Header.
134  /// @return Returns a String containing one or more expectations being made on the server by the client.
135  const String& GetExpectHeader() const;
136  /// @brief Sets the From Header.
137  /// @remarks This field is entirely optional. Some smaller web services can make use of this however.
138  /// @param From Contains an email address that uniquely identifies the sender of the request.
139  void SetFromHeader(const String& From);
140  /// @brief Gets the From Header.
141  /// @return Returns a String containing an email address that uniquely identifies the sender of the request.
142  const String& GetFromHeader() const;
143  /// @brief Sets the Host Header.
144  /// @remarks This header is required for all requests being made via HTTP 1.1 and up. It is useful for servers when resolving specific hosts behind proxies.
145  /// @param Host The URI-Authority of the host to be connected to.
146  void SetHostHeader(const String& Host);
147  /// @brief Gets the Host Header.
148  /// @return Returns a String containing the URI-Authority of the host to be connected to, or blank if the field is not set.
149  const String& GetHostHeader() const;
150  /// @brief Sets the User-Agent Header.
151  /// @remarks An optional header used to provide slightly more context about what the requester is running.
152  /// @param UserAgent The name of the platform/software being used to generate this request.
153  void SetUserAgentHeader(const String& UserAgent);
154  /// @brief Gets the User-Agent Header.
155  /// @return Returns a String containing the name of the platform/software being used to generate this request.
156  const String& GetUserAgentHeader() const;
157  };//HTTPRequest
158  }//Network
159 }//Mezzanine
160 
161 #endif
String::const_iterator StringIterator
Convenience typedef for String iterators.
Definition: httpmessage.h:77
A base class for HTTP text parsing classes.
Definition: httpmessage.h:73
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
HTTPRequestMethod RequestMethod
The HTTP method to use for the request.
Definition: httprequest.h:66
A simple class to facilitate the creation of HTTP requests.
Definition: httprequest.h:61
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
URI RequestURI
The URI of the resource to request.
Definition: httprequest.h:69
A helper class for the reading and using of Uniform Resource Identifiers.
Definition: uri.h:59
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
HTTPRequestMethod
This enum is a listing of commonly supported HTTP request methods.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159