From 5b436e2304529407b5945224a318605ef45139a3 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 23 Dec 2011 15:28:00 +0000 Subject: [PATCH] added a mime type handler to the sample httpd program --- qse/samples/net/http01.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qse/samples/net/http01.c b/qse/samples/net/http01.c index b1cac759..39abec2f 100644 --- a/qse/samples/net/http01.c +++ b/qse/samples/net/http01.c @@ -133,6 +133,15 @@ static int handle_expect_continue ( return xtn->orgcbs->handle_expect_continue (httpd, client, req); } +const qse_mchar_t* get_mime_type (qse_httpd_t* httpd, const qse_mchar_t* path) +{ + if (qse_mbsend (path, QSE_MT(".html"))) return QSE_MT("text/html"); + if (qse_mbsend (path, QSE_MT(".txt"))) return QSE_MT("text/plain"); + if (qse_mbsend (path, QSE_MT(".jpg"))) return QSE_MT("image/jpeg"); + if (qse_mbsend (path, QSE_MT(".mp4"))) return QSE_MT("video/mp4"); + return QSE_NULL; +} + static qse_httpd_t* httpd = NULL; static void sigint (int sig) @@ -142,7 +151,7 @@ static void sigint (int sig) static qse_httpd_cbs_t httpd_cbs = { - { QSE_NULL }, + { get_mime_type, QSE_NULL, }, handle_request, handle_expect_continue };