libwebsockets
Lightweight C library for HTML5 websockets
lws-http.h File Reference

Go to the source code of this file.

Data Structures

struct  lws_process_html_args
 
struct  lws_process_html_state
 
struct  lws_tokens
 
struct  lws_token_limits
 

Macros

#define LWS_RECOMMENDED_MIN_HEADER_SPACE   2048
 
#define LWSAHH_CODE_MASK   ((1 << 16) - 1)
 
#define LWSAHH_FLAG_NO_SERVER_NAME   (1 << 30)
 
#define LWS_ILLEGAL_HTTP_CONTENT_LEN   ((lws_filepos_t)-1ll)
 
#define lws_http_client_http_resp_is_error(code)   (!(code < 400))
 
#define LWS_H2_STREAM_SID   -1
 

Typedefs

typedef const char *(* lws_process_html_state_cb) (void *data, int index)
 
typedef void(* lws_hdr_custom_fe_cb_t) (const char *name, int nlen, void *opaque)
 

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
}
 
enum  lws_token_indexes {
  WSI_TOKEN_GET_URI , WSI_TOKEN_POST_URI , WSI_TOKEN_HOST , WSI_TOKEN_CONNECTION ,
  WSI_TOKEN_UPGRADE , WSI_TOKEN_ORIGIN , WSI_TOKEN_CHALLENGE , WSI_TOKEN_HTTP ,
  WSI_TOKEN_HTTP_ACCEPT , WSI_TOKEN_HTTP_IF_MODIFIED_SINCE , WSI_TOKEN_HTTP_IF_NONE_MATCH , WSI_TOKEN_HTTP_ACCEPT_ENCODING ,
  WSI_TOKEN_HTTP_ACCEPT_LANGUAGE , WSI_TOKEN_HTTP_PRAGMA , WSI_TOKEN_HTTP_CACHE_CONTROL , WSI_TOKEN_HTTP_AUTHORIZATION ,
  WSI_TOKEN_HTTP_COOKIE , WSI_TOKEN_HTTP_CONTENT_LENGTH , WSI_TOKEN_HTTP_CONTENT_TYPE , WSI_TOKEN_HTTP_DATE ,
  WSI_TOKEN_HTTP_RANGE , WSI_TOKEN_HTTP_ACCEPT_RANGES , WSI_TOKEN_HTTP_AGE , WSI_TOKEN_HTTP_ALLOW ,
  WSI_TOKEN_HTTP_CONTENT_DISPOSITION , WSI_TOKEN_HTTP_CONTENT_ENCODING , WSI_TOKEN_HTTP_CONTENT_LANGUAGE , WSI_TOKEN_HTTP_CONTENT_LOCATION ,
  WSI_TOKEN_HTTP_CONTENT_RANGE , WSI_TOKEN_HTTP_ETAG , WSI_TOKEN_HTTP_EXPECT , WSI_TOKEN_HTTP_EXPIRES ,
  WSI_TOKEN_HTTP_FROM , WSI_TOKEN_HTTP_IF_MATCH , WSI_TOKEN_HTTP_IF_RANGE , WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE ,
  WSI_TOKEN_HTTP_LAST_MODIFIED , WSI_TOKEN_HTTP_LINK , WSI_TOKEN_HTTP_LOCATION , WSI_TOKEN_HTTP_REFRESH ,
  WSI_TOKEN_HTTP_RETRY_AFTER , WSI_TOKEN_HTTP_SERVER , WSI_TOKEN_HTTP_SET_COOKIE , WSI_TOKEN_HTTP_TRANSFER_ENCODING ,
  WSI_TOKEN_HTTP_URI_ARGS , WSI_TOKEN_HTTP1_0 , WSI_TOKEN_X_FORWARDED_FOR , WSI_TOKEN_CONNECT ,
  WSI_TOKEN_HEAD_URI , WSI_TOKEN_X_AUTH_TOKEN , WSI_TOKEN_DSS_SIGNATURE , _WSI_TOKEN_CLIENT_SENT_PROTOCOLS ,
  _WSI_TOKEN_CLIENT_PEER_ADDRESS , _WSI_TOKEN_CLIENT_URI , _WSI_TOKEN_CLIENT_HOST , _WSI_TOKEN_CLIENT_ORIGIN ,
  _WSI_TOKEN_CLIENT_METHOD , _WSI_TOKEN_CLIENT_IFACE , _WSI_TOKEN_CLIENT_LOCALPORT , _WSI_TOKEN_CLIENT_ALPN ,
  WSI_TOKEN_COUNT , WSI_TOKEN_NAME_PART , WSI_TOKEN_SKIPPING , WSI_TOKEN_SKIPPING_SAW_CR ,
  WSI_PARSING_COMPLETE , WSI_INIT_TOKEN_MUXURL
}
 
