#include <llurlrequest.h>
Public Types | |
enum | ERequestAction { INVALID, HTTP_HEAD, HTTP_GET, HTTP_PUT, HTTP_POST, HTTP_DELETE, HTTP_MOVE, REQUEST_ACTION_COUNT } |
This enumeration is for specifying the type of request. More... | |
Public Member Functions | |
LLURLRequest (ERequestAction action) | |
Constructor. | |
LLURLRequest (ERequestAction action, const std::string &url) | |
Constructor. | |
virtual | ~LLURLRequest () |
Destructor. | |
void | useProxy (bool use_proxy) |
void | useProxy (const std::string &proxy) |
virtual EStatus | handleError (EStatus status, LLPumpIO *pump) |
Give this pipe a chance to handle a generated error. | |
void | setURL (const std::string &url) |
Set the url for the request. | |
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. | |
Protected Types | |
enum | EState { STATE_INITIALIZED, STATE_WAITING_FOR_RESPONSE, STATE_PROCESSING_RESPONSE, STATE_HAVE_RESPONSE } |
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. | |
Protected Attributes | |
EState | mState |
ERequestAction | mAction |
LLURLRequestDetail * | mDetail |
LLIOPipe::ptr_t | mCompletionCallback |
Private Member Functions | |
LOG_CLASS (LLURLRequest) | |
void | initialize () |
Initialize the object. Called during construction. | |
bool | configure () |
Handle action specific url request configuration. | |
LLURLRequest (const LLURLRequest &) | |
Declaration of unimplemented method to prevent copy construction. | |
Static Private Member Functions | |
static size_t | downCallback (char *data, size_t size, size_t nmemb, void *user) |
Download callback method. | |
static size_t | upCallback (char *data, size_t size, size_t nmemb, void *user) |
Upload callback method. |
Definition at line 64 of file llurlrequest.h.
This enumeration is for specifying the type of request.
INVALID | |
HTTP_HEAD | |
HTTP_GET | |
HTTP_PUT | |
HTTP_POST | |
HTTP_DELETE | |
HTTP_MOVE | |
REQUEST_ACTION_COUNT |
Definition at line 71 of file llurlrequest.h.
enum LLURLRequest::EState [protected] |
STATE_INITIALIZED | |
STATE_WAITING_FOR_RESPONSE | |
STATE_PROCESSING_RESPONSE | |
STATE_HAVE_RESPONSE |
Definition at line 194 of file llurlrequest.h.
LLURLRequest::LLURLRequest | ( | LLURLRequest::ERequestAction | action | ) |
Constructor.
action | One of the ERequestAction enumerations. |
Definition at line 99 of file llurlrequest.cpp.
References initialize(), and LLMemType::MTYPE_IO_URL_REQUEST.
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. |
Definition at line 106 of file llurlrequest.cpp.
References initialize(), LLMemType::MTYPE_IO_URL_REQUEST, and setURL().
LLURLRequest::~LLURLRequest | ( | ) | [virtual] |
Destructor.
Definition at line 116 of file llurlrequest.cpp.
References mDetail, and LLMemType::MTYPE_IO_URL_REQUEST.
LLURLRequest::LLURLRequest | ( | const LLURLRequest & | ) | [private] |
Declaration of unimplemented method to prevent copy construction.
LLURLRequest::LOG_CLASS | ( | LLURLRequest | ) | [private] |
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.
Definition at line 122 of file llurlrequest.cpp.
References mDetail, LLMemType::MTYPE_IO_URL_REQUEST, and LLURLRequestDetail::mURL.
Referenced by LLXMLSDRPCClientFactory< Client >::build(), LLSDRPCClientFactory< Client >::build(), LLURLRequest(), and LLContextURLExtractor::process_impl().
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.
Definition at line 128 of file llurlrequest.cpp.
References LLURLRequestDetail::mCurlRequest, mDetail, LLMemType::MTYPE_IO_URL_REQUEST, and LLCurlEasyRequest::slist_append().
Referenced by LLXMLSDRPCClientFactory< Client >::build(), LLSDRPCClientFactory< Client >::build(), configure(), and request().
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.
Definition at line 140 of file llurlrequest.cpp.
References FALSE, LLURLRequestDetail::mCurlRequest, mDetail, LLCurlEasyRequest::setopt(), LLCurlEasyRequest::setoptString(), and TRUE.
Referenced by request().
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();
Definition at line 134 of file llurlrequest.cpp.
References LLURLRequestDetail::mBodyLimit, mDetail, and LLURLRequestDetail::mIsBodyLimitSet.
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.
Definition at line 146 of file llurlrequest.cpp.
References headerCallback(), mCompletionCallback, LLURLRequestDetail::mCurlRequest, mDetail, LLMemType::MTYPE_IO_URL_REQUEST, and LLCurlEasyRequest::setHeaderCallback().
Referenced by request().
void LLURLRequest::useProxy | ( | bool | use_proxy | ) |
@ brief Turn off (or on) the CURLOPT_PROXY header.
Definition at line 160 of file llurlrequest.cpp.
References FALSE, lldebugs, llendl, LLURLRequestDetail::mCurlRequest, mDetail, NULL, LLCurlEasyRequest::setoptString(), and indra::ipc::saranwrap::status().
Referenced by request().
void LLURLRequest::useProxy | ( | const std::string & | proxy | ) |
@ brief Set the CURLOPT_PROXY header to the given value.
Definition at line 194 of file llurlrequest.cpp.
References LLURLRequestDetail::mCurlRequest, mDetail, and LLCurlEasyRequest::setoptString().
LLIOPipe::EStatus LLURLRequest::handleError | ( | LLIOPipe::EStatus | status, | |
LLPumpIO * | pump | |||
) | [virtual] |
Give this pipe a chance to handle a generated error.
Reimplemented from LLIOPipe.
Definition at line 200 of file llurlrequest.cpp.
References HTTP_STATUS_PIPE_ERROR, LLURLRequestComplete::httpStatus(), LLIOPipe::lookupStatusString(), mCompletionCallback, LLMemType::MTYPE_IO_URL_REQUEST, NULL, LLPumpIO::respond(), and LLURLRequestComplete::responseStatus().
LLIOPipe::EStatus LLURLRequest::process_impl | ( | const LLChannelDescriptors & | channels, | |
buffer_ptr_t & | buffer, | |||
bool & | eos, | |||
LLSD & | context, | |||
LLPumpIO * | pump | |||
) | [protected, virtual] |
Process the data in buffer.
Definition at line 220 of file llurlrequest.cpp.
References configure(), LLCurlEasyRequest::getResult(), HTTP_POST, HTTP_PUT, llendl, llwarns, mAction, LLBufferArray::makeChannelConsumer(), LLPumpIO::LLLinkInfo::mChannels, LLURLRequestDetail::mChannels, mCompletionCallback, LLURLRequestDetail::mCurlRequest, mDetail, LLPumpIO::LLLinkInfo::mPipe, LLURLRequestDetail::mResponseBuffer, mState, LLMemType::MTYPE_IO_URL_REQUEST, LLURLRequestDetail::mURL, NULL, LLCurlEasyRequest::perform(), PUMP_DEBUG, LLPumpIO::respond(), LLURLRequestComplete::responseStatus(), STATE_HAVE_RESPONSE, STATE_INITIALIZED, STATE_PROCESSING_RESPONSE, STATE_WAITING_FOR_RESPONSE, indra::ipc::saranwrap::status(), LLIOPipe::STATUS_BREAK, LLIOPipe::STATUS_DONE, LLIOPipe::STATUS_ERROR, LLIOPipe::STATUS_NO_CONNECTION, LLIOPipe::STATUS_OK, LLIOPipe::STATUS_STOP, and LLCurl::strerror().
void LLURLRequest::initialize | ( | ) | [private] |
Initialize the object. Called during construction.
Definition at line 327 of file llurlrequest.cpp.
References downCallback(), LLURLRequestDetail::mCurlRequest, mDetail, mState, LLMemType::MTYPE_IO_URL_REQUEST, LLCurlEasyRequest::setopt(), LLCurlEasyRequest::setReadCallback(), LLCurlEasyRequest::setWriteCallback(), STATE_INITIALIZED, and upCallback().
Referenced by LLURLRequest().
bool LLURLRequest::configure | ( | ) | [private] |
Handle action specific url request configuration.
Definition at line 337 of file llurlrequest.cpp.
References addHeader(), LLBufferArray::countAfter(), HTTP_DELETE, HTTP_GET, HTTP_HEAD, HTTP_MOVE, HTTP_POST, HTTP_PUT, LLChannelDescriptors::in(), llendl, llwarns, mAction, LLURLRequestDetail::mChannels, LLURLRequestDetail::mCurlRequest, mDetail, LLURLRequestDetail::mResponseBuffer, LLMemType::MTYPE_IO_URL_REQUEST, LLURLRequestDetail::mURL, NULL, S32, LLCurlEasyRequest::sendRequest(), LLCurlEasyRequest::setopt(), LLCurlEasyRequest::setoptString(), and LLCurlEasyRequest::setPost().
Referenced by process_impl().
size_t LLURLRequest::downCallback | ( | char * | data, | |
size_t | size, | |||
size_t | nmemb, | |||
void * | user | |||
) | [static, private] |
Download callback method.
Definition at line 407 of file llurlrequest.cpp.
References LLBufferArray::append(), LLURLRequestDetail::mBodyLimit, LLURLRequestDetail::mChannels, mDetail, LLURLRequestDetail::mIsBodyLimitSet, LLURLRequestDetail::mResponseBuffer, mState, LLMemType::MTYPE_IO_URL_REQUEST, LLChannelDescriptors::out(), STATE_PROCESSING_RESPONSE, and STATE_WAITING_FOR_RESPONSE.
Referenced by initialize().
size_t LLURLRequest::upCallback | ( | char * | data, | |
size_t | size, | |||
size_t | nmemb, | |||
void * | user | |||
) | [static, private] |
Upload callback method.
Definition at line 441 of file llurlrequest.cpp.
References LLBufferArray::countAfter(), LLChannelDescriptors::in(), llmin(), LLURLRequestDetail::mChannels, mDetail, LLURLRequestDetail::mLastRead, LLURLRequestDetail::mResponseBuffer, LLMemType::MTYPE_IO_URL_REQUEST, LLBufferArray::readAfter(), and S32.
Referenced by initialize().
EState LLURLRequest::mState [protected] |
Definition at line 201 of file llurlrequest.h.
Referenced by downCallback(), initialize(), and process_impl().
ERequestAction LLURLRequest::mAction [protected] |
LLURLRequestDetail* LLURLRequest::mDetail [protected] |
Definition at line 203 of file llurlrequest.h.
Referenced by addHeader(), checkRootCertificate(), configure(), downCallback(), initialize(), process_impl(), setBodyLimit(), setCallback(), setURL(), upCallback(), useProxy(), and ~LLURLRequest().
LLIOPipe::ptr_t LLURLRequest::mCompletionCallback [protected] |
Definition at line 204 of file llurlrequest.h.
Referenced by handleError(), process_impl(), and setCallback().