2019-08-14 10:44:14 +01:00
|
|
|
/*
|
2018-04-19 12:53:53 +08:00
|
|
|
* libwebsockets - small server side websockets and web server implementation
|
|
|
|
*
|
2019-08-14 10:44:14 +01:00
|
|
|
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
|
2018-04-19 12:53:53 +08:00
|
|
|
*
|
2019-08-14 10:44:14 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2018-04-19 12:53:53 +08:00
|
|
|
*
|
2019-08-14 10:44:14 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2018-04-19 12:53:53 +08:00
|
|
|
*
|
2019-08-14 10:44:14 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
2018-04-19 12:53:53 +08:00
|
|
|
*
|
2019-08-15 10:49:52 +01:00
|
|
|
* This is included from private-lib-core.h if either H1 or H2 roles are
|
2018-04-19 12:53:53 +08:00
|
|
|
* enabled
|
|
|
|
*/
|
|
|
|
|
2018-09-04 08:06:46 +08:00
|
|
|
#if defined(LWS_WITH_HUBBUB)
|
2018-04-27 14:36:10 +08:00
|
|
|
#include <hubbub/hubbub.h>
|
|
|
|
#include <hubbub/parser.h>
|
|
|
|
#endif
|
|
|
|
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, 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.
2018-09-02 14:43:05 +08:00
|
|
|
#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION)
|
2019-08-15 10:49:52 +01:00
|
|
|
#include "private-lib-roles-http-compression.h"
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, 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.
2018-09-02 14:43:05 +08:00
|
|
|
#endif
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#define lwsi_role_http(wsi) (lwsi_role_h1(wsi) || lwsi_role_h2(wsi))
|
|
|
|
|
|
|
|
enum http_version {
|
|
|
|
HTTP_VERSION_1_0,
|
|
|
|
HTTP_VERSION_1_1,
|
|
|
|
HTTP_VERSION_2
|
|
|
|
};
|
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
enum http_conn_type {
|
2018-04-19 12:53:53 +08:00
|
|
|
HTTP_CONNECTION_CLOSE,
|
|
|
|
HTTP_CONNECTION_KEEP_ALIVE
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is totally opaque to code using the library. It's exported as a
|
|
|
|
* forward-reference pointer-only declaration; the user can use the pointer with
|
|
|
|
* other APIs to get information out of it.
|
|
|
|
*/
|
|
|
|
|
2019-08-18 10:35:43 +01:00
|
|
|
#if defined(LWS_PLAT_FREERTOS)
|
2018-04-19 12:53:53 +08:00
|
|
|
typedef uint16_t ah_data_idx_t;
|
|
|
|
#else
|
|
|
|
typedef uint32_t ah_data_idx_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct lws_fragments {
|
|
|
|
ah_data_idx_t offset;
|
|
|
|
uint16_t len;
|
|
|
|
uint8_t nfrag; /* which ah->frag[] continues this content, or 0 */
|
|
|
|
uint8_t flags; /* only http2 cares */
|
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(LWS_WITH_RANGES)
|
|
|
|
enum range_states {
|
|
|
|
LWSRS_NO_ACTIVE_RANGE,
|
|
|
|
LWSRS_BYTES_EQ,
|
|
|
|
LWSRS_FIRST,
|
|
|
|
LWSRS_STARTING,
|
|
|
|
LWSRS_ENDING,
|
|
|
|
LWSRS_COMPLETED,
|
|
|
|
LWSRS_SYNTAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lws_range_parsing {
|
|
|
|
unsigned long long start, end, extent, agg, budget;
|
|
|
|
const char buf[128];
|
|
|
|
int pos;
|
|
|
|
enum range_states state;
|
|
|
|
char start_valid, end_valid, ctr, count_ranges, did_try, inside, send_ctr;
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
lws_ranges_init(struct lws *wsi, struct lws_range_parsing *rp,
|
|
|
|
unsigned long long extent);
|
|
|
|
int
|
|
|
|
lws_ranges_next(struct lws_range_parsing *rp);
|
|
|
|
void
|
|
|
|
lws_ranges_reset(struct lws_range_parsing *rp);
|
|
|
|
#endif
|
|
|
|
|
2020-10-04 07:27:22 +01:00
|
|
|
#define LWS_HTTP_NO_KNOWN_HEADER 0xff
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
/*
|
|
|
|
* these are assigned from a pool held in the context.
|
|
|
|
* Both client and server mode uses them for http header analysis
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct allocated_headers {
|
|
|
|
struct allocated_headers *next; /* linked list */
|
|
|
|
struct lws *wsi; /* owner */
|
|
|
|
char *data; /* prepared by context init to point to dedicated storage */
|
|
|
|
ah_data_idx_t data_length;
|
|
|
|
/*
|
|
|
|
* the randomly ordered fragments, indexed by frag_index and
|
|
|
|
* lws_fragments->nfrag for continuation.
|
|
|
|
*/
|
|
|
|
struct lws_fragments frags[WSI_TOKEN_COUNT];
|
|
|
|
time_t assigned;
|
|
|
|
/*
|
|
|
|
* for each recognized token, frag_index says which frag[] his data
|
|
|
|
* starts in (0 means the token did not appear)
|
|
|
|
* the actual header data gets dumped as it comes in, into data[]
|
|
|
|
*/
|
|
|
|
uint8_t frag_index[WSI_TOKEN_COUNT];
|
|
|
|
|
2019-08-18 05:04:15 +01:00
|
|
|
#if defined(LWS_WITH_CLIENT)
|
2018-04-19 12:53:53 +08:00
|
|
|
char initial_handshake_hash_base64[30];
|
|
|
|
#endif
|
|
|
|
int hdr_token_idx;
|
|
|
|
|
2019-02-26 17:18:24 +08:00
|
|
|
ah_data_idx_t pos;
|
|
|
|
ah_data_idx_t http_response;
|
|
|
|
ah_data_idx_t current_token_limit;
|
2020-06-26 07:34:27 +01:00
|
|
|
ah_data_idx_t unk_pos; /* to undo speculative unknown header */
|
2019-02-26 17:18:24 +08:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_CUSTOM_HEADERS)
|
|
|
|
ah_data_idx_t unk_value_pos;
|
|
|
|
|
|
|
|
ah_data_idx_t unk_ll_head;
|
|
|
|
ah_data_idx_t unk_ll_tail;
|
|
|
|
#endif
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
int16_t lextable_pos;
|
|
|
|
|
|
|
|
uint8_t in_use;
|
|
|
|
uint8_t nfrag;
|
|
|
|
char /*enum uri_path_states */ ups;
|
|
|
|
char /*enum uri_esc_states */ ues;
|
|
|
|
|
|
|
|
char esc_stash;
|
|
|
|
char post_literal_equal;
|
|
|
|
uint8_t /* enum lws_token_indexes */ parser_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-27 14:36:10 +08:00
|
|
|
|
2018-09-04 08:06:46 +08:00
|
|
|
#if defined(LWS_WITH_HUBBUB)
|
2018-04-27 14:36:10 +08:00
|
|
|
struct lws_rewrite {
|
|
|
|
hubbub_parser *parser;
|
|
|
|
hubbub_parser_optparams params;
|
|
|
|
const char *from, *to;
|
|
|
|
int from_len, to_len;
|
|
|
|
unsigned char *p, *end;
|
|
|
|
struct lws *wsi;
|
|
|
|
};
|
|
|
|
static LWS_INLINE int hstrcmp(hubbub_string *s, const char *p, int len)
|
|
|
|
{
|
|
|
|
if ((int)s->len != len)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return strncmp((const char *)s->ptr, p, len);
|
|
|
|
}
|
|
|
|
typedef hubbub_error (*hubbub_callback_t)(const hubbub_token *token, void *pw);
|
|
|
|
LWS_EXTERN struct lws_rewrite *
|
|
|
|
lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, const char *to);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_rewrite_destroy(struct lws_rewrite *r);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_rewrite_parse(struct lws_rewrite *r, const unsigned char *in, int in_len);
|
|
|
|
#endif
|
|
|
|
|
2018-04-27 15:20:56 +08:00
|
|
|
struct lws_pt_role_http {
|
|
|
|
struct allocated_headers *ah_list;
|
|
|
|
struct lws *ah_wait_list;
|
|
|
|
#ifdef LWS_WITH_CGI
|
|
|
|
struct lws_cgi *cgi_list;
|
|
|
|
#endif
|
|
|
|
int ah_wait_list_length;
|
|
|
|
uint32_t ah_pool_length;
|
|
|
|
|
|
|
|
int ah_count_in_use;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lws_peer_role_http {
|
|
|
|
uint32_t count_ah;
|
|
|
|
uint32_t total_ah;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lws_vhost_role_http {
|
2019-08-17 21:20:55 +01:00
|
|
|
#if defined(LWS_CLIENT_HTTP_PROXYING)
|
2018-04-27 15:20:56 +08:00
|
|
|
char http_proxy_address[128];
|
2019-08-17 21:20:55 +01:00
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
const struct lws_http_mount *mount_list;
|
|
|
|
const char *error_document_404;
|
2019-08-17 21:20:55 +01:00
|
|
|
#if defined(LWS_CLIENT_HTTP_PROXYING)
|
2018-04-27 15:20:56 +08:00
|
|
|
unsigned int http_proxy_port;
|
2019-08-17 21:20:55 +01:00
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
};
|
|
|
|
|
2018-04-27 19:16:50 +08:00
|
|
|
#ifdef LWS_WITH_ACCESS_LOG
|
|
|
|
struct lws_access_log {
|
|
|
|
char *header_log;
|
|
|
|
char *user_agent;
|
|
|
|
char *referrer;
|
|
|
|
unsigned long sent;
|
|
|
|
int response;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, 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.
2018-09-02 14:43:05 +08:00
|
|
|
#define LWS_HTTP_CHUNK_HDR_MAX_SIZE (6 + 2) /* 6 hex digits and then CRLF */
|
|
|
|
#define LWS_HTTP_CHUNK_TRL_MAX_SIZE (2 + 5) /* CRLF, then maybe 0 CRLF CRLF */
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
struct _lws_http_mode_related {
|
|
|
|
struct lws *new_wsi_list;
|
2018-04-27 14:36:10 +08:00
|
|
|
|
2018-09-04 08:06:46 +08:00
|
|
|
unsigned char *pending_return_headers;
|
|
|
|
size_t pending_return_headers_len;
|
2019-04-05 21:13:59 +08:00
|
|
|
size_t prh_content_length;
|
2018-09-04 08:06:46 +08:00
|
|
|
|
2018-04-27 14:36:10 +08:00
|
|
|
#if defined(LWS_WITH_HTTP_PROXY)
|
|
|
|
struct lws_rewrite *rw;
|
2019-03-22 06:22:40 +08:00
|
|
|
struct lws_buflist *buflist_post_body;
|
2018-04-27 14:36:10 +08:00
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
struct allocated_headers *ah;
|
|
|
|
struct lws *ah_wait_list;
|
2018-04-27 14:36:10 +08:00
|
|
|
|
2019-10-09 19:11:20 +01:00
|
|
|
unsigned long writeable_len;
|
|
|
|
|
2019-08-18 10:35:43 +01:00
|
|
|
#if defined(LWS_WITH_FILE_OPS)
|
2018-04-19 12:53:53 +08:00
|
|
|
lws_filepos_t filepos;
|
|
|
|
lws_filepos_t filelen;
|
|
|
|
lws_fop_fd_t fop_fd;
|
2019-08-18 10:35:43 +01:00
|
|
|
#endif
|
2019-10-07 14:28:18 +01:00
|
|
|
#if defined(LWS_WITH_CLIENT)
|
|
|
|
char multipart_boundary[16];
|
|
|
|
#endif
|
2018-04-19 12:53:53 +08:00
|
|
|
#if defined(LWS_WITH_RANGES)
|
|
|
|
struct lws_range_parsing range;
|
|
|
|
char multipart_content_type[64];
|
|
|
|
#endif
|
|
|
|
|
2018-04-27 19:16:50 +08:00
|
|
|
#ifdef LWS_WITH_ACCESS_LOG
|
|
|
|
struct lws_access_log access_log;
|
|
|
|
#endif
|
2021-01-06 15:08:22 +00:00
|
|
|
#if defined(LWS_WITH_SERVER)
|
|
|
|
unsigned int response_code;
|
|
|
|
#endif
|
2018-04-27 19:16:50 +08:00
|
|
|
#ifdef LWS_WITH_CGI
|
2020-10-11 07:43:46 +01:00
|
|
|
struct lws_cgi *cgi; /* wsi being cgi stream have one of these */
|
2018-04-27 19:16:50 +08:00
|
|
|
#endif
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, 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.
2018-09-02 14:43:05 +08:00
|
|
|
#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION)
|
|
|
|
struct lws_compression_support *lcs;
|
|
|
|
lws_comp_ctx_t comp_ctx;
|
2018-09-02 14:35:37 +08:00
|
|
|
unsigned char comp_accept_mask;
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, 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.
2018-09-02 14:43:05 +08:00
|
|
|
#endif
|
2018-04-27 19:16:50 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
enum http_version request_version;
|
2018-09-02 14:35:37 +08:00
|
|
|
enum http_conn_type conn_type;
|
2018-04-19 12:53:53 +08:00
|
|
|
lws_filepos_t tx_content_length;
|
|
|
|
lws_filepos_t tx_content_remain;
|
|
|
|
lws_filepos_t rx_content_length;
|
|
|
|
lws_filepos_t rx_content_remain;
|
2018-04-27 14:36:10 +08:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_HTTP_PROXY)
|
|
|
|
unsigned int perform_rewrite:1;
|
2018-09-04 08:06:46 +08:00
|
|
|
unsigned int proxy_clientside:1;
|
|
|
|
unsigned int proxy_parent_chunked:1;
|
2018-04-27 14:36:10 +08:00
|
|
|
#endif
|
2018-06-16 10:38:17 +08:00
|
|
|
unsigned int deferred_transaction_completed:1;
|
2018-07-21 10:26:13 +08:00
|
|
|
unsigned int content_length_explicitly_zero:1;
|
2020-02-28 10:31:04 +00:00
|
|
|
unsigned int content_length_given:1;
|
2018-09-04 08:06:46 +08:00
|
|
|
unsigned int did_stream_close:1;
|
2019-10-07 14:28:18 +01:00
|
|
|
unsigned int multipart:1;
|
2019-11-18 09:19:08 +00:00
|
|
|
unsigned int cgi_transaction_complete:1;
|
2019-10-07 14:28:18 +01:00
|
|
|
unsigned int multipart_issue_boundary:1;
|
2018-04-19 12:53:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-18 05:04:15 +01:00
|
|
|
#if defined(LWS_WITH_CLIENT)
|
2018-04-19 12:53:53 +08:00
|
|
|
enum lws_chunk_parser {
|
|
|
|
ELCP_HEX,
|
|
|
|
ELCP_CR,
|
|
|
|
ELCP_CONTENT,
|
|
|
|
ELCP_POST_CR,
|
|
|
|
ELCP_POST_LF,
|
2020-01-30 13:19:11 +00:00
|
|
|
ELCP_TRAILER_CR,
|
|
|
|
ELCP_TRAILER_LF
|
2018-04-19 12:53:53 +08:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum lws_parse_urldecode_results {
|
|
|
|
LPUR_CONTINUE,
|
|
|
|
LPUR_SWALLOW,
|
|
|
|
LPUR_FORBID,
|
|
|
|
LPUR_EXCESSIVE,
|
|
|
|
};
|
|
|
|
|
2018-11-28 12:16:01 +08:00
|
|
|
enum lws_check_basic_auth_results {
|
|
|
|
LCBA_CONTINUE,
|
|
|
|
LCBA_FAILED_AUTH,
|
|
|
|
LCBA_END_TRANSACTION,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum lws_check_basic_auth_results
|
2019-12-12 18:45:00 +00:00
|
|
|
lws_check_basic_auth(struct lws *wsi, const char *basic_auth_login_file, unsigned int auth_mode);
|
2018-11-28 12:16:01 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
lws_unauthorised_basic_auth(struct lws *wsi);
|
|
|
|
|
2018-04-27 19:16:50 +08:00
|
|
|
int
|
|
|
|
lws_read_h1(struct lws *wsi, unsigned char *buf, lws_filepos_t len);
|
2018-04-19 12:53:53 +08:00
|
|
|
|
2018-04-27 19:16:50 +08:00
|
|
|
void
|
|
|
|
_lws_header_table_reset(struct allocated_headers *ah);
|
2018-04-19 12:53:53 +08:00
|
|
|
|
2018-04-27 19:16:50 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
_lws_destroy_ah(struct lws_context_per_thread *pt, struct allocated_headers *ah);
|
2019-02-20 07:47:48 +08:00
|
|
|
|
2019-03-19 11:53:57 +08:00
|
|
|
int
|
|
|
|
lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit,
|
|
|
|
char *uri_ptr, char ws);
|
2019-08-09 10:12:09 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
lws_sul_http_ah_lifecheck(lws_sorted_usec_list_t *sul);
|
2019-10-07 14:28:18 +01:00
|
|
|
|
|
|
|
uint8_t *
|
|
|
|
lws_http_multipart_headers(struct lws *wsi, uint8_t *p);
|
2020-03-07 20:03:58 +00:00
|
|
|
|
ss: rx metadata
At the moment you can define and set per-stream metadata at the client,
which will be string-substituted and if configured in the policy, set in
related outgoing protocol specific content like h1 headers.
This patch extends the metadata concept to also check incoming protocol-
specific content like h1 headers and where it matches the binding in the
streamtype's metadata entry, make it available to the client by name, via
a new lws_ss_get_metadata() api.
Currently warmcat.com has additional headers for
server: lwsws (well-known header name)
test-custom-header: hello (custom header name)
minimal-secure-streams test is updated to try to recover these both
in direct and -client (via proxy) versions. The corresponding metadata
part of the "mintest" stream policy from warmcat.com is
{
"srv": "server:"
}, {
"test": "test-custom-header:"
},
If built direct, or at the proxy, the stream has access to the static
policy metadata definitions and can store the rx metadata in the stream
metadata allocation, with heap-allocated a value. For client side that
talks to a proxy, only the proxy knows the policy, and it returns rx
metadata inside the serialized link to the client, which stores it on
the heap attached to the stream.
In addition an optimization for mapping static policy metadata definitions
to individual stream handle metadata is changed to match by name.
2020-09-10 06:43:43 +01:00
|
|
|
int
|
|
|
|
lws_http_string_to_known_header(const char *s, size_t slen);
|
|
|
|
|
2020-09-17 12:43:31 +01:00
|
|
|
int
|
|
|
|
lws_http_date_render_from_unix(char *buf, size_t len, const time_t *t);
|
|
|
|
|
|
|
|
int
|
|
|
|
lws_http_date_parse_unix(const char *b, size_t len, time_t *t);
|
|
|
|
|
2020-04-21 19:49:58 +01:00
|
|
|
enum {
|
|
|
|
CCTLS_RETURN_ERROR = -1,
|
|
|
|
CCTLS_RETURN_DONE = 0,
|
|
|
|
CCTLS_RETURN_RETRY = 1,
|
|
|
|
};
|
|
|
|
|
2020-03-07 20:03:58 +00:00
|
|
|
int
|
|
|
|
lws_client_create_tls(struct lws *wsi, const char **pcce, int do_c1);
|