From c9b80e466faa4d8849cf46d18dabb5bfa8496d0e Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Thu, 19 Oct 2006 07:21:55 +0000 Subject: [PATCH] updates. --- lib/silchttp/tests/test_silchttpserver.c | 37 +++++++++++++++++------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/silchttp/tests/test_silchttpserver.c b/lib/silchttp/tests/test_silchttpserver.c index 76604b88..197e5deb 100644 --- a/lib/silchttp/tests/test_silchttpserver.c +++ b/lib/silchttp/tests/test_silchttpserver.c @@ -12,6 +12,30 @@ char *htdocs = "."; +/* Add proper content type to reply per URI */ + +static void http_content_type(SilcHttpServer httpd, SilcHttpConnection conn, + const char *uri) +{ + const char *type; + + type = silc_http_server_get_header(httpd, conn, "Content-Type"); + if (type) + silc_http_server_add_header(httpd, conn, "Content-Type", type); + else if (strstr(uri, ".jpg")) + silc_http_server_add_header(httpd, conn, "Content-Type", "image/jpeg"); + else if (strstr(uri, ".gif")) + silc_http_server_add_header(httpd, conn, "Content-Type", "image/gif"); + else if (strstr(uri, ".png")) + silc_http_server_add_header(httpd, conn, "Content-Type", "image/png"); + else if (strstr(uri, ".css")) + silc_http_server_add_header(httpd, conn, "Content-Type", "text/css"); + else if (strstr(uri, ".htm")) + silc_http_server_add_header(httpd, conn, "Content-Type", "text/html"); + else if (strstr(uri, ".php")) + silc_http_server_add_header(httpd, conn, "Content-Type", "text/html"); +} + /* Serve pages */ static void http_callback_file(SilcHttpServer httpd, SilcHttpConnection conn, @@ -22,7 +46,6 @@ static void http_callback_file(SilcHttpServer httpd, SilcHttpConnection conn, SilcBuffer php; char *filedata, filename[256]; SilcUInt32 data_len; - const char *type; SilcBool usephp = FALSE; if (!strcasecmp(method, "GET")) { @@ -49,15 +72,7 @@ static void http_callback_file(SilcHttpServer httpd, SilcHttpConnection conn, return; } - type = silc_http_server_get_header(httpd, conn, "Content-Type"); - if (type) - silc_http_server_add_header(httpd, conn, "Content-Type", type); - else if (strstr(uri, ".jpg")) - silc_http_server_add_header(httpd, conn, "Content-Type", "image/jpeg"); - else if (strstr(uri, ".gif")) - silc_http_server_add_header(httpd, conn, "Content-Type", "image/gif"); - else if (strstr(uri, ".png")) - silc_http_server_add_header(httpd, conn, "Content-Type", "image/png"); + http_content_type(httpd, conn, uri); /* Send page */ silc_buffer_set(&page, filedata, data_len); @@ -71,6 +86,8 @@ static void http_callback_file(SilcHttpServer httpd, SilcHttpConnection conn, return; } + http_content_type(httpd, conn, uri); + /* Send page */ silc_http_server_send(httpd, conn, php); silc_buffer_free(php); -- 2.24.0