enum  lws_h2_settings {
  H2SET_HEADER_TABLE_SIZE = 1 , H2SET_ENABLE_PUSH , H2SET_MAX_CONCURRENT_STREAMS , H2SET_INITIAL_WINDOW_SIZE ,
  H2SET_MAX_FRAME_SIZE , H2SET_MAX_HEADER_LIST_SIZE , H2SET_RESERVED7 , H2SET_ENABLE_CONNECT_PROTOCOL ,
  H2SET_COUNT
}
 
enum  {
  LWSHUMETH_GET , LWSHUMETH_POST , LWSHUMETH_OPTIONS , LWSHUMETH_PUT ,
  LWSHUMETH_PATCH , LWSHUMETH_DELETE , LWSHUMETH_CONNECT , LWSHUMETH_HEAD ,
  LWSHUMETH_COLON_PATH
}
 

Functions

LWS_VISIBLE LWS_EXTERN const char * lws_get_mimetype (const char *file, const struct lws_http_mount *m)
 
LWS_VISIBLE LWS_EXTERN int lws_serve_http_file (struct lws *wsi, const char *file, const char *content_type, const char *other_headers, int other_headers_len)
 
LWS_VISIBLE LWS_EXTERN int lws_serve_http_file_fragment (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_chunked_html_process (struct lws_process_html_args *args, struct lws_process_html_state *s)
 
LWS_VISIBLE LWS_EXTERN const unsigned char * lws_token_to_string (enum lws_token_indexes token)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_hdr_total_length (struct lws *wsi, enum lws_token_indexes h)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_hdr_fragment_length (struct lws *wsi, enum lws_token_indexes h, int frag_idx)
 
LWS_VISIBLE LWS_EXTERN int lws_hdr_copy (struct lws *wsi, char *dest, int len, enum lws_token_indexes h)
 
LWS_VISIBLE LWS_EXTERN int lws_hdr_copy_fragment (struct lws *wsi, char *dest, int len, enum lws_token_indexes h, int frag_idx)
 
LWS_VISIBLE LWS_EXTERN int lws_hdr_custom_length (struct lws *wsi, const char *name, int nlen)
 
LWS_VISIBLE LWS_EXTERN int lws_hdr_custom_copy (struct lws *wsi, char *dst, int len, const char *name, int nlen)
 
LWS_VISIBLE LWS_EXTERN int lws_hdr_custom_name_foreach (struct lws *wsi, lws_hdr_custom_fe_cb_t cb, void *opaque)
 
LWS_VISIBLE LWS_EXTERN int lws_get_urlarg_by_name_safe (struct lws *wsi, const char *name, char *buf, int len)
 
LWS_VISIBLE LWS_EXTERN const char * lws_get_urlarg_by_name (struct lws *wsi, const char *name, char *buf, int len)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_status (struct lws *wsi, unsigned int code, unsigned char **p, unsigned char *end)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_by_name (struct lws *wsi, const unsigned char *name, const unsigned char *value, int length, unsigned char **p, unsigned char *end)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_by_token (struct lws *wsi, enum lws_token_indexes token, const unsigned char *value, int length, unsigned char **p, unsigned char *end)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_header_content_length (struct lws *wsi, lws_filepos_t content_length, unsigned char **p, unsigned char *end)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_finalize_http_header (struct lws *wsi, unsigned char **p, unsigned char *end)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_finalize_write_http_header (struct lws *wsi, unsigned char *start, unsigned char **p, unsigned char *end)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_add_http_common_headers (struct lws *wsi, unsigned int code, const char *content_type, lws_filepos_t content_len, unsigned char **p, unsigned char *end)
 
LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_http_get_uri_and_method (struct lws *wsi, char **puri_ptr, int *puri_len)
 
LWS_VISIBLE LWS_EXTERN const char * lws_urlencode (char *escaped, const char *string, int len)
 
LWS_VISIBLE LWS_EXTERN int lws_urldecode (char *string, const char *escaped, int len)
 
LWS_VISIBLE LWS_EXTERN int lws_http_date_render_from_unix (char *buf, size_t len, const time_t *t)
 
LWS_VISIBLE LWS_EXTERN int lws_http_date_parse_unix (const char *b, size_t len, time_t *t)
 
LWS_VISIBLE LWS_EXTERN int lws_http_check_retry_after (struct lws *wsi, lws_usec_t *us_interval_in_out)
 
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 LWS_EXTERN int lws_http_headers_detach (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_http_mark_sse (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_h2_client_stream_long_poll_rxonly (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_http_compression_apply (struct lws *wsi, const char *name, unsigned char **p, unsigned char *end, char decomp)
 
LWS_VISIBLE LWS_EXTERN int lws_http_is_redirected_to_get (struct lws *wsi)
 
LWS_VISIBLE LWS_EXTERN int lws_http_cookie_get (struct lws *wsi, const char *name, char *buf, size_t *max)
 
LWS_VISIBLE LWS_EXTERN int lws_h2_update_peer_txcredit (struct lws *wsi, unsigned int sid, int bump)
 
LWS_VISIBLE LWS_EXTERN int lws_h2_get_peer_txcredit_estimate (struct lws *wsi)
 

Data Structure Documentation

◆ lws_process_html_args

struct lws_process_html_args

Definition at line 132 of file lws-http.h.

+ Collaboration diagram for lws_process_html_args:
Data Fields
char * p

pointer to the buffer containing the data

int len

length of the original data at p

int max_len

maximum length we can grow the data to

int final

set if this is the last chunk of the file

int chunked

0 == unchunked, 1 == produce chunk headers (incompatible with HTTP/2)

◆ lws_process_html_state

struct lws_process_html_state

Definition at line 143 of file lws-http.h.

+ Collaboration diagram for lws_process_html_state:
Data Fields
char * start

pointer to start of match

char swallow[16]

matched character buffer

int pos

position in match

void * data

opaque pointer

const char *const * vars

list of variable names

int count_vars

count of variable names

lws_process_html_state_cb replace

called on match to perform substitution

Macro Definition Documentation

◆ LWS_RECOMMENDED_MIN_HEADER_SPACE

#define LWS_RECOMMENDED_MIN_HEADER_SPACE   2048

Definition at line 27 of file lws-http.h.

◆ lws_http_client_http_resp_is_error

#define lws_http_client_http_resp_is_error (   code)    (!(code < 400))

lws_http_client_http_error() - determine if the response code indicates an error

Parameters
codethe response code to test

Returns nonzero if the code indicates an error, else zero if reflects a non-error condition

Definition at line 982 of file lws-http.h.

◆ LWS_H2_STREAM_SID

#define LWS_H2_STREAM_SID   -1

lws_h2_update_peer_txcredit() - manually update stream peer tx credit

Parameters
wsithe h2 child stream whose peer credit to change
sidthe stream ID, or LWS_H2_STREAM_SID for the wsi stream ID
bumpsigned change to confer upon peer tx credit for sid

In conjunction with LCCSCF_H2_MANUAL_RXFLOW flag, allows the user code to selectively starve the remote peer of the ability to send us data on a client connection.

Normally lws sends an initial window size for the peer to send to it of 0, but during the header phase it sends a WINDOW_UPDATE to increase the amount available. LCCSCF_H2_MANUAL_RXFLOW restricts this initial increase in tx credit for the stream, before it has been asked to send us anything, to the amount specified in the client info .manual_initial_tx_credit member, and this api can be called to send the other side permission to send us up to bump additional bytes.

The nwsi tx credit is updated automatically for exactly what was sent to us on a stream with LCCSCF_H2_MANUAL_RXFLOW flag, but the stream's own tx credit must be handled manually by user code via this api.

Returns 0 for success or nonzero for failure.

Definition at line 1009 of file lws-http.h.

Typedef Documentation

◆ lws_process_html_state_cb

typedef const char *(* lws_process_html_state_cb) (void *data, int index)

Definition at line 141 of file lws-http.h.

Enumeration Type Documentation

◆ http_status

Enumerator
HTTP_STATUS_CONTINUE 
HTTP_STATUS_OK 
HTTP_STATUS_NO_CONTENT 
HTTP_STATUS_PARTIAL_CONTENT 
HTTP_STATUS_MOVED_PERMANENTLY 
HTTP_STATUS_FOUND 
HTTP_STATUS_SEE_OTHER 
HTTP_STATUS_NOT_MODIFIED 
HTTP_STATUS_BAD_REQUEST 
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 
HTTP_STATUS_NOT_IMPLEMENTED 
HTTP_STATUS_BAD_GATEWAY 
HTTP_STATUS_SERVICE_UNAVAILABLE 
HTTP_STATUS_GATEWAY_TIMEOUT 
HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED 

Definition at line 83 of file lws-http.h.

83 {
85
86 HTTP_STATUS_OK = 200,
89
94
113
120};
@ HTTP_STATUS_EXPECTATION_FAILED
Definition: lws-http.h:112
@ HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE
Definition: lws-http.h:110
@ HTTP_STATUS_NOT_ACCEPTABLE
Definition: lws-http.h:101
@ HTTP_STATUS_REQ_URI_TOO_LONG
Definition: lws-http.h:109
@ HTTP_STATUS_INTERNAL_SERVER_ERROR
Definition: lws-http.h:114
@ HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE
Definition: lws-http.h:111
@ HTTP_STATUS_REQUEST_TIMEOUT
Definition: lws-http.h:103
@ HTTP_STATUS_PROXY_AUTH_REQUIRED
Definition: lws-http.h:102
@ HTTP_STATUS_FORBIDDEN
Definition: lws-http.h:98
@ HTTP_STATUS_BAD_REQUEST
Definition: lws-http.h:95
@ HTTP_STATUS_FOUND
Definition: lws-http.h:91
@ HTTP_STATUS_METHOD_NOT_ALLOWED
Definition: lws-http.h:100
@ HTTP_STATUS_GONE
Definition: lws-http.h:105
@ HTTP_STATUS_NOT_MODIFIED
Definition: lws-http.h:93
@ HTTP_STATUS_CONFLICT
Definition: lws-http.h:104
@ HTTP_STATUS_MOVED_PERMANENTLY
Definition: lws-http.h:90
@ HTTP_STATUS_PARTIAL_CONTENT
Definition: lws-http.h:88
@ HTTP_STATUS_REQ_ENTITY_TOO_LARGE
Definition: lws-http.h:108
@ HTTP_STATUS_SERVICE_UNAVAILABLE
Definition: lws-http.h:117
@ HTTP_STATUS_LENGTH_REQUIRED
Definition: lws-http.h:106
@ HTTP_STATUS_PRECONDITION_FAILED
Definition: lws-http.h:107
@ HTTP_STATUS_BAD_GATEWAY
Definition: lws-http.h:116
@ HTTP_STATUS_NOT_IMPLEMENTED
Definition: lws-http.h:115
@ HTTP_STATUS_NO_CONTENT
Definition: lws-http.h:87
@ HTTP_STATUS_OK
Definition: lws-http.h:86
@ HTTP_STATUS_CONTINUE
Definition: lws-http.h:84
@ HTTP_STATUS_UNAUTHORIZED
Definition: lws-http.h:96
@ HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED
Definition: lws-http.h:119
@ HTTP_STATUS_SEE_OTHER
Definition: lws-http.h:92
@ HTTP_STATUS_GATEWAY_TIMEOUT
Definition: lws-http.h:118
@ HTTP_STATUS_NOT_FOUND
Definition: lws-http.h:99
@ HTTP_STATUS_PAYMENT_REQUIRED
Definition: lws-http.h:97

Function Documentation

◆ lws_get_mimetype()

LWS_VISIBLE LWS_EXTERN const char * lws_get_mimetype ( const char *  file,
const struct lws_http_mount m 
)

lws_get_mimetype() - Determine mimetype to use from filename

Parameters
filefilename
mNULL, or mount context

This uses a canned list of known filetypes first, if no match and m is non-NULL, then tries a list of per-mount file suffix to mimtype mappings.

Returns either NULL or a pointer to the mimetype matching the file.

◆ lws_serve_http_file()

LWS_VISIBLE LWS_EXTERN int lws_serve_http_file ( struct lws *  wsi,
const char *  file,
const char *  content_type,
const char *  other_headers,
int  other_headers_len 
)

lws_serve_http_file() - Send a file back to the client using http

Parameters
wsiWebsocket instance (available from user callback)
fileThe file to issue over http
content_typeThe http content type, eg, text/html
other_headersNULL or pointer to header string
other_headers_lenlength of the other headers if non-NULL
 This function is intended to be called from the callback in response
 to http requests from the client.  It allows the callback to issue
 local files down the http link in a single step.

 Returning <0 indicates error and the wsi should be closed.  Returning
 >0 indicates the file was completely sent and
 lws_http_transaction_completed() called on the wsi (and close if != 0)
 ==0 indicates the file transfer is started and needs more service later,
 the wsi should be left alone.

◆ lws_serve_http_file_fragment()

LWS_VISIBLE LWS_EXTERN int lws_serve_http_file_fragment ( struct lws *  wsi)

◆ lws_chunked_html_process()

LWS_VISIBLE LWS_EXTERN int lws_chunked_html_process ( struct lws_process_html_args args,
struct lws_process_html_state s 
)

lws_chunked_html_process() - generic chunked substitution

Parameters
argsbuffer to process using chunked encoding
scurrent processing state

◆ lws_urlencode()

LWS_VISIBLE LWS_EXTERN const char * lws_urlencode ( char *  escaped,
const char *  string,
int  len 
)

lws_urlencode() - like strncpy but with urlencoding

Parameters
escapedoutput buffer
stringinput buffer ('/0' terminated)
lenoutput buffer max length

Because urlencoding expands the output string, it's not possible to do it in-place, ie, with escaped == string

◆ lws_urldecode()

LWS_VISIBLE LWS_EXTERN int lws_urldecode ( char *  string,
const char *  escaped,
int  len 
)

lws_urldecode() - like strncpy but with urldecoding

Parameters
stringoutput buffer
escapedinput buffer ('\0' terminated)
lenoutput buffer max length

This is only useful for '\0' terminated strings

Since urldecoding only shrinks the output string, it is possible to do it in-place, ie, string == escaped

Returns 0 if completed OK or nonzero for urldecode violation (non-hex chars where hex required, etc)

◆ lws_http_date_render_from_unix()

LWS_VISIBLE LWS_EXTERN int lws_http_date_render_from_unix ( char *  buf,
size_t  len,
const time_t *  t 
)

lws_http_date_render_from_unix() - render unixtime as RFC7231 date string

Parameters
bufDestination string buffer
lenavilable length of dest string buffer in bytes
tpointer to the time_t to render

Returns 0 if time_t is rendered into the string buffer successfully, else nonzero.

◆ lws_http_date_parse_unix()

LWS_VISIBLE LWS_EXTERN int lws_http_date_parse_unix ( const char *  b,
size_t  len,
time_t *  t 
)

lws_http_date_parse_unix() - parse a RFC7231 date string into unixtime

Parameters
bSource string buffer
lenavilable length of source string buffer in bytes
tpointer to the destination time_t to set

Returns 0 if string buffer parsed as RFC7231 time successfully, and *t set to the parsed unixtime, else return nonzero.

◆ lws_http_check_retry_after()

LWS_VISIBLE LWS_EXTERN int lws_http_check_retry_after ( struct lws *  wsi,
lws_usec_t us_interval_in_out 
)

lws_http_check_retry_after() - increase a timeout if retry-after present

Parameters
wsihttp stream this relates to
us_interval_in_outdefault us retry interval on entry may be updated

This function may extend the incoming retry interval if the server has requested that using retry-after: header. It won't reduce the incoming retry interval, only leave it alone or increase it.

*us_interval_in_out should be set to a default retry interval on entry, if the wsi has a retry-after time or interval that resolves to an interval longer than the entry *us_interval_in_out, that will be updated to the longer interval and return 0.

If no usable retry-after or the time is now or in the past, *us_interval_in_out is left alone and the function returns nonzero.

◆ lws_return_http_status()

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

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

◆ 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 
)

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)

lws_http_transaction_completed() - wait for new http transaction or close

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

◆ lws_http_headers_detach()

LWS_VISIBLE LWS_EXTERN int lws_http_headers_detach ( struct lws *  wsi)

lws_http_headers_detach() - drop the associated headers storage and allow it to be reused by another connection

Parameters
wsihttp connection

If the wsi has an ah headers struct attached, detach it.

◆ lws_http_mark_sse()

LWS_VISIBLE LWS_EXTERN int lws_http_mark_sse ( struct lws *  wsi)

lws_http_mark_sse() - called to indicate this http stream is now doing SSE

Parameters
wsihttp connection

Cancel any timeout on the wsi, and for h2, mark the network connection as containing an immortal stream for the duration the SSE stream is open.

◆ lws_h2_client_stream_long_poll_rxonly()

LWS_VISIBLE LWS_EXTERN int lws_h2_client_stream_long_poll_rxonly ( struct lws *  wsi)

lws_h2_client_stream_long_poll_rxonly() - h2 stream to immortal read-only

Parameters
wsih2 stream client wsi

Send END_STREAM-flagged zero-length DATA frame to set client stream wsi into half-closed (local) and remote into half-closed (remote). Set the client stream wsi to be immortal (not subject to timeouts).

Used if the remote server supports immortal long poll to put the stream into a read-only state where it can wait as long as needed for rx.

Returns 0 if the process (which happens asynchronously) started or non-zero if it wasn't an h2 stream.

◆ lws_http_compression_apply()

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

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_is_redirected_to_get()

LWS_VISIBLE LWS_EXTERN int lws_http_is_redirected_to_get ( struct lws *  wsi)

lws_http_is_redirected_to_get() - true if redirected to GET

Parameters
wsithe wsi to check

Check if the wsi is currently in GET mode, after, eg, doing a POST and receiving a 303.

◆ lws_http_cookie_get()

LWS_VISIBLE LWS_EXTERN int lws_http_cookie_get ( struct lws *  wsi,
const char *  name,
char *  buf,
size_t *  max 
)

lws_http_cookie_get() - return copy of named cookie if present

Parameters
wsithe wsi to check
namename of the cookie
bufbuffer to store the cookie contents into
max_lenon entry, maximum length of buf... on exit, used len of buf

If no cookie header, or no cookie of the requested name, or the value is larger than can fit in buf, returns nonzero.

If the cookie is found, copies its value into buf with a terminating NUL, sets *max_len to the used length, and returns 0.

This handles the parsing of the possibly multi-cookie header string and terminating the requested cookie at the next ; if present.

◆ lws_h2_update_peer_txcredit()

LWS_VISIBLE LWS_EXTERN int lws_h2_update_peer_txcredit ( struct lws *  wsi,
unsigned int  sid,
int  bump 
)

◆ lws_h2_get_peer_txcredit_estimate()

LWS_VISIBLE LWS_EXTERN int lws_h2_get_peer_txcredit_estimate ( struct lws *  wsi)

lws_h2_get_peer_txcredit_estimate() - return peer tx credit estimate

Parameters
wsithe h2 child stream whose peer credit estimate to return

Returns the estimated amount of tx credit at the peer, in other words the number of bytes the peer is authorized to send to us.

It's an 'estimate' because we don't know how much is already in flight towards us and actually already used.