From 5502aff768e5cbc3bbd05e067bc0dfc456770f86 Mon Sep 17 00:00:00 2001 From: m0gg Date: Mon, 1 Jan 2007 22:54:46 +0000 Subject: Header parsing error solved --- examples/nanohttp/http_server.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'examples/nanohttp') diff --git a/examples/nanohttp/http_server.c b/examples/nanohttp/http_server.c index a00c982..052aec1 100644 --- a/examples/nanohttp/http_server.c +++ b/examples/nanohttp/http_server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: http_server.c,v 1.12 2006/12/10 12:23:45 m0gg Exp $ +* $Id: http_server.c,v 1.13 2007/01/01 22:54:46 m0gg Exp $ * * CSOAP Project: A http client/server library in C (example) * Copyright (C) 2003 Ferhat Ayaz @@ -22,6 +22,7 @@ * Email: hero@persua.de ******************************************************************/ #include +#include #include #include @@ -63,29 +64,20 @@ static void secure_service(httpd_conn_t *conn, struct hrequest_t *req) static void default_service(httpd_conn_t *conn, struct hrequest_t *req) { - httpd_send_header(conn, 404, HTTP_STATUS_404_REASON_PHRASE); - http_output_stream_write_string(conn->out, - "" - "" - "Default error page" - "" - "" - "

Default error page

" - "
"); + char buf[512]; - http_output_stream_write_string(conn->out, req->path); + snprintf(buf, 512, "Resource \"%s\" not found", req->path); - http_output_stream_write_string(conn->out, " cannot be found" - "
" - "" - ""); + httpd_send_not_found(conn, buf); return; -} +} static void headers_service(httpd_conn_t *conn, struct hrequest_t *req) { hpair_t *walker; + char buf[512]; + int len; httpd_send_header(conn, 200, HTTP_STATUS_200_REASON_PHRASE); http_output_stream_write_string(conn->out, @@ -99,11 +91,8 @@ static void headers_service(httpd_conn_t *conn, struct hrequest_t *req) for (walker=req->header; walker; walker=walker->next) { - http_output_stream_write_string(conn->out, "
  • "); - http_output_stream_write_string(conn->out, walker->key); - http_output_stream_write_string(conn->out, " = "); - http_output_stream_write_string(conn->out, walker->value); - http_output_stream_write_string(conn->out, "
  • "); + len = snprintf(buf, 512, "
  • %s: %s
  • ", walker->key, walker->value); + http_output_stream_write(conn->out, buf, len); } http_output_stream_write_string(conn->out, -- cgit v1.1-32-gdbae