aboutsummaryrefslogtreecommitdiff
path: root/lib/roles/h1
diff options
context:
space:
mode:
authorAndy Green <andy@warmcat.com>2019-04-05 21:13:59 +0800
committerAndy Green <andy@warmcat.com>2019-05-06 10:24:51 +0100
commitf89aa401ccf371530119cf858da997a02c0f3905 (patch)
tree1436d2934ac886df3c899f113820435df3cfb0a6 /lib/roles/h1
parent7ca8b77f2cba3d4d042fa2a3df70660529f44dab (diff)
downloadlibwebsockets-f89aa401ccf371530119cf858da997a02c0f3905.tar.gz
generic-sessions update
Generic sessions has been overdue some love to align it with the progress in the rest of lws. 1) Strict Content Security Policy 2) http2 compatibility 3) fixes and additions for use in a separate process via unix domain socket 4) work on ws and http proxying in lws 5) add minimal example
Diffstat (limited to 'lib/roles/h1')
-rw-r--r--lib/roles/h1/ops-h1.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/lib/roles/h1/ops-h1.c b/lib/roles/h1/ops-h1.c
index 19860b53..ad8a0baf 100644
--- a/lib/roles/h1/ops-h1.c
+++ b/lib/roles/h1/ops-h1.c
@@ -116,7 +116,7 @@ lws_read_h1(struct lws *wsi, unsigned char *buf, lws_filepos_t len)
case LRS_BODY:
http_postbody:
- lwsl_notice("%s: http post body: remain %d\n", __func__,
+ lwsl_debug("%s: http post body: remain %d\n", __func__,
(int)wsi->http.rx_content_remain);
if (!wsi->http.rx_content_remain)
@@ -659,27 +659,35 @@ rops_handle_POLLOUT_h1(struct lws *wsi)
if (lwsi_state(wsi) == LRS_ISSUE_HTTP_BODY) {
#if defined(LWS_WITH_HTTP_PROXY)
if (wsi->http.proxy_clientside) {
- unsigned char *buf;
+ unsigned char *buf, prebuf[LWS_PRE + 1024];
size_t len = lws_buflist_next_segment_len(
&wsi->parent->http.buflist_post_body, &buf);
int n;
- lwsl_debug("%s: %p: proxying body %d %d %d %d %d\n",
- __func__, wsi, (int)len,
- (int)wsi->http.tx_content_length,
- (int)wsi->http.tx_content_remain,
- (int)wsi->http.rx_content_length,
- (int)wsi->http.rx_content_remain
- );
-
- n = lws_write(wsi, buf, len, LWS_WRITE_HTTP);
- if (n < 0) {
- lwsl_err("%s: PROXY_BODY: write failed\n",
- __func__);
- return -1;
- }
+ if (len) {
+
+ if (len > sizeof(prebuf) - LWS_PRE)
+ len = sizeof(prebuf) - LWS_PRE;
+
+ memcpy(prebuf + LWS_PRE, buf, len);
- lws_buflist_use_segment(&wsi->parent->http.buflist_post_body, len);
+ lwsl_debug("%s: %p: proxying body %d %d %d %d %d\n",
+ __func__, wsi, (int)len,
+ (int)wsi->http.tx_content_length,
+ (int)wsi->http.tx_content_remain,
+ (int)wsi->http.rx_content_length,
+ (int)wsi->http.rx_content_remain
+ );
+
+ n = lws_write(wsi, prebuf + LWS_PRE, len, LWS_WRITE_HTTP);
+ if (n < 0) {
+ lwsl_err("%s: PROXY_BODY: write %d failed\n",
+ __func__, (int)len);
+ return LWS_HP_RET_BAIL_DIE;
+ }
+
+ lws_buflist_use_segment(&wsi->parent->http.buflist_post_body, len);
+ }
if (wsi->parent->http.buflist_post_body)
lws_callback_on_writable(wsi);