Commit c7fa14b2 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

Add /fibonacci handler

parent 4aa9ad4d
#include <lwan/lwan.h>
extern int handle_root(struct lwan_request *request, struct lwan_response *response);
extern int handle_fibonacci(struct lwan_request *request, struct lwan_response *response);
LWAN_HANDLER(root)
{
return handle_root(request, response);
}
LWAN_HANDLER(fibonacci)
{
return handle_fibonacci(request, response);
}
static int listen_and_serve(void)
{
const struct lwan_url_map default_map[] = {
{ .prefix = "/", .handler = LWAN_HANDLER_REF(root) },
{ .prefix = "/fibonacci", .handler = LWAN_HANDLER_REF(fibonacci) },
{ .prefix = NULL }
};
struct lwan l;
......
......@@ -19,6 +19,7 @@ cdef extern from "lwan/lwan-strbuf.h":
pass
bint lwan_strbuf_set_static(lwan_strbuf *s1, const char *s2, size_t sz) nogil
bint lwan_strbuf_printf(lwan_strbuf *s, const char *fmt, ...) nogil
cdef extern from "interface.c":
int listen_and_serve() nogil
......@@ -34,3 +35,19 @@ cdef public int handle_root(lwan_request *request, lwan_response *response) nogi
lwan_strbuf_set_static(response.buffer, message, strlen(message))
return HTTP_OK
cdef unsigned int fibonacci(unsigned int n) nogil:
cdef unsigned int i, a, b
a, b = 0, 1
for i in range(n):
a, b = b, a + b
return a
cdef public int handle_fibonacci(lwan_request *request, lwan_response *response) nogil:
response.mime_type = "text/plain"
lwan_strbuf_printf(response.buffer, "Fibonacci(10^6) = %u (with overflow)\n", fibonacci(1000000))
return HTTP_OK
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