This is a maintenance fork of libuhttpd
 
 
 
Go to file
Jianhui Zhao 3cb41b2403 Update CONTRIBUTING
Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
2017-12-29 14:54:34 +08:00
cmake/Modules Restructure with libubox 2017-12-29 14:40:58 +08:00
example Restructure with libubox 2017-12-29 14:40:58 +08:00
src Bump version to 1.0.0 2017-12-29 14:42:37 +08:00
.gitignore New script used to automatically generate SSL certificate files 2017-11-11 17:10:22 +08:00
CMakeLists.txt Restructure with libubox 2017-12-29 14:40:58 +08:00
CONTRIBUTING.md Update CONTRIBUTING 2017-12-29 14:54:34 +08:00
CONTRIBUTING_ZH.md Update CONTRIBUTING 2017-12-29 14:54:34 +08:00
LICENSE Initial commit 2017-11-04 17:30:20 +08:00
README.md Update README 2017-12-29 14:48:59 +08:00
README_ZH.md Update README 2017-12-29 14:48:59 +08:00
gen_cert.sh New script used to automatically generate SSL certificate files 2017-11-11 17:10:22 +08:00
openssl.cnf New script used to automatically generate SSL certificate files 2017-11-11 17:10:22 +08:00

README.md

libuhttpd(中文)

A very tiny and fast HTTP server library based on libubox and referenced from uhttpd for Embedded Linux.

Keep Watching for More Actions on This Space

Features

  • tiny and fast
  • use libubox as its event backend
  • support HTTPS: OpenSSL, mbedtls and CyaSSl(wolfssl)
  • flexible and you can easily extend your application to have HTTP/HTTPS services
  • code structure is concise and understandable, also suitable for learning

Dependencies

Configure

See which configuration are supported

~/libuhttpd/build$ cmake .. -L
~/libuhttpd/build$ cmake .. -LH

Run the Example

First generate the SSL certificate file

~/libuhttpd/build$ cd ..
~/libuhttpd$ ./gen_cert.sh

Run

~/libuhttpd$ ./build/example/helloworld

Then use the command curl or browser to test

$ curl -k 'https://127.0.0.1:8000/hello?name=test' -v

Example

#include <uhttpd.h>

#define port "8000"

static void hello_action(struct uh_client *cl)
{
    cl->send_header(cl, 200, "OK", -1);
    cl->append_header(cl, "Myheader", "Hello");
    cl->header_end(cl);

    cl->chunk_printf(cl, "<h1>Hello Libuhttpd %s</h1>", UHTTPD_VERSION_STRING);
    cl->chunk_printf(cl, "<h1>REMOTE_ADDR: %s</h1>", cl->get_peer_addr(cl));
    cl->chunk_printf(cl, "<h1>PATH: %s</h1>", cl->get_path(cl));
    cl->chunk_printf(cl, "<h1>QUERY: %s</h1>", cl->get_query(cl));
    cl->request_done(cl);
}

int main(int argc, char **argv)
{
    struct uh_server *srv = NULL;
    
    uh_log_debug("libuhttpd version: %s", UHTTPD_VERSION_STRING);

    uloop_init();

    srv = uh_server_new("0.0.0.0", port);
    if (!srv)
        goto done;

    uh_log_debug("Listen on: *:%s", port);

#if (UHTTPD_SSL_SUPPORT)
    if (srv->ssl_init(srv, "server-key.pem", "server-cert.pem") < 0)
        goto done;
#endif

    uh_add_action(srv, "/hello", hello_action);
    
    uloop_run();
done:
    uloop_done();
    srv->free(srv);
    
    return 0;
}

Contributing

If you would like to help making libuhttpd better, see the CONTRIBUTING.md file.