support http/2

This commit is contained in:
ading2210 2024-01-17 17:46:08 -05:00
parent 8bcfc2157c
commit baab0aea8f
6 changed files with 36 additions and 3 deletions

View file

@ -13,7 +13,7 @@ WISP_CLIENT="wisp_client"
EXPORTED_FUNCS="_init_curl,_start_request,_tick_request,_active_requests"
RUNTIME_METHODS="addFunction,removeFunction,allocate,ALLOC_NORMAL"
COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lssl -lcrypto -lcjson -lz -lbrotlidec -lbrotlicommon -I $INCLUDE_DIR -L $LIB_DIR"
COMPILER_OPTIONS="-o $MODULE_FILE -lcurl -lssl -lcrypto -lcjson -lz -lbrotlidec -lbrotlicommon -lnghttp2 -I $INCLUDE_DIR -L $LIB_DIR"
EMSCRIPTEN_OPTIONS="-lwebsocket.js -sASSERTIONS=1 -sALLOW_TABLE_GROWTH -sALLOW_MEMORY_GROWTH -sEXPORTED_FUNCTIONS=$EXPORTED_FUNCS -sEXPORTED_RUNTIME_METHODS=$RUNTIME_METHODS"
if [ "$1" = "release" ]; then

View file

@ -72,6 +72,7 @@ void start_request(const char* url, const char* json_params, DataCallback data_c
//some default options
curl_easy_setopt(http_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(http_handle, CURLOPT_ACCEPT_ENCODING, "");
curl_easy_setopt(http_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
//if url is a websocket, tell curl that we should handle the connection manually
if (starts_with(url, "wss://") || starts_with(url, "ws://")) {

View file

@ -9,6 +9,7 @@ CJSON_PREFIX=$(realpath build/cjson-wasm)
CURL_PREFIX=$(realpath build/curl-wasm)
ZLIB_PREFIX=$(realpath build/zlib-wasm)
BROTLI_PREFIX=$(realpath build/brotli-wasm)
NGHTTP2_PREFIX=$(realpath build/nghttp2-wasm)
if [ ! -d $OPENSSL_PREFIX ]; then
tools/openssl.sh
@ -25,8 +26,12 @@ fi
if [ ! -d $CURL_PREFIX ]; then
tools/curl.sh
fi
if [ ! -d $NGHTTP2_PREFIX ]; then
tools/nghttp2.sh
fi
cp -r $OPENSSL_PREFIX/* $CURL_PREFIX
cp -r $CJSON_PREFIX/* $CURL_PREFIX
cp -r $ZLIB_PREFIX/* $CURL_PREFIX
cp -r $BROTLI_PREFIX/* $CURL_PREFIX
cp -r $BROTLI_PREFIX/* $CURL_PREFIX
cp -r $NGHTTP2_PREFIX/* $CURL_PREFIX

View file

@ -10,6 +10,7 @@ PREFIX=$(realpath build/curl-wasm)
OPENSSL_PREFIX=$(realpath build/openssl-wasm)
ZLIB_PREFIX=$(realpath build/zlib-wasm)
BROTLI_PREFIX=$(realpath build/brotli-wasm)
NGHTTP2_PREFIX=$(realpath build/nghttp2-wasm)
cd build
rm -rf curl
@ -17,7 +18,7 @@ git clone -b master --depth=1 https://github.com/curl/curl
cd curl
autoreconf -fi
emconfigure ./configure --host i686-linux --disable-shared --disable-threaded-resolver --without-libpsl --disable-netrc --disable-ipv6 --disable-tftp --disable-ntlm-wb --enable-websockets --with-ssl=$OPENSSL_PREFIX --with-zlib=$ZLIB_PREFIX --with-brotli=$BROTLI_PREFIX
emconfigure ./configure --host i686-linux --disable-shared --disable-threaded-resolver --without-libpsl --disable-netrc --disable-ipv6 --disable-tftp --disable-ntlm-wb --enable-websockets --with-ssl=$OPENSSL_PREFIX --with-zlib=$ZLIB_PREFIX --with-brotli=$BROTLI_PREFIX --with-nghttp2=$NGHTTP2_PREFIX
emmake make -j$CORE_COUNT CFLAGS="-pthread" LIBS="-lbrotlicommon"
rm -rf $PREFIX

24
client/tools/nghttp2.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
#compile nghttp2 for use with emscripten
set -x
set -e
CORE_COUNT=$(nproc --all)
PREFIX=$(realpath build/nghttp2-wasm)
cd build
rm -rf nghttp2
git clone -b master --depth=1 https://github.com/nghttp2/nghttp2
cd nghttp2
rm -rf $PREFIX
mkdir -p $PREFIX
autoreconf -fi
emconfigure ./configure --host i686-linux --enable-static --disable-shared --enable-lib-only --prefix=$PREFIX
emmake make -j$CORE_COUNT
make install
cd ../../

View file

@ -14,6 +14,8 @@ rm -rf openssl
git clone -b master --depth=1 https://github.com/openssl/openssl
cd openssl
export CFLAGS="-Wall -Oz"
export CXXFLAGS="-Wall -Oz"
emconfigure ./Configure linux-x32 --prefix=$PREFIX -no-asm -static -no-afalgeng -no-dso -DOPENSSL_SYS_NETWARE -DSIG_DFL=0 -DSIG_IGN=0 -DHAVE_FORK=0 -DOPENSSL_NO_AFALGENG=1 -DOPENSSL_NO_SPEED=1 -DOPENSSL_NO_DYNAMIC_ENGINE -DDLOPEN_FLAG=0
sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile
emmake make -j$CORE_COUNT build_generated libssl.a libcrypto.a