lookup content type only when needed

This commit is contained in:
Niclas Finne 2012-05-29 19:28:14 +02:00
parent a95c2cf6c1
commit 0d6dabe6f5
2 changed files with 30 additions and 20 deletions

View File

@ -103,16 +103,11 @@ PT_THREAD(send_string(struct httpd_state *s, const char *str))
PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
static const char *
get_content_type(const char *filename)
{
static const char *ptr;
PSOCK_BEGIN(&s->sout);
SEND_STRING(&s->sout, statushdr);
ptr = strrchr(s->filename, ISO_period);
const char *ptr;
ptr = strrchr(filename, ISO_period);
if(ptr == NULL) {
ptr = http_content_type_plain;
} else if(strcmp(http_htm, ptr) == 0) {
@ -128,7 +123,17 @@ PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
} else {
ptr = http_content_type_binary;
}
SEND_STRING(&s->sout, ptr);
return ptr;
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
{
PSOCK_BEGIN(&s->sout);
SEND_STRING(&s->sout, statushdr);
SEND_STRING(&s->sout, get_content_type(s->filename));
PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/

View File

@ -103,16 +103,11 @@ PT_THREAD(send_string(struct httpd_state *s, const char *str))
PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
static const char *
get_content_type(const char *filename)
{
static const char *ptr;
PSOCK_BEGIN(&s->sout);
SEND_STRING(&s->sout, statushdr);
ptr = strrchr(s->filename, ISO_period);
const char *ptr;
ptr = strrchr(filename, ISO_period);
if(ptr == NULL) {
ptr = http_content_type_plain;
} else if(strcmp(http_htm, ptr) == 0) {
@ -128,7 +123,17 @@ PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
} else {
ptr = http_content_type_binary;
}
SEND_STRING(&s->sout, ptr);
return ptr;
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
{
PSOCK_BEGIN(&s->sout);
SEND_STRING(&s->sout, statushdr);
SEND_STRING(&s->sout, get_content_type(s->filename));
PSOCK_END(&s->sout);
}
/*---------------------------------------------------------------------------*/