summaryrefslogtreecommitdiff
path: root/lib/sendf.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2022-09-09 15:11:14 +0200
committerDaniel Stenberg <daniel@haxx.se>2022-09-09 15:11:14 +0200
commit664249d095275ec532f55dd1752d80c8c1093a77 (patch)
treef8e3add4b66fb64271d22178743f3dc2f1758dcd /lib/sendf.c
parent60a3b25dbf1f211f6ba5216f2d774cfb26cb3e29 (diff)
downloadcurl-664249d095275ec532f55dd1752d80c8c1093a77.tar.gz
ws: initial websockets support
Closes #8995
Diffstat (limited to 'lib/sendf.c')
-rw-r--r--lib/sendf.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/sendf.c b/lib/sendf.c
index 2fe7169dd..66cec0597 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -48,6 +48,7 @@
#include "strdup.h"
#include "http2.h"
#include "headers.h"
+#include "ws.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -534,6 +535,7 @@ static CURLcode chop_write(struct Curl_easy *data,
curl_write_callback writebody = NULL;
char *ptr = optr;
size_t len = olen;
+ void *writebody_ptr = data->set.out;
if(!len)
return CURLE_OK;
@@ -544,8 +546,18 @@ static CURLcode chop_write(struct Curl_easy *data,
return pausewrite(data, type, ptr, len);
/* Determine the callback(s) to use. */
- if(type & CLIENTWRITE_BODY)
+ if(type & CLIENTWRITE_BODY) {
+#ifdef USE_WEBSOCKETS
+ if(conn->handler->protocol & (CURLPROTO_WS|CURLPROTO_WSS)) {
+ struct HTTP *ws = data->req.p.http;
+ writebody = Curl_ws_writecb;
+ ws->ws.data = data;
+ writebody_ptr = ws;
+ }
+ else
+#endif
writebody = data->set.fwrite_func;
+ }
if((type & CLIENTWRITE_HEADER) &&
(data->set.fwrite_header || data->set.writeheader)) {
/*
@@ -563,7 +575,7 @@ static CURLcode chop_write(struct Curl_easy *data,
if(writebody) {
size_t wrote;
Curl_set_in_callback(data, true);
- wrote = writebody(ptr, 1, chunklen, data->set.out);
+ wrote = writebody(ptr, 1, chunklen, writebody_ptr);
Curl_set_in_callback(data, false);
if(CURL_WRITEFUNC_PAUSE == wrote) {