Update http_static

This commit is contained in:
2023-01-07 00:20:42 +01:00
parent fb59b0d8c4
commit 99c4eb1c8a
4 changed files with 52 additions and 46 deletions

View File

@ -39,6 +39,12 @@
#define CLIENT_MAX_HEADER_SIZE 8192
#define HTTP_INIT_HEADER_FIELD_NUM 16
#define HTTP_TYPE_INFORMATIONAL 1
#define HTTP_TYPE_SUCCESS 2
#define HTTP_TYPE_REDIRECTION 3
#define HTTP_TYPE_CLIENT_ERROR 4
#define HTTP_TYPE_SERVER_ERROR 5
#ifndef SERVER_STR
# define SERVER_STR "sesimos"
#endif
@ -48,13 +54,13 @@
#endif
typedef struct {
unsigned short code;
char type[16];
unsigned short code:10;
unsigned char type:3;
char msg[64];
} http_status;
typedef struct {
unsigned short code;
unsigned short code:10;
const char *msg;
} http_status_msg;

View File

@ -9,51 +9,51 @@
#include "http.h"
const http_status http_statuses[] = {
{100, "Informational", "Continue"},
{101, "Informational", "Switching Protocols"},
{100, HTTP_TYPE_INFORMATIONAL, "Continue"},
{101, HTTP_TYPE_INFORMATIONAL, "Switching Protocols"},
{200, "Success", "OK"},
{201, "Success", "Created"},
{202, "Success", "Accepted"},
{203, "Success", "Non-Authoritative Information"},
{204, "Success", "No Content"},
{205, "Success", "Reset Content"},
{206, "Success", "Partial Content"},
{200, HTTP_TYPE_SUCCESS, "OK"},
{201, HTTP_TYPE_SUCCESS, "Created"},
{202, HTTP_TYPE_SUCCESS, "Accepted"},
{203, HTTP_TYPE_SUCCESS, "Non-Authoritative Information"},
{204, HTTP_TYPE_SUCCESS, "No Content"},
{205, HTTP_TYPE_SUCCESS, "Reset Content"},
{206, HTTP_TYPE_SUCCESS, "Partial Content"},
{300, "Redirection", "Multiple Choices"},
{301, "Redirection", "Moved Permanently"},
{302, "Redirection", "Found"},
{303, "Redirection", "See Other"},
{304, "Success", "Not Modified"},
{305, "Redirection", "Use Proxy"},
{307, "Redirection", "Temporary Redirect"},
{308, "Redirection", "Permanent Redirect"},
{300, HTTP_TYPE_REDIRECTION, "Multiple Choices"},
{301, HTTP_TYPE_REDIRECTION, "Moved Permanently"},
{302, HTTP_TYPE_REDIRECTION, "Found"},
{303, HTTP_TYPE_REDIRECTION, "See Other"},
{304, HTTP_TYPE_SUCCESS, "Not Modified"},
{305, HTTP_TYPE_REDIRECTION, "Use Proxy"},
{307, HTTP_TYPE_REDIRECTION, "Temporary Redirect"},
{308, HTTP_TYPE_REDIRECTION, "Permanent Redirect"},
{400, "Client Error", "Bad Request"},
{401, "Client Error", "Unauthorized"},
{402, "Client Error", "Payment Required"},
{403, "Client Error", "Forbidden"},
{404, "Client Error", "Not Found"},
{405, "Client Error", "Method Not Allowed"},
{406, "Client Error", "Not Acceptable"},
{407, "Client Error", "Proxy Authentication Required"},
{408, "Client Error", "Request Timeout"},
{409, "Client Error", "Conflict"},
{410, "Client Error", "Gone"},
{411, "Client Error", "Length Required"},
{412, "Client Error", "Precondition Failed"},
{413, "Client Error", "Request Entity Too Large"},
{414, "Client Error", "Request-URI Too Long"},
{415, "Client Error", "Unsupported Media Type"},
{416, "Client Error", "Range Not Satisfiable"},
{417, "Client Error", "Expectation Failed"},
{400, HTTP_TYPE_CLIENT_ERROR, "Bad Request"},
{401, HTTP_TYPE_CLIENT_ERROR, "Unauthorized"},
{402, HTTP_TYPE_CLIENT_ERROR, "Payment Required"},
{403, HTTP_TYPE_CLIENT_ERROR, "Forbidden"},
{404, HTTP_TYPE_CLIENT_ERROR, "Not Found"},
{405, HTTP_TYPE_CLIENT_ERROR, "Method Not Allowed"},
{406, HTTP_TYPE_CLIENT_ERROR, "Not Acceptable"},
{407, HTTP_TYPE_CLIENT_ERROR, "Proxy Authentication Required"},
{408, HTTP_TYPE_CLIENT_ERROR, "Request Timeout"},
{409, HTTP_TYPE_CLIENT_ERROR, "Conflict"},
{410, HTTP_TYPE_CLIENT_ERROR, "Gone"},
{411, HTTP_TYPE_CLIENT_ERROR, "Length Required"},
{412, HTTP_TYPE_CLIENT_ERROR, "Precondition Failed"},
{413, HTTP_TYPE_CLIENT_ERROR, "Request Entity Too Large"},
{414, HTTP_TYPE_CLIENT_ERROR, "Request-URI Too Long"},
{415, HTTP_TYPE_CLIENT_ERROR, "Unsupported Media Type"},
{416, HTTP_TYPE_CLIENT_ERROR, "Range Not Satisfiable"},
{417, HTTP_TYPE_CLIENT_ERROR, "Expectation Failed"},
{500, "Server Error", "Internal Server Error"},
{501, "Server Error", "Not Implemented"},
{502, "Server Error", "Bad Gateway"},
{503, "Server Error", "Service Unavailable"},
{504, "Server Error", "Gateway Timeout"},
{505, "Server Error", "HTTP Version Not Supported"},
{500, HTTP_TYPE_SERVER_ERROR, "Internal Server Error"},
{501, HTTP_TYPE_SERVER_ERROR, "Not Implemented"},
{502, HTTP_TYPE_SERVER_ERROR, "Bad Gateway"},
{503, HTTP_TYPE_SERVER_ERROR, "Service Unavailable"},
{504, HTTP_TYPE_SERVER_ERROR, "Gateway Timeout"},
{505, HTTP_TYPE_SERVER_ERROR, "HTTP Version Not Supported"},
};
const http_status_msg http_status_messages[] = {

View File

@ -524,7 +524,7 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
res->status = http_get_status(status_code);
if (res->status == NULL && status_code >= 100 && status_code <= 999) {
custom_status->code = status_code;
strcpy(custom_status->type, "");
custom_status->type = 0;
snprintf(custom_status->msg, sizeof(custom_status->msg), "%.*s",
(int) (strchr(ptr, '\r') - ptr - 13), ptr + 13);
res->status = custom_status;

View File

@ -101,7 +101,7 @@ static int fastcgi_handler_1(client_ctx_t *ctx, fastcgi_cnx_t *fcgi_cnx) {
http_remove_header_field(&res->hdr, "Status", HTTP_REMOVE_ALL);
if (res->status == NULL && status_code >= 100 && status_code <= 999) {
ctx->custom_status.code = status_code;
strcpy(ctx->custom_status.type, "");
ctx->custom_status.type = 0;
strcpy(ctx->custom_status.msg, status_hdr + 4);
res->status = &ctx->custom_status;
} else if (res->status == NULL) {