new_http_request

NAME
SYNOPSIS
DESCRIPTION
AUTHOR
LICENSE
VERSION
SEE ALSO

NAME

new_http_request, http_request_time, http_request_url, http_request_path, http_request_query_string, http_request_method, http_request_method_string, http_request_is_HEAD, http_request_version, http_request_nr_headers, http_request_get_headers, http_request_get_header - functions for parsing HTTP requests

SYNOPSIS

#include <pthr_http.h>

http_request new_http_request (pseudothread, io_handle);
time_t http_request_time (http_request);
const char *http_request_url (http_request);
const char *http_request_path (http_request);
const char *http_request_query_string (http_request);
int http_request_method (http_request);
const char *http_request_method_string (http_request);
int http_request_is_HEAD (http_request);
void http_request_version (http_request, int *major, int *minor);
int http_request_nr_headers (http_request);
vector http_request_get_headers (http_request);
const char *http_request_get_header (http_request h, const char *key);

DESCRIPTION

These functions allow you to efficiently parse incoming HTTP requests from conforming HTTP/0.9, HTTP/1.0 and HTTP/1.1 clients. The request parser understands GET, HEAD and POST requests and conforms as far as possible to RFC 2616.
new_http_request creates a new request object, parsing the incoming request on the given io_handle. If the stream closes at the beginning of the request the function returns NULL. If the request is faulty, then the library prints a message to syslog and throws an exception by calling pth_die(3). Otherwise it initializes a complete http_request object and returns it.
http_request_time returns the timestamp of the incoming request.
http_request_url returns the complete URL of the request. http_request_path returns just the path component of the URL (ie. without the query string if there was one). http_request_query_string returns just the query string (for GET requests only). Do not do your own parsing of query strings: there is a CGI library built into pthrlib (see: new_cgi(3)).
http_request_method returns the method, one of HTTP_METHOD_GET, HTTP_METHOD_HEAD or HTTP_METHOD_POST. http_request_is_HEAD is just a quick way of testing if the method is a HEAD request. http_request_method_string returns the method as a string rather than a coded number.
http_request_version returns the major and minor numbers of the HTTP request (eg. major = 1, minor = 0 for a HTTP/1.0 request).
http_request_nr_headers, http_request_get_headers and http_request_get_header return the number of HTTP headers, the list of HTTP headers and a particular HTTP header (if it exists). http_request_get_headers returns a vector or struct http_header. This structure contains at least two fields called key and value. HTTP header keys are case insensitive when searching, and you will find that the list of keys returned by http_request_get_headers has been converted to lowercase.

AUTHOR

Richard Jones <rich@annexia.org>

LICENSE

GNU LGPL (see http://www.gnu.org/)

VERSION

pthrlib-3.0.3

SEE ALSO

new_http_response(3), new_cgi(3), new_pseudothread(3), io_fdopen(3), RFC 2616.