Class to handle url based requests. More...
#include <llurlrequest.h>
Public Types | |
enum | ERequestAction |
This enumeration is for specifying the type of request. | |
Public Member Functions | |
virtual EStatus | handleError (EStatus status, LLPumpIO *pump) |
Give this pipe a chance to handle a generated error. | |
LLURLRequest (ERequestAction action, const std::string &url) | |
Constructor. | |
LLURLRequest (ERequestAction action) | |
Constructor. | |
void | useProxy (const std::string &proxy) |
void | useProxy (bool use_proxy) |
virtual | ~LLURLRequest () |
Destructor. | |
void | addHeader (const char *header) |
Add a header to the http post. | |
void | checkRootCertificate (bool check) |
Check remote server certificate signed by a known root CA. | |
void | setBodyLimit (U32 size) |
Return at most size bytes of body. | |
void | setCallback (LLURLRequestComplete *callback) |
Set a completion callback for this URLRequest. | |
void | setURL (const std::string &url) |
Set the url for the request. | |
Protected Member Functions | |
virtual EStatus | process_impl (const LLChannelDescriptors &channels, buffer_ptr_t &buffer, bool &eos, LLSD &context, LLPumpIO *pump) |
Process the data in buffer. |
Class to handle url based requests.
Currently, this class is implemented on top of curl. From the vantage of a programmer using this class, you do not care so much, but it's useful to know since in order to accomplish 'non-blocking' behavior, we have to use a more expensive curl interface which can still block if the server enters a half-accepted state. It would be worth the time and effort to eventually port this to a raw client socket.
LLURLRequest::LLURLRequest | ( | LLURLRequest::ERequestAction | action | ) |
LLURLRequest::LLURLRequest | ( | LLURLRequest::ERequestAction | action, | |
const std::string & | url | |||
) |
Constructor.
action | One of the ERequestAction enumerations. | |
url | The url of the request. It should already be encoded. |
void LLURLRequest::addHeader | ( | const char * | header | ) |
Add a header to the http post.
The header must be correctly formatted for HTTP requests. This provides a raw interface if you know what kind of request you will be making during construction of this instance. All required headers will be automatically constructed, so this is usually useful for encoding parameters.
void LLURLRequest::checkRootCertificate | ( | bool | check | ) |
Check remote server certificate signed by a known root CA.
Set whether request will check that remote server certificates are signed by a known root CA when using HTTPS.
void LLURLRequest::setBodyLimit | ( | U32 | size | ) |
Return at most size bytes of body.
If the body had more bytes than this limit, they will not be returned and the connection closed. In this case, STATUS_STOP will be passed to responseStatus();
void LLURLRequest::setCallback | ( | LLURLRequestComplete * | callback | ) |
Set a completion callback for this URLRequest.
The callback is added to this URLRequet's pump when either the entire buffer is known or an error like timeout or connection refused has happened. In the case of a complete transfer, this object builds a response chain such that the callback and the next process consumer get to read the output.
This setup is a little fragile since the url request consumer might not just read the data - it may do a channel change, which invalidates the input to the callback, but it works well in practice.
void LLURLRequest::setURL | ( | const std::string & | url | ) |
Set the url for the request.
This method assumes the url is encoded appropriately for the request. The url must be set somehow before the first call to process(), or the url will not be set correctly.
void LLURLRequest::useProxy | ( | const std::string & | proxy | ) |
@ brief Set the CURLOPT_PROXY header to the given value.
void LLURLRequest::useProxy | ( | bool | use_proxy | ) |
@ brief Turn off (or on) the CURLOPT_PROXY header.