2017-11-30 00:46:38 +00:00
|
|
|
# libuhttp([中文](https://github.com/zhaojh329/libuhttp/blob/master/README_ZH.md))
|
2017-11-09 04:54:28 +00:00
|
|
|
|
|
|
|
![](https://img.shields.io/badge/license-GPLV3-brightgreen.svg?style=plastic "License")
|
|
|
|
|
2017-11-12 08:28:09 +00:00
|
|
|
[libev]: http://software.schmorp.de/pkg/libev.html
|
|
|
|
[http-parser]: https://github.com/nodejs/http-parser
|
|
|
|
|
|
|
|
A very tiny and fast HTTP library based on [libev] and [http-parser] for Embedded Linux.
|
2017-11-14 02:41:42 +00:00
|
|
|
Support HTTPS(alternative OpenSSL and CyaSSl(wolfssl)) and if you're sensitive to size,
|
|
|
|
you can choose CyaSSl(wolfssl).
|
2017-11-09 05:29:10 +00:00
|
|
|
|
2017-11-11 11:06:51 +00:00
|
|
|
`Keep Watching for More Actions on This Space`
|
|
|
|
|
2017-11-10 11:16:47 +00:00
|
|
|
# Features
|
2017-11-12 08:28:09 +00:00
|
|
|
* tiny and fast
|
2017-11-29 23:57:56 +00:00
|
|
|
* use [libev] as its event backend
|
|
|
|
* support HTTPS: alternative OpenSSL and CyaSSl(wolfssl)
|
2017-11-12 08:28:09 +00:00
|
|
|
* flexible and you can easily extend your application to have HTTP/HTTPS services
|
2017-11-29 23:57:56 +00:00
|
|
|
* support embedding LUA code into HTML code, like embedding PHP to HTML(soon be supported)
|
2017-11-15 05:21:02 +00:00
|
|
|
* code structure is concise and understandable, also suitable for learning
|
2017-11-12 08:28:09 +00:00
|
|
|
|
|
|
|
# Why use [libev] as its backend?
|
|
|
|
[libev] tries to do one thing only (POSIX event library), and this in the most efficient way possible.
|
|
|
|
Libevent tries to give you the full solution (event lib, non-blocking I/O library, http server, DNS client).
|
|
|
|
|
|
|
|
[libev] tries to follow the UNIX toolbox philosophy of doing one thing only, as good as possible.
|
2017-11-10 11:16:47 +00:00
|
|
|
|
2017-11-13 08:34:48 +00:00
|
|
|
# How to Build
|
2017-11-09 05:29:10 +00:00
|
|
|
## Install dependency Tools and Libraries
|
2017-11-13 08:34:48 +00:00
|
|
|
Ubuntu
|
2017-11-12 08:28:09 +00:00
|
|
|
|
2017-11-22 06:11:31 +00:00
|
|
|
~$ sudo apt install gcc cmake libev-dev libssl-dev libwolfssl-dev
|
2017-11-13 08:34:48 +00:00
|
|
|
|
|
|
|
CentOS
|
|
|
|
|
2017-11-22 06:11:31 +00:00
|
|
|
~$ sudo yum install gcc cmake libev-devel openssl-devel
|
2017-11-12 08:28:09 +00:00
|
|
|
|
|
|
|
## Clone the repository
|
|
|
|
|
|
|
|
~$ git clone https://github.com/zhaojh329/libuhttp.git
|
|
|
|
~$ cd libuhttp
|
|
|
|
|
|
|
|
## Create the build directory
|
|
|
|
|
|
|
|
~/libuhttp$ mkdir build
|
|
|
|
~/libuhttp$ cd build
|
|
|
|
|
|
|
|
## Configure
|
|
|
|
See which configuration are supported
|
|
|
|
|
2017-11-13 13:01:17 +00:00
|
|
|
~/libuhttp/build$ cmake .. -L
|
2017-11-12 08:28:09 +00:00
|
|
|
~/libuhttp/build$ cmake .. -LH
|
|
|
|
|
2017-11-30 00:46:38 +00:00
|
|
|
Default configure: automatically select the SSL library as its SSL backend(If there is a SSL library available)
|
2017-11-12 08:28:09 +00:00
|
|
|
|
|
|
|
~/libuhttp/build$ cmake ..
|
|
|
|
|
|
|
|
Disable SSl support
|
|
|
|
|
|
|
|
~/libuhttp/build$ cmake .. -DUHTTP_DISABLE_SSL=1
|
|
|
|
|
|
|
|
Explicit use OpenSSL as its SSL backend
|
|
|
|
|
|
|
|
~/libuhttp/build$ cmake .. -DUHTTP_USE_OPENSSL=1
|
|
|
|
|
|
|
|
Explicit use CyaSSl(wolfssl) as its SSL backend
|
|
|
|
|
|
|
|
~/libuhttp/build$ cmake .. -DUHTTP_USE_CYASSL=1
|
2017-11-12 09:43:05 +00:00
|
|
|
|
|
|
|
Turn on debug
|
|
|
|
|
|
|
|
~/libuhttp/build$ cmake .. -DUHTTP_DEBUG=1
|
2017-11-09 05:29:10 +00:00
|
|
|
|
2017-11-12 08:28:09 +00:00
|
|
|
## Build and install libuhttp
|
|
|
|
|
|
|
|
~/libuhttp/build$ make && sudo make install
|
|
|
|
|
|
|
|
## Run the Example
|
|
|
|
First generate the SSL certificate file
|
|
|
|
|
|
|
|
~/libuhttp/build$ cd ..
|
|
|
|
~/libuhttp$ ./gen_cert.sh
|
2017-11-10 11:16:47 +00:00
|
|
|
|
2017-11-12 08:28:09 +00:00
|
|
|
Run
|
|
|
|
|
|
|
|
~/libuhttp$ ./build/example/helloworld
|
|
|
|
|
2017-11-14 14:16:26 +00:00
|
|
|
Then use the command curl or browser to test
|
2017-11-12 08:28:09 +00:00
|
|
|
|
2017-11-14 14:16:26 +00:00
|
|
|
$ curl -k 'https://127.0.0.1:8000/test?name=context%3d%7b"nid"%3a"test"%7d' -v
|
|
|
|
|
|
|
|
If use browser to test, it will be show
|
|
|
|
|
|
|
|
Hello World
|
|
|
|
Libuhttp v0.1
|
|
|
|
Url: /test?name=context%3d%7b%22nid%22%3a%22test%22%7d
|
|
|
|
Path: /test
|
|
|
|
Name: context%3d%7b%22nid%22%3a%22test%22%7d
|
|
|
|
Unescaped Name: context={"nid":"test"}
|
|
|
|
Host: 192.168.0.100:8000
|
|
|
|
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
|
2017-11-10 11:16:47 +00:00
|
|
|
|
|
|
|
# [Example](https://github.com/zhaojh329/libuhttp/blob/master/example/helloworld.c)
|
|
|
|
|
|
|
|
# Contributing
|
2017-11-10 11:19:26 +00:00
|
|
|
If you would like to help making [libuhttp](https://github.com/zhaojh329/libuhttp) better,
|
|
|
|
see the [CONTRIBUTING.md](https://github.com/zhaojh329/libuhttp/blob/master/CONTRIBUTING.md) file.
|
2017-11-10 11:16:47 +00:00
|
|
|
|
|
|
|
# Thanks for the following project
|
2017-11-12 08:28:09 +00:00
|
|
|
* [libev]
|
|
|
|
* [http-parser]
|
2017-11-27 05:18:59 +00:00
|
|
|
* [mongoose](https://github.com/cesanta/mongoose)
|