|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||
#include "ot/web/HttpRequest.h"
Class to represent a request to be sent to a HTTP server.
The HttpRequest class will be used by applications wishing to take advantage of the lower-level features of the HTTP protocol provided by the HttpClient class.Member functions are provided to set the HTTP method employed, the URL of the resource to be accessed, the MIME-type headers, entity details, network timeouts and the version of the HTTP protocol to use.
This class is used to capture all the details of a HTTP request but it is unable to actually perform the request. The HttpClient class should be used in conjunction with this one in order to send requests to HTTP servers.
An HTTP request may contain an entity to send to an origin server (usually via the POST or PUT methods). When the application wishes to send an entity, it does so by first making a call to setEntity() to specify how the entity should be sent.
The HttpRequest class (with support from HttpClient), provides applications with three alternative ways of sending an entity:-
| Constructor/Destructor Summary | |
HttpRequest(const URL& url)Constructs a new HttpRequest from a URL. | |
| Method Summary | |
size_t |
getConnectTimeout() constReturns the timeout value (in milliseconds) used when establishing a new TCP/IP connection for this HttpRequest. |
RefPtr< InputStream > |
getEntityInputStream() constReturns the application-supplied entity InputStream. |
size_t |
getEntityLength() constReturns the length of the entity that will be sent with this HTTP request. |
EntityType |
getEntityType() constReturns the type of entity that will be sent with this HTTP request. |
const String& |
getMethod() constReturns The HTTP method (e.g. |
RefPtr< MimeHeaderSequence > |
getMimeHeaders() constReturns the sequence of MIME-type headers associated with this HttpRequest. |
HttpProtocolVersion |
getProtocolVersion() constReturns the version of the HTTP protocol to be used when processing this request. |
const Byte* |
getRawEntityData() constReturns a pointer to an application-supplied data buffer containing the entity to be sent with this request. |
size_t |
getTimeout() constReturns the timeout value (in milliseconds) used for TCP/IP network send and receive operations for this HttpRequest. |
const URL& |
getURL() constReturns the URL of the resource that will be accessed via this HttpRequest. |
bool |
hasEntity() constTests if this HttpRequest has an entity to send along with the request. |
bool |
isIdempotent() constTests if this HttpRequest has the property of Idempotence. |
void |
setConnectTimeout(size_t timeoutMS)Sets the timeout value (in milliseconds) used when establishing a new TCP/IP connection for this HttpRequest. |
void |
setEntity(EntityType type, size_t length, const Byte* pRawData, InputStream* pInoutStream, const String& mimeType)Specifies details of the entity to be transmitted along with this HTTP request. |
void |
setMethod(const String& method)Sets the HTTP method to be used when sending this HttpRequest to a server. |
void |
setProtocolVersion(HttpProtocolVersion version)Sets the version of the HTTP protocol to be used when processing this request. |
void |
setTimeout(size_t timeoutMS)Sets the timeout value (in milliseconds) used for TCP/IP network send and receive operations for this HttpRequest. |
void |
setURL(const URL& url)Sets the URL of the resource that will be accessed via this HttpRequest. |
| Enumerations |
enum EntityType { |
NoEntity, |
|
|
RawEntity, |
|
|
OutputStreamEntity, |
|
|
InputStreamEntity} |
|
| Constructor/Destructor Detail |
HttpRequest(const URL& url)
| Method Detail |
size_t getConnectTimeout() const
RefPtr< InputStream > getEntityInputStream() const
size_t getEntityLength() const
EntityType getEntityType() const
const String& getMethod() const
RefPtr< MimeHeaderSequence > getMimeHeaders() const
A non-const RefPtr is returned which can be used to manipulate the header sequence, either adding or removing headers as appropriate. When this request is sent to a server, the MIME header sequence is sent immediately after the request line. In some cases, the HTTP protocol demands certain headers are present with a particular value (e.g. the Host header). In these cases, the header values set by the application may be overridden.
HttpProtocolVersion getProtocolVersion() const
const Byte* getRawEntityData() const
size_t getTimeout() const
const URL& getURL() const
bool hasEntity() const
bool isIdempotent() const
The methods GET, HEAD, PUT, OPTIONS, TRACE and DELETE all share this property.
void setConnectTimeout(size_t timeoutMS)
void setEntity(EntityType type,
size_t length,
const Byte* pRawData,
InputStream* pInoutStream,
const String& mimeType)
When very large entities are going to be sent, it is more memory-efficient to use the streamed entity types as these do not require additional buffering. However, the RawEntity type is often more appropriate when the entity is small as this often involves a little less work for the application programmer.
If a length is specified, OpenTop will use this value to generate a Content-Length header field. Where no length is provided, the protocol version of this request must be set to HTTP/1.1 or above in order to allow the use of the chunked transfer encoding. It it worth noting that many HTTP/1.1 servers do not accept chunked entities because security flaws have been discovered in both the Apache and IIS implementations.
The mimeType argument describes the MIME type of the entity and is used to generate a Content-Type header field unless the application has already provided one. When mimeType is an empty string, a MIME type of application/x-www-form-urlencoded is assumed as this is often specified when sending FORM data to a HTTP server. Further information about MIME types and form processing is described in the documentation for the OpenTop FormEmulator interface.
For convenience, the method field of this HttpRequest is changed from the default value of 'GET' to 'POST' if an entity type other than NoEntity is specified.
See the class description (above) for general information about sending entities.
type - length - pRawData - pInputStream - mimeType - IllegalArgumentException - void setMethod(const String& method)
void setProtocolVersion(HttpProtocolVersion version)
void setTimeout(size_t timeoutMS)
void setURL(const URL& url)
url -
|
OpenTop 1.5 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||||
| SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD | |||||||