zhaojh329 / libuhttpd Goto Github PK
View Code? Open in Web Editor NEWA very flexible, lightweight and high performance HTTP server library based on libev and http-parser for Embedded Linux.
License: MIT License
A very flexible, lightweight and high performance HTTP server library based on libev and http-parser for Embedded Linux.
License: MIT License
Hi,
I thought that by chunking I would be able to like stream the output to a webpage, but it doesn't work. The browser waits and then gets it al at once.
I do
conn->send_head(conn, 200, -1, NULL);
conn->chunk_printf(conn, render_header());
conn->chunk_printf(conn, "In progress...");
sleep(3); // symbolizing the work
conn->chunk_printf(conn,"Complete");
conn->chunk_printf(conn, render_footer());
conn->chunk_end(conn);
So I would expect to have the header and the In progress...
on screen, and after 3 seconds the rest. But my browser just waits the 3 seconds and then shows it all. The same happens when I do it with curl.
What am I doing wrong?
Thanks,
Herman
Hi,
Can you reproduce this? I cloned openwrt today, on 302f7d57a9ad31d71e737af8932aa8e86c476699.
I switched the C library to glibc.
[removed]/staging_dir/toolchain-x86_64_gcc-7.4.0_glibc/lib/gcc/x86_64-openwrt-linux-gnu/7.4.0/../../../../x86_64-openwrt-linux-gnu/bin/ld: [removed]/staging_dir/target-x86_64_glibc/usr/lib/liblua.so: undefined reference to `log10'
[removed]/staging_dir/toolchain-x86_64_gcc-7.4.0_glibc/lib/gcc/x86_64-openwrt-linux-gnu/7.4.0/../../../../x86_64-openwrt-linux-gnu/bin/ld: [removed]/staging_dir/target-x86_64_glibc/usr/lib/liblua.so: undefined reference to `sqrt'
[removed]/staging_dir/toolchain-x86_64_gcc-7.4.0_glibc/lib/gcc/x86_64-openwrt-linux-gnu/7.4.0/../../../../x86_64-openwrt-linux-gnu/bin/ld: [removed]/staging_dir/target-x86_64_glibc/usr/lib/liblua.so: undefined reference to `asinh'
[removed]/staging_dir/toolchain-x86_64_gcc-7.4.0_glibc/lib/gcc/x86_64-openwrt-linux-gnu/7.4.0/../../../../x86_64-openwrt-linux-gnu/bin/ld: [removed]/staging_dir/target-x86_64_glibc/usr/lib/liblua.so: undefined reference to `floor'
collect2: error: ld returned 1 exit status
example/CMakeFiles/template.dir/build.make:86: recipe for target 'example/template' failed
make[6]: *** [example/template] Error 1
make[6]: Leaving directory '[removed]/build_dir/target-x86_64_glibc/libuhttpd-mbedtls/libuhttpd-2.2.1'
CMakeFiles/Makefile2:204: recipe for target 'example/CMakeFiles/template.dir/all' failed
make[5]: *** [example/CMakeFiles/template.dir/all] Error 2
make[5]: Leaving directory '[removed]/build_dir/target-x86_64_glibc/libuhttpd-mbedtls/libuhttpd-2.2.1'
Makefile:129: recipe for target 'all' failed
make[4]: *** [all] Error 2
Thank you in advance!
当在openwrt的编译环境中,make package/libuhttpd/compile V=99时,产生找不到liblua.so的错误
#sudo make package/libuhttpd/compile V=99
.....
install -d -m0755 /home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64/build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-2.2.2/ipkg-rtd1295/libuhttpd-nossl/usr/lib/
install -m0644 /home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64/build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-2.2.2/ipkg-install/usr/lib/libuhttpd.so* /home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64/build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-2.2.2/ipkg-rtd1295/libuhttpd-nossl/usr/lib/
find /home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64/build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-2.2.2/ipkg-rtd1295/libuhttpd-nossl -name 'CVS' -o -name '.svn' -o -name '.#' -o -name '~'| xargs -r rm -rf
Package libuhttpd-nossl is missing dependencies for the following libraries:
liblua.so.5.1.5
Makefile:83: recipe for target '/home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64/bin/rtd1295-glibc/packages/base/libuhttpd-nossl_2.2.2-1_rtd1295.ipk' failed
make[2]: *** [/home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64/bin/rtd1295-glibc/packages/base/libuhttpd-nossl_2.2.2-1_rtd1295.ipk] Error 1
make[2]: Leaving directory '/home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64/package/network/services/libuhttpd'
package/Makefile:191: recipe for target 'package/network/services/libuhttpd/compile' failed
make[1]: *** [package/network/services/libuhttpd/compile] Error 2
make[1]: Leaving directory '/home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64'
/home/ugreen/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64/include/toplevel.mk:198: recipe for target 'package/libuhttpd/compile' failed
make: *** [package/libuhttpd/compile] Error 2
#find ./ -name liblua.so.*
./target/linux/rtd1295/image/image_file-r160868/tmp/rootfs/usr/lib/liblua.so.5.1.5
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/root-rtd1295/usr/lib/liblua.so.5.1.5
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/lua-5.1.5/ipkg-install/usr/lib/liblua.so.5.1.5
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/lua-5.1.5/ipkg-rtd1295/liblua/usr/lib/liblua.so.5.1.5
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/lua-5.1.5/src/liblua.so.5.1.5
./staging_dir/target-aarch64_cortex-a53+neon_glibc-2.19/root-rtd1295/usr/lib/liblua.so.5.1.5
./staging_dir/target-aarch64_cortex-a53+neon_glibc-2.19/usr/lib/liblua.so.5.1.5
find ./ -name libuhttpd.so.*
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-1.0.4/ipkg-install/usr/lib/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-1.0.4/ipkg-rtd1295/libuhttpd-nossl/usr/lib/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-1.0.4/src/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-2.2.2/ipkg-install/usr/lib/libuhttpd.so.2.2.2
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-2.2.2/ipkg-rtd1295/libuhttpd-nossl/usr/lib/libuhttpd.so.2.2.2
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-nossl/libuhttpd-2.2.2/src/libuhttpd.so.2.2.2
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-mbedtls/libuhttpd-1.0.4/ipkg-install/usr/lib/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-mbedtls/libuhttpd-1.0.4/ipkg-rtd1295/libuhttpd-mbedtls/usr/lib/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-mbedtls/libuhttpd-1.0.4/src/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-openssl/libuhttpd-1.0.4/ipkg-install/usr/lib/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-openssl/libuhttpd-1.0.4/ipkg-rtd1295/libuhttpd-openssl/usr/lib/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-openssl/libuhttpd-1.0.4/src/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-openssl/libuhttpd-2.2.2/src/libuhttpd.so.2.2.2
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-wolfssl/libuhttpd-1.0.4/ipkg-install/usr/lib/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-wolfssl/libuhttpd-1.0.4/ipkg-rtd1295/libuhttpd-wolfssl/usr/lib/libuhttpd.so.1.0.4
./build_dir/target-aarch64_cortex-a53+neon_glibc-2.19/libuhttpd-wolfssl/libuhttpd-1.0.4/src/libuhttpd.so.1.0.4
./staging_dir/target-aarch64_cortex-a53+neon_glibc-2.19/root-rtd1295/usr/lib/libuhttpd.so.1.0.4
ugreen@ugreen-PowerEdge-T140:~/sdk1296/buildscripts/OpenWrt-ImageBuilder-rtd1295-mnas_emmc.Linux-x86_64$
Something strange happened locally such that a bunch of packages now get linking errors. This one included:
[13/21] Linking C executable example/multi_process_server
FAILED: example/multi_process_server
: && /home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/bin/powerpc-openwrt-linux-musl-gcc -Os -pipe -mcpu=464fp -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -fmacro-prefix-map=/home/mangix/devstuff/openwrt/build_dir/target-powerpc_464fp_musl/libuhttpd-nossl/libuhttpd-3.12.1=libuhttpd-3.12.1 -Wformat -Werror=format-security -DPIC -fPIC -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,now -Wl,-z,relro -DNDEBUG -L/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/usr/lib -L/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib -DPIC -fPIC -specs=/home/mangix/devstuff/openwrt/include/hardened-ld-pie.specs -znow -zrelro -rdynamic example/CMakeFiles/multi_process_server.dir/multi_process_server.c.o example/CMakeFiles/multi_process_server.dir/handler.c.o -o example/multi_process_server -lev src/libuhttpd.so.3.12.1 && :
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuhttpd.so.3.12.1: undefined reference to `ssl_session_free'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuhttpd.so.3.12.1: undefined reference to `ssl_connect'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuhttpd.so.3.12.1: undefined reference to `ssl_read'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuhttpd.so.3.12.1: undefined reference to `ssl_strerror'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuhttpd.so.3.12.1: undefined reference to `ssl_err_code'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuhttpd.so.3.12.1: undefined reference to `ssl_write'
/home/mangix/devstuff/openwrt/staging_dir/toolchain-powerpc_464fp_gcc-11.2.0_musl/lib/gcc/powerpc-openwrt-linux-musl/11.2.0/../../../../powerpc-openwrt-linux-musl/bin/ld: src/libuhttpd.so.3.12.1: undefined reference to `ssl_session_new'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
make[2]: *** [Makefile:61: /home/mangix/devstuff/openwrt/build_dir/target-powerpc_464fp_musl/libuhttpd-nossl/libuhttpd-3.12.1/.built] Error 1
make[2]: Leaving directory '/home/mangix/devstuff/openwrt/feeds/packages/libs/libuhttpd'
time: package/feeds/packages/libuhttpd/nossl/compile#0.21#0.11#0.31
ERROR: package/feeds/packages/libuhttpd failed to build (build variant: nossl).
make[1]: *** [package/Makefile:125: package/feeds/packages/libuhttpd/compile] Error 1
make[1]: Leaving directory '/home/mangix/devstuff/openwrt'
make: *** [/home/mangix/devstuff/openwrt/include/toplevel.mk:230: package/libuhttpd/compile] Error 2
Looking at the code, these functions are not implemented when there is no ssl library.
After "make install" a "sudo ldconfig" is required for dynamic linking (built on Ubuntu).
Hi zhaojh329, it seems that the lua bindings were removed in v3, is there any intention to reimplement a lua binding? If I want to use from within Lua should I just stick to v2.x? Thanks!
I'll restructure the project using libubox and no longer use libev.
您好大神,我向您求助
我的系统:debian10.13
我提前下载并编译了libev,make install的位置是/usr/local/libev-4.33/install
然后,我用这个命令下载了您的库以及依赖库:git clone --branch v3.14.1 --recursive https://github.com/zhaojh329/libuhttpd.git
然后,我解压了库,并创建了build文件夹,我cd到了这里:/usr/local/libuhttpd/build
然后,我尝试用:cmake ..
我看到了如下的错误:
CMake Error at /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find Libev (missing: LIBEV_LIBRARY LIBEV_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindLibev.cmake:25 (find_package_handle_standard_args)
CMakeLists.txt:20 (find_package)
我尝试了手动添加环境变量:export LIBEV_LIBRARY=/usr/local/libev-4.33/install/lib,然后,再次执行cmake ..
还是遇到了相同的错误。
请您指正,如何正确进行cmake?非常感谢。
您好大神,请问这个库支持用C++调用吗
Prior to commit e557721, it was easy to send a custom error message to the client:
conn->error(conn, HTTP_STATUS_BAD_REQUEST, "I cannot understand this POST data.\n");
would give:
$ curl localhost:8000 -d zborglh
I cannot understand this POST data.
Since that commit, the error()
method is no longer available. Instead, we have a new method called send_error()
, which always sends an empty body:
conn->send_error(conn, HTTP_STATUS_BAD_REQUEST, "I cannot understand this POST data.");
gives:
$ curl localhost:8000 -d zborglh
$ # ← empty response body
Inspecting the full response, it appears the custom message is sent, but it is sent as the status text:
$ curl -i localhost:8000 -d zborglh
HTTP/1.1 400 I cannot understand this POST data.
Server: Libuhttpd/3.14.1
Content-Length: 0
Content-Type: text/plain
Connection: close
A custom status text is far less useful than a custom message within the response body. Would you please consider restoring the functionality of the previous error()
method?
This is a feature request.
The send_head()
method either sends a Content-Length header (if a valid length is provided), or enables chunked transfer encoding. It would be nice if it could be instructed to do neither.
Use case: Server-sent events (SSE) are a nice way to send a stream of messages to the client without requiring a request/response pair for each message. Although not as popular as WebSockets, SSE has the advantage of simplicity. Being plain HTTP, it is easier to implement on an HTTP server, as it doesn't require switching protocols. The framing overhead can be as small as 7 bytes per message:
/* This is a complete SSE message. */
conn->printf(conn, "data:%s\n\n", message_payload);
Even though SSE seems to work fine with chunked transfer encoding, using this encoding is not required, and is actually not recommended:
Authors are also cautioned that HTTP chunking can have unexpected negative effects on the reliability of this protocol, in particular if the chunking is done by a different layer unaware of the timing requirements. If this is a problem, chunking can be disabled for serving event streams.
Also, wrapping SSE with chunked transfer encoding amounts to redundant message framing, which practically doubles the framing overhead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.