LibHTTP is often used as HTTP and HTTPS library inside a larger application. A C API is available to integrate the LibHTTP functionality in a larger codebase. A C++ wrapper is also available, although it is not guaranteed that all functionality available through the C API can also be accessed from C++. This document describes the public C API. Basic usage examples of the API can be found in Embedding/.
Macros
| Macro | Description |
|---|---|
LIBHTTP_VERSION |
The current version of the website as a string with the major and minor version number seperated with a dot. For version 1.9, this string will for example have the value "1.9" |
Structures
struct client_cert;struct httplib_callbacks;struct httplib_client_options;struct httplib_form_data_handler;struct httplib_header;struct httplib_option;struct httplib_request_info;struct httplib_server_ports;
Functions
System Functions
httplib_check_feature( feature );httplib_cry( ctx, conn, fmt, ... );httplib_get_context( conn );httplib_get_builtin_mime_type( file_name );httplib_get_option( ctx, name );httplib_get_random();httplib_get_response_code_text( conn, response_code );httplib_get_server_ports( ctx, size, ports );httplib_get_user_data( ctx );httplib_get_valid_options();httplib_start( callbacks, user_data, options );httplib_stop( ctx );httplib_version();
Communication Functions
httplib_close_connection( conn );httplib_connect_client( host, port, use_ssl, error_buffer, error_buffer_size );httplib_connect_client_secure( client_options, error_buffer, error_buffer_size );httplib_download( host, port, use_ssl, error_buffer, error_buffer_size, fmt, ... );httplib_get_cookie( cookie, var_name, buf, buf_len );httplib_get_header( conn, name );httplib_get_request_info( conn );httplib_get_response( conn, ebuf, ebuf_len, timeout );httplib_get_user_connection_data( conn );httplib_get_var( data, data_len, var_name, dst, dst_len );httplib_get_var2( data, data_len, var_name, dst, dst_len, occurrence );httplib_handle_form_request( conn, fdh );httplib_printf( conn, fmt, ... );httplib_read( conn, buf, len );httplib_send_file( conn, path, mime_type, additional_headers );httplib_set_request_handler( ctx, uri, handler, cbdata );httplib_set_user_connection_data( conn, data );httplib_store_body( conn, path );httplib_write( conn, buf, len );
Websocket Functions
httplib_connect_websocket_client( host, port, use_ssl, error_buffer, error_buffer_size, path, origin, data_func, close_func, user_data);httplib_set_websocket_handler( ctx, uri, connect_handler, ready_handler, data_handler, close_handler, cbdata );httplib_websocket_client_write( conn, opcode, data, data_len );httplib_websocket_write( conn, opcode, data, data_len );
Authentication Functions
httplib_modify_passwords_file( passwords_file_name, domain, user, password );httplib_set_auth_handler( ctx, uri, handler, cbdata );
Data Manipulation and Comparison Functions
httplib_atomic_dec( addr );httplib_atomic_inc( addr );httplib_base64_encode( src, src_len, dst, dst_len );httplib_md5( buf, ... );httplib_strcasecmp( s1, s2 );httplib_strcasestr( big_str, small_str );httplib_strdup( str );httplib_strlcpy( dst, src, len );httplib_strncasecmp( s1, s2, len );httplib_strndup( str, len );httplib_url_decode( src, src_len, dst, dst_len, is_form_url_encoded );httplib_url_encode( src, dst, dst_len );
Memory Allocation Functions
httplib_calloc( ptr, size );httplib_free( ptr );httplib_malloc( size );httplib_realloc( ptr, size );httplib_set_alloc_callback_func( log_func );
Process Functions
httplib_kill( pid, sig );httplib_lock_connection( conn );httplib_lock_context( ctx );httplib_poll( pfd, nfds, timeout );httplib_pthread_cond_broadcast( cv );httplib_pthread_cond_destroy( cv );httplib_pthread_cond_init( cv, attr );httplib_pthread_cond_signal( cv );httplib_pthread_cond_timedwait( cv, mutex, abstime );httplib_pthread_cond_wait( cv, mutex );httplib_pthread_getspecific( key );httplib_pthread_join( thread, value_ptr );httplib_pthread_key_create( key, destructor );httplib_pthread_key_delete( key );httplib_pthread_mutex_destroy( mutex );httplib_pthread_mutex_init( mutex, attr );httplib_pthread_mutex_lock( mutex );httplib_pthread_mutex_trylock( mutex );httplib_pthread_mutex_unlock( mutex );httplib_pthread_self();httplib_pthread_setspecific( key, value );httplib_start_thread( f, p );httplib_unlock_connection( conn );httplib_unlock_context( ctx );