X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilchttp%2Ftests%2Ftest_silchttpserver.c;h=cb9050b14f93a6c09b1595de03c7a815e3417ca6;hp=76604b8810be61412d21262ed6877942286eff09;hb=08e0dddd6750b245da53e2bc3528d0b5a6d57e8b;hpb=7df5e78201d7eb15ff5ecdc378af70d7d1ea1453 diff --git a/lib/silchttp/tests/test_silchttpserver.c b/lib/silchttp/tests/test_silchttpserver.c index 76604b88..cb9050b1 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")) { @@ -42,22 +65,14 @@ static void http_callback_file(SilcHttpServer httpd, SilcHttpConnection conn, SILC_LOG_DEBUG(("Filename: '%s'", filename)); if (!usephp) { - filedata = silc_file_readfile(filename, &data_len); + filedata = silc_file_readfile(filename, &data_len, NULL); if (!filedata) { silc_http_server_send_error(httpd, conn, "404 Not Found", "

404 Not Found

The page you are looking for cannot be located"); 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); @@ -104,7 +121,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); SILC_LOG_DEBUG(("Allocating scheduler")); - schedule = silc_schedule_init(0, NULL); + schedule = silc_schedule_init(0, NULL, NULL); if (!schedule) goto err;