Home --> Documentations --> PJLIB-UTIL Reference

pj_http_req_callback Struct Reference

Data Fields

void(* on_response )(pj_http_req *http_req, const pj_http_resp *resp)
void(* on_send_data )(pj_http_req *http_req, void **data, pj_size_t *size)
void(* on_data_read )(pj_http_req *http_req, void *data, pj_size_t size)
void(* on_complete )(pj_http_req *http_req, pj_status_t status, const pj_http_resp *resp)

Detailed Description

This structure describes the callbacks to be called by the HTTP request.

Field Documentation

◆ on_complete

void(* pj_http_req_callback::on_complete) (pj_http_req *http_req, pj_status_t status, const pj_http_resp *resp)

This callback is called when the HTTP request is completed. If the callback on_data_read() is specified, the variable response->data will be set to NULL, otherwise it will contain the complete data. Response data is allocated from pj_http_req's internal memory pool so the data remain valid as long as pj_http_req is not destroyed and application does not start a new request.

If no longer required, application may choose to destroy pj_http_req immediately by calling pj_http_req_destroy() inside the callback.

http_reqThe http request.
statusThe status of the request operation. PJ_SUCCESS if the operation completed successfully (connection-wise). To check the server's status-code response to the HTTP request, application should check resp->status_code instead.
respThe response of the corresponding request. If the status argument is non-PJ_SUCCESS, this argument will be set to NULL.

◆ on_data_read

void(* pj_http_req_callback::on_data_read) (pj_http_req *http_req, void *data, pj_size_t size)

This callback is called when a segment of response body data arrives. If this callback is specified (i.e. not NULL), the on_complete() callback will be called with zero-length data (within the response parameter), hence the application must store and manage its own data buffer, otherwise the on_complete() callback will be called with the response parameter containing the complete data.

http_reqThe http request.
dataThe buffer containing the data.
sizeThe length of data in the buffer.

◆ on_response

void(* pj_http_req_callback::on_response) (pj_http_req *http_req, const pj_http_resp *resp)

This callback is called when a complete HTTP response header is received.

http_reqThe http request.
respThe response of the request.

◆ on_send_data

void(* pj_http_req_callback::on_send_data) (pj_http_req *http_req, void **data, pj_size_t *size)

This callback is called when the HTTP request is ready to send its request body. Application may wish to use this callback if it wishes to load the data at a later time or if it does not wish to load the whole data into memory. In order for this callback to be called, application MUST set http_req_param.total_size to a value greater than 0.

http_reqThe http request.
dataPointer to the data that will be sent. Application must set the pointer to the current data chunk/segment to be sent. Data must remain valid until the next on_send_data() callback or for the last segment, until it is sent.
sizePointer to the data size that will be sent.

The documentation for this struct was generated from the following file:


PJLIB-UTIL Open Source, small footprint, and portable asynchronous/caching DNS resolver, text scanner, STUN client, and XML library
Copyright (C) 2006-2009 Teluu Inc.