mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
refactor: move everything related to HTTP_PROXY out of struct lws and private-libwebsockets.h into http role private
This commit is contained in:
parent
25e27d76d1
commit
9c9ef9cea2
5 changed files with 57 additions and 50 deletions
|
@ -789,9 +789,9 @@ just_kill_connection:
|
|||
wsi, wsi->desc.sockfd);
|
||||
|
||||
#ifdef LWS_WITH_HTTP_PROXY
|
||||
if (wsi->rw) {
|
||||
lws_rewrite_destroy(wsi->rw);
|
||||
wsi->rw = NULL;
|
||||
if (wsi->http.rw) {
|
||||
lws_rewrite_destroy(wsi->http.rw);
|
||||
wsi->http.rw = NULL;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
|
|
|
@ -135,10 +135,7 @@
|
|||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef LWS_WITH_HTTP_PROXY
|
||||
#include <hubbub/hubbub.h>
|
||||
#include <hubbub/parser.h>
|
||||
#endif
|
||||
|
||||
#if defined(LWS_BUILTIN_GETIFADDRS)
|
||||
#include "./misc/getifaddrs.h"
|
||||
#else
|
||||
|
@ -1386,6 +1383,10 @@ struct lws {
|
|||
struct _lws_websocket_related *ws; /* allocated if we upgrade to ws */
|
||||
#endif
|
||||
|
||||
struct lws_role_ops *role_ops;
|
||||
lws_wsi_state_t wsistate;
|
||||
lws_wsi_state_t wsistate_pre_close;
|
||||
|
||||
/* lifetime members */
|
||||
|
||||
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
|
||||
|
@ -1442,13 +1443,12 @@ struct lws {
|
|||
lws_tls_bio *client_bio;
|
||||
struct lws *pending_read_list_prev, *pending_read_list_next;
|
||||
#endif
|
||||
#ifdef LWS_WITH_HTTP_PROXY
|
||||
struct lws_rewrite *rw;
|
||||
#endif
|
||||
|
||||
#ifdef LWS_LATENCY
|
||||
unsigned long action_start;
|
||||
unsigned long latency_start;
|
||||
#endif
|
||||
|
||||
lws_sock_file_fd_type desc; /* .filefd / .sockfd */
|
||||
#if defined(LWS_WITH_STATS)
|
||||
uint64_t active_writable_req_us;
|
||||
|
@ -1457,14 +1457,10 @@ struct lws {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
struct lws_role_ops *role_ops;
|
||||
|
||||
lws_usec_t pending_timer;
|
||||
|
||||
time_t pending_timeout_set;
|
||||
|
||||
lws_wsi_state_t wsistate;
|
||||
lws_wsi_state_t wsistate_pre_close;
|
||||
|
||||
|
||||
/* ints */
|
||||
int position_in_fds_table;
|
||||
|
@ -1526,19 +1522,14 @@ struct lws {
|
|||
unsigned int client_h2_alpn:1;
|
||||
unsigned int client_h2_substream:1;
|
||||
#endif
|
||||
#ifdef LWS_WITH_HTTP_PROXY
|
||||
unsigned int perform_rewrite:1;
|
||||
#endif
|
||||
|
||||
#if defined(LWS_WITH_TLS)
|
||||
unsigned int use_ssl;
|
||||
unsigned int redirect_to_https:1;
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
unsigned int sock_send_blocking:1;
|
||||
#endif
|
||||
#if defined(LWS_WITH_TLS)
|
||||
unsigned int redirect_to_https:1;
|
||||
#endif
|
||||
|
||||
#ifndef LWS_NO_CLIENT
|
||||
unsigned short c_port;
|
||||
|
@ -1912,30 +1903,6 @@ lws_tls_check_cert_lifetime(struct lws_vhost *vhost);
|
|||
|
||||
int lws_jws_selftest(void);
|
||||
|
||||
#ifdef LWS_WITH_HTTP_PROXY
|
||||
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
|
||||
|
||||
#ifndef LWS_NO_CLIENT
|
||||
LWS_EXTERN int lws_client_socket_service(struct lws *wsi,
|
||||
|
|
|
@ -1044,7 +1044,7 @@ lws_client_connect_via_info(struct lws_client_connect_info *i)
|
|||
}
|
||||
#ifdef LWS_WITH_HTTP_PROXY
|
||||
if (i->uri_replace_to)
|
||||
wsi->rw = lws_rewrite_create(wsi, html_parser_cb,
|
||||
wsi->http.rw = lws_rewrite_create(wsi, html_parser_cb,
|
||||
i->uri_replace_from,
|
||||
i->uri_replace_to);
|
||||
#endif
|
||||
|
|
|
@ -834,12 +834,12 @@ lws_client_interpret_server_handshake(struct lws *wsi)
|
|||
}
|
||||
|
||||
#ifdef LWS_WITH_HTTP_PROXY
|
||||
wsi->perform_rewrite = 0;
|
||||
wsi->http.perform_rewrite = 0;
|
||||
if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE)) {
|
||||
if (!strncmp(lws_hdr_simple_ptr(wsi,
|
||||
WSI_TOKEN_HTTP_CONTENT_TYPE),
|
||||
"text/html", 9))
|
||||
wsi->perform_rewrite = 1;
|
||||
wsi->http.perform_rewrite = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1144,8 +1144,8 @@ spin_chunks:
|
|||
|
||||
#ifdef LWS_WITH_HTTP_PROXY
|
||||
/* hubbub */
|
||||
if (wsi->perform_rewrite)
|
||||
lws_rewrite_parse(wsi->rw, (unsigned char *)*buf, n);
|
||||
if (wsi->http.perform_rewrite)
|
||||
lws_rewrite_parse(wsi->http.rw, (unsigned char *)*buf, n);
|
||||
else
|
||||
#endif
|
||||
{
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
* enabled
|
||||
*/
|
||||
|
||||
#if defined(LWS_WITH_HTTP_PROXY)
|
||||
#include <hubbub/hubbub.h>
|
||||
#include <hubbub/parser.h>
|
||||
#endif
|
||||
|
||||
#define lwsi_role_http(wsi) (lwsi_role_h1(wsi) || lwsi_role_h2(wsi))
|
||||
|
||||
enum http_version {
|
||||
|
@ -127,8 +132,39 @@ struct allocated_headers {
|
|||
};
|
||||
|
||||
|
||||
|
||||
#if defined(LWS_WITH_HTTP_PROXY)
|
||||
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
|
||||
|
||||
struct _lws_http_mode_related {
|
||||
struct lws *new_wsi_list;
|
||||
|
||||
#if defined(LWS_WITH_HTTP_PROXY)
|
||||
struct lws_rewrite *rw;
|
||||
#endif
|
||||
|
||||
lws_filepos_t filepos;
|
||||
lws_filepos_t filelen;
|
||||
lws_fop_fd_t fop_fd;
|
||||
|
@ -144,6 +180,10 @@ struct _lws_http_mode_related {
|
|||
lws_filepos_t tx_content_remain;
|
||||
lws_filepos_t rx_content_length;
|
||||
lws_filepos_t rx_content_remain;
|
||||
|
||||
#if defined(LWS_WITH_HTTP_PROXY)
|
||||
unsigned int perform_rewrite:1;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue