Commit 5e0e8697 authored by Rafaël Carré's avatar Rafaël Carré

httpd: simplify httpd_ReasonFromCode

parent d2f69bc3
......@@ -177,14 +177,16 @@ struct httpd_client_t
/*****************************************************************************
* Various functions
*****************************************************************************/
typedef struct
static const char *httpd_ReasonFromCode( unsigned i_code )
{
typedef struct
{
unsigned i_code;
const char psz_reason[36];
} http_status_info;
} http_status_info;
static const http_status_info http_reason[] =
{
static const http_status_info http_reason[] =
{
/*{ 100, "Continue" },
{ 101, "Switching Protocols" },*/
{ 200, "OK" },
......@@ -240,26 +242,24 @@ static const http_status_info http_reason[] =
{ 505, "Protocol version not supported" },
{ 551, "Option not supported" },
{ 999, "" }
};
};
static const char psz_fallback_reason[5][16] =
{ "Continue", "OK", "Found", "Client error", "Server error" };
static const char *httpd_ReasonFromCode( unsigned i_code )
{
const http_status_info *p;
static const char psz_fallback_reason[5][16] = {
"Continue", "OK", "Found", "Client error", "Server error"
};
assert( ( i_code >= 100 ) && ( i_code <= 599 ) );
for (p = http_reason; i_code > p->i_code; p++);
const http_status_info *p = http_reason;
while (i_code < p->i_code)
p++;
if( p->i_code == i_code )
if (p->i_code == i_code)
return p->psz_reason;
return psz_fallback_reason[(i_code / 100) - 1];
}
static size_t httpd_HtmlError (char **body, int code, const char *url)
{
const char *errname = httpd_ReasonFromCode (code);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment