BLOG | DOCUMENTATION | TRAC

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

pj_http_req_callback Struct Reference
[Simple HTTP Client]

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

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.

Parameters:
http_req The http request.
status The 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.
resp The response of the corresponding request. If the status argument is non-PJ_SUCCESS, this argument will be set to NULL.
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.

Parameters:
http_req The http request.
data The buffer containing the data.
size The length of data in the buffer.

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

Parameters:
http_req The http request.
resp The response of the request.
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.

Parameters:
http_req The http request.
data Pointer 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.
size Pointer 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.