libwebsockets
Lightweight C library for HTML5 websockets
HTTP

Modules

 Form Parsing
 
 HTML Chunked Substitution
 
 HTTP File transfer
 
 HTTP headers: create
 
 HTTP headers: read
 
 Urlencode and Urldecode
 

Data Structures

struct  lws_process_html_args
 
struct  lws_tokens
 

Enumerations

enum  http_status {
  HTTP_STATUS_CONTINUE = 100, HTTP_STATUS_OK = 200, HTTP_STATUS_NO_CONTENT = 204, HTTP_STATUS_PARTIAL_CONTENT = 206,
  HTTP_STATUS_MOVED_PERMANENTLY = 301, HTTP_STATUS_FOUND = 302, HTTP_STATUS_SEE_OTHER = 303, HTTP_STATUS_NOT_MODIFIED = 304,
  HTTP_STATUS_BAD_REQUEST = 400, HTTP_STATUS_UNAUTHORIZED, HTTP_STATUS_PAYMENT_REQUIRED, HTTP_STATUS_FORBIDDEN,
  HTTP_STATUS_NOT_FOUND, HTTP_STATUS_METHOD_NOT_ALLOWED, HTTP_STATUS_NOT_ACCEPTABLE, HTTP_STATUS_PROXY_AUTH_REQUIRED,
  HTTP_STATUS_REQUEST_TIMEOUT, HTTP_STATUS_CONFLICT, HTTP_STATUS_GONE, HTTP_STATUS_LENGTH_REQUIRED,
  HTTP_STATUS_PRECONDITION_FAILED, HTTP_STATUS_REQ_ENTITY_TOO_LARGE, HTTP_STATUS_REQ_URI_TOO_LONG, HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
  HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE, HTTP_STATUS_EXPECTATION_FAILED, HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, HTTP_STATUS_NOT_IMPLEMENTED,
  HTTP_STATUS_BAD_GATEWAY, HTTP_STATUS_SERVICE_UNAVAILABLE, HTTP_STATUS_GATEWAY_TIMEOUT, HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED
}
 

Functions

LWS_VISIBLE LWS_EXTERN int lws_return_http_status (struct lws *wsi, unsigned int code, const char *html_body)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_http_redirect (struct lws *wsi, int code, const unsigned char *loc, int len, unsigned char **p, unsigned char *end)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_http_transaction_completed (struct lws *wsi)
 
LWS_VISIBLE int lws_http_compression_apply (struct lws *wsi, const char *name, unsigned char **p, unsigned char *end, char decomp)
 

Detailed Description

Modules related to handling HTTP

Function Documentation

◆ lws_http_compression_apply()

LWS_VISIBLE int lws_http_compression_apply ( struct lws *  wsi,
const char *  name,
unsigned char **  p,
unsigned char *  end,
char  decomp 
)

#include <include/libwebsockets/lws-http.h>

lws_http_compression_apply() - apply an http compression transform

Parameters
wsithe wsi to apply the compression transform to
nameNULL, or the name of the compression transform, eg, "deflate"
ppointer to pointer to headers buffer
endpointer to end of headers buffer
decomp0 = add compressor to wsi, 1 = add decompressor

This allows transparent compression of dynamically generated HTTP. The requested compression (eg, "deflate") is only applied if the client headers indicated it was supported (and it has support in lws), otherwise it's a NOP.

If the requested compression method is NULL, then the supported compression formats are tried, and for non-decompression (server) mode the first that's found on the client's accept-encoding header is chosen.

NOTE: the compression transform, same as h2 support, relies on the user code using LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal lws fileserving code already does this.

If the library was built without the cmake option LWS_WITH_HTTP_STREAM_COMPRESSION set, then a NOP is provided for this api, allowing user code to build either way and use compression if available.

◆ lws_http_redirect()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_http_redirect ( struct lws *  wsi,
int  code,
const unsigned char *  loc,
int  len,
unsigned char **  p,
unsigned char *  end 
)

#include <include/libwebsockets/lws-http.h>

lws_http_redirect() - write http redirect out on wsi

Parameters
wsiwebsocket connection
codeHTTP response code (eg, 301)
locwhere to redirect to
lenlength of loc
ppointer current position in buffer (updated as we write)
endpointer to end of buffer

Returns amount written, or < 0 indicating fatal write failure.

◆ lws_http_transaction_completed()

LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_http_transaction_completed ( struct lws *  wsi)

#include <include/libwebsockets/lws-http.h>

lws_http_transaction_completed() - wait for new http transaction or close

Parameters
wsiwebsocket connection
 Returns 1 if the HTTP connection must close now
 Returns 0 and resets connection to wait for new HTTP header /
   transaction if possible

◆ lws_return_http_status()

LWS_VISIBLE LWS_EXTERN int lws_return_http_status ( struct lws *  wsi,
unsigned int  code,
const char *  html_body 
)

#include <include/libwebsockets/lws-http.h>

lws_return_http_status() - Return simple http status

Parameters
wsiWebsocket instance (available from user callback)
codeStatus index, eg, 404
html_bodyUser-readable HTML description < 1KB, or NULL
 Helper to report HTTP errors back to the client cleanly and
 consistently