Commit 3ddc5c03 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

Initial commit

parents
*.pyc
*.pyo
*.c
*.h
*.so
/build/
/dist/
!interface.c
.PHONY: all cython_module run
all: cython_module
cython_module:
python3 setup.py build_ext --inplace
run: cython_module
export LD_LIBRARY_PATH=/usr/local/lib; python3 -c "import lwan; lwan.run()"
#include <lwan/lwan.h>
extern int handle_root(struct lwan_request *request, struct lwan_response *response);
LWAN_HANDLER(root)
{
return handle_root(request, response);
}
static int listen_and_serve(void)
{
const struct lwan_url_map default_map[] = {
{ .prefix = "/", .handler = LWAN_HANDLER_REF(root) },
{ .prefix = NULL }
};
struct lwan l;
lwan_init(&l);
lwan_set_url_map(&l, default_map);
lwan_main_loop(&l);
lwan_shutdown(&l);
return 0;
}
from libc.string cimport strlen
cdef extern from "lwan/lwan.h":
struct lwan_strbuf:
pass
struct lwan_value:
char* value
struct lwan_request:
lwan_value original_url
struct lwan_response:
char *mime_type
lwan_strbuf *buffer
enum lwan_http_status:
HTTP_OK
cdef extern from "lwan/lwan-strbuf.h":
struct lwan_strbuf:
pass
bint lwan_strbuf_set_static(lwan_strbuf *s1, const char *s2, size_t sz) nogil
cdef extern from "interface.c":
int listen_and_serve() nogil
def run():
with nogil:
listen_and_serve()
cdef public int handle_root(lwan_request *request, lwan_response *response) nogil:
cdef char *message = "Hello, World!"
response.mime_type = "text/plain"
lwan_strbuf_set_static(response.buffer, message, strlen(message))
return HTTP_OK
# Timeout in seconds to keep a connection alive.
keep_alive_timeout = 15
# Set to true to not print any debugging messages. (Only effective in
# release builds.)
quiet = false
# Set SO_REUSEPORT=1 in the master socket.
reuse_port = false
# Value of "Expires" header. Default is 1 month and 1 week.
expires = 1M 1w
# Number of I/O threads. Default (0) is number of online CPUs.
threads = 0
# Disable HAProxy's PROXY protocol by default. Only enable if needed.
proxy_protocol = false
listener *:8080 {
serve_files / {
path = ./wwwroot
# When requesting for file.ext, look for a smaller/newer file.ext.gz,
# and serve that instead if `Accept-Encoding: gzip` is in the
# request headers.
serve precompressed files = true
}
}
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
setup(
ext_modules = cythonize([
Extension("lwan",
sources=["lwan_wrapper.pyx", "interface.c"],
libraries=["lwan"],
)
])
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment