summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-06 00:13:28 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-06 00:13:28 +0000
commitd9f5cb7a28ee79e299e41d3ce325171f01e1a3d7 (patch)
treec13af66675cbd2ed3de340ab139297e4dcdbd199
parent8d66c8c5cac310958fa64e3f62b828ea960202ba (diff)
downloadtipidee-d9f5cb7a28ee79e299e41d3ce325171f01e1a3d7.tar.xz
Some fixes, preparation for changes in error responses
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--doc/index.html2
-rw-r--r--package/deps.mak7
-rw-r--r--src/include/tipidee/util.h9
-rw-r--r--src/libtipidee/deps-lib/tipidee1
-rw-r--r--src/libtipidee/tipidee_util_defaulttext.c59
-rw-r--r--src/tipideed/cgi.c5
-rw-r--r--src/tipideed/tipideed.c4
7 files changed, 80 insertions, 7 deletions
diff --git a/doc/index.html b/doc/index.html
index da7aa73..bda2237 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -80,7 +80,7 @@ on what I want from a web server, which is:
<ul>
<li> Usability with HTTPS without the need to entangle the code with a
-given TLS library (which means delegating the TLS layer to a super-server
+given TLS library &mdash; which means delegating the TLS layer to a super-server
and not performing the socket work itself. This is important: tying your
Web server to a TLS library makes it more difficult to maintain, more
difficult to secure, more difficult to build, and more difficult to
diff --git a/package/deps.mak b/package/deps.mak
index 854c476..88dbd44 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -38,6 +38,7 @@ src/libtipidee/tipidee_response_status.o src/libtipidee/tipidee_response_status.
src/libtipidee/tipidee_rql_read.o src/libtipidee/tipidee_rql_read.lo: src/libtipidee/tipidee_rql_read.c src/include/tipidee/method.h src/include/tipidee/rql.h src/include/tipidee/uri.h
src/libtipidee/tipidee_uri_parse.o src/libtipidee/tipidee_uri_parse.lo: src/libtipidee/tipidee_uri_parse.c src/include/tipidee/uri.h
src/libtipidee/tipidee_util_chunked_read.o src/libtipidee/tipidee_util_chunked_read.lo: src/libtipidee/tipidee_util_chunked_read.c src/include/tipidee/util.h
+src/libtipidee/tipidee_util_defaulttext.o src/libtipidee/tipidee_util_defaulttext.lo: src/libtipidee/tipidee_util_defaulttext.c src/include/tipidee/util.h
src/libtipidee/tipidee_util_httpdate.o src/libtipidee/tipidee_util_httpdate.lo: src/libtipidee/tipidee_util_httpdate.c src/include/tipidee/util.h
src/tipideed/cgi.o src/tipideed/cgi.lo: src/tipideed/cgi.c src/include/tipidee/headers.h src/include/tipidee/method.h src/include/tipidee/response.h src/include/tipidee/uri.h src/tipideed/tipideed-internal.h
src/tipideed/harden.o src/tipideed/harden.lo: src/tipideed/harden.c src/tipideed/tipideed-internal.h
@@ -54,12 +55,12 @@ tipidee-config: src/config/tipidee-config.o src/config/confnode.o src/config/con
tipidee-config-preprocess: EXTRA_LIBS := -lskarnet
tipidee-config-preprocess: src/config/tipidee-config-preprocess.o
ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
-libtipidee.a.xyzzy: src/libtipidee/tipidee_conf_free.o src/libtipidee/tipidee_conf_get.o src/libtipidee/tipidee_conf_get_argv.o src/libtipidee/tipidee_conf_get_content_type.o src/libtipidee/tipidee_conf_get_redirection.o src/libtipidee/tipidee_conf_get_string.o src/libtipidee/tipidee_conf_get_uint32.o src/libtipidee/tipidee_conf_init.o src/libtipidee/tipidee_headers_get_content_length.o src/libtipidee/tipidee_headers_init.o src/libtipidee/tipidee_headers_parse.o src/libtipidee/tipidee_headers_search.o src/libtipidee/tipidee_method_conv_table.o src/libtipidee/tipidee_method_tonum.o src/libtipidee/tipidee_method_tostr.o src/libtipidee/tipidee_response_error.o src/libtipidee/tipidee_response_header_builtin.o src/libtipidee/tipidee_response_header_common_put.o src/libtipidee/tipidee_response_header_date.o src/libtipidee/tipidee_response_header_date_fmt.o src/libtipidee/tipidee_response_header_lastmodified.o src/libtipidee/tipidee_response_status.o src/libtipidee/tipidee_rql_read.o src/libtipidee/tipidee_uri_parse.o src/libtipidee/tipidee_util_chunked_read.o src/libtipidee/tipidee_util_httpdate.o
+libtipidee.a.xyzzy: src/libtipidee/tipidee_conf_free.o src/libtipidee/tipidee_conf_get.o src/libtipidee/tipidee_conf_get_argv.o src/libtipidee/tipidee_conf_get_content_type.o src/libtipidee/tipidee_conf_get_redirection.o src/libtipidee/tipidee_conf_get_string.o src/libtipidee/tipidee_conf_get_uint32.o src/libtipidee/tipidee_conf_init.o src/libtipidee/tipidee_headers_get_content_length.o src/libtipidee/tipidee_headers_init.o src/libtipidee/tipidee_headers_parse.o src/libtipidee/tipidee_headers_search.o src/libtipidee/tipidee_method_conv_table.o src/libtipidee/tipidee_method_tonum.o src/libtipidee/tipidee_method_tostr.o src/libtipidee/tipidee_response_error.o src/libtipidee/tipidee_response_header_builtin.o src/libtipidee/tipidee_response_header_common_put.o src/libtipidee/tipidee_response_header_date.o src/libtipidee/tipidee_response_header_date_fmt.o src/libtipidee/tipidee_response_header_lastmodified.o src/libtipidee/tipidee_response_status.o src/libtipidee/tipidee_rql_read.o src/libtipidee/tipidee_uri_parse.o src/libtipidee/tipidee_util_chunked_read.o src/libtipidee/tipidee_util_defaulttext.o src/libtipidee/tipidee_util_httpdate.o
else
-libtipidee.a.xyzzy: src/libtipidee/tipidee_conf_free.lo src/libtipidee/tipidee_conf_get.lo src/libtipidee/tipidee_conf_get_argv.lo src/libtipidee/tipidee_conf_get_content_type.lo src/libtipidee/tipidee_conf_get_redirection.lo src/libtipidee/tipidee_conf_get_string.lo src/libtipidee/tipidee_conf_get_uint32.lo src/libtipidee/tipidee_conf_init.lo src/libtipidee/tipidee_headers_get_content_length.lo src/libtipidee/tipidee_headers_init.lo src/libtipidee/tipidee_headers_parse.lo src/libtipidee/tipidee_headers_search.lo src/libtipidee/tipidee_method_conv_table.lo src/libtipidee/tipidee_method_tonum.lo src/libtipidee/tipidee_method_tostr.lo src/libtipidee/tipidee_response_error.lo src/libtipidee/tipidee_response_header_builtin.lo src/libtipidee/tipidee_response_header_common_put.lo src/libtipidee/tipidee_response_header_date.lo src/libtipidee/tipidee_response_header_date_fmt.lo src/libtipidee/tipidee_response_header_lastmodified.lo src/libtipidee/tipidee_response_status.lo src/libtipidee/tipidee_rql_read.lo src/libtipidee/tipidee_uri_parse.lo src/libtipidee/tipidee_util_chunked_read.lo src/libtipidee/tipidee_util_httpdate.lo
+libtipidee.a.xyzzy: src/libtipidee/tipidee_conf_free.lo src/libtipidee/tipidee_conf_get.lo src/libtipidee/tipidee_conf_get_argv.lo src/libtipidee/tipidee_conf_get_content_type.lo src/libtipidee/tipidee_conf_get_redirection.lo src/libtipidee/tipidee_conf_get_string.lo src/libtipidee/tipidee_conf_get_uint32.lo src/libtipidee/tipidee_conf_init.lo src/libtipidee/tipidee_headers_get_content_length.lo src/libtipidee/tipidee_headers_init.lo src/libtipidee/tipidee_headers_parse.lo src/libtipidee/tipidee_headers_search.lo src/libtipidee/tipidee_method_conv_table.lo src/libtipidee/tipidee_method_tonum.lo src/libtipidee/tipidee_method_tostr.lo src/libtipidee/tipidee_response_error.lo src/libtipidee/tipidee_response_header_builtin.lo src/libtipidee/tipidee_response_header_common_put.lo src/libtipidee/tipidee_response_header_date.lo src/libtipidee/tipidee_response_header_date_fmt.lo src/libtipidee/tipidee_response_header_lastmodified.lo src/libtipidee/tipidee_response_status.lo src/libtipidee/tipidee_rql_read.lo src/libtipidee/tipidee_uri_parse.lo src/libtipidee/tipidee_util_chunked_read.lo src/libtipidee/tipidee_util_defaulttext.lo src/libtipidee/tipidee_util_httpdate.lo
endif
libtipidee.so.xyzzy: EXTRA_LIBS := -lskarnet
-libtipidee.so.xyzzy: src/libtipidee/tipidee_conf_free.lo src/libtipidee/tipidee_conf_get.lo src/libtipidee/tipidee_conf_get_argv.lo src/libtipidee/tipidee_conf_get_content_type.lo src/libtipidee/tipidee_conf_get_redirection.lo src/libtipidee/tipidee_conf_get_string.lo src/libtipidee/tipidee_conf_get_uint32.lo src/libtipidee/tipidee_conf_init.lo src/libtipidee/tipidee_headers_get_content_length.lo src/libtipidee/tipidee_headers_init.lo src/libtipidee/tipidee_headers_parse.lo src/libtipidee/tipidee_headers_search.lo src/libtipidee/tipidee_method_conv_table.lo src/libtipidee/tipidee_method_tonum.lo src/libtipidee/tipidee_method_tostr.lo src/libtipidee/tipidee_response_error.lo src/libtipidee/tipidee_response_header_builtin.lo src/libtipidee/tipidee_response_header_common_put.lo src/libtipidee/tipidee_response_header_date.lo src/libtipidee/tipidee_response_header_date_fmt.lo src/libtipidee/tipidee_response_header_lastmodified.lo src/libtipidee/tipidee_response_status.lo src/libtipidee/tipidee_rql_read.lo src/libtipidee/tipidee_uri_parse.lo src/libtipidee/tipidee_util_chunked_read.lo src/libtipidee/tipidee_util_httpdate.lo
+libtipidee.so.xyzzy: src/libtipidee/tipidee_conf_free.lo src/libtipidee/tipidee_conf_get.lo src/libtipidee/tipidee_conf_get_argv.lo src/libtipidee/tipidee_conf_get_content_type.lo src/libtipidee/tipidee_conf_get_redirection.lo src/libtipidee/tipidee_conf_get_string.lo src/libtipidee/tipidee_conf_get_uint32.lo src/libtipidee/tipidee_conf_init.lo src/libtipidee/tipidee_headers_get_content_length.lo src/libtipidee/tipidee_headers_init.lo src/libtipidee/tipidee_headers_parse.lo src/libtipidee/tipidee_headers_search.lo src/libtipidee/tipidee_method_conv_table.lo src/libtipidee/tipidee_method_tonum.lo src/libtipidee/tipidee_method_tostr.lo src/libtipidee/tipidee_response_error.lo src/libtipidee/tipidee_response_header_builtin.lo src/libtipidee/tipidee_response_header_common_put.lo src/libtipidee/tipidee_response_header_date.lo src/libtipidee/tipidee_response_header_date_fmt.lo src/libtipidee/tipidee_response_header_lastmodified.lo src/libtipidee/tipidee_response_status.lo src/libtipidee/tipidee_rql_read.lo src/libtipidee/tipidee_uri_parse.lo src/libtipidee/tipidee_util_chunked_read.lo src/libtipidee/tipidee_util_defaulttext.lo src/libtipidee/tipidee_util_httpdate.lo
tipideed: EXTRA_LIBS := -lskarnet
tipideed: src/tipideed/tipideed.o src/tipideed/cgi.o src/tipideed/harden.o src/tipideed/log.o src/tipideed/options.o src/tipideed/regular.o src/tipideed/responses.o src/tipideed/send_file.o src/tipideed/tipideed.o src/tipideed/trace.o libtipidee.a.xyzzy
INTERNAL_LIBS :=
diff --git a/src/include/tipidee/util.h b/src/include/tipidee/util.h
index 5160a69..7870a23 100644
--- a/src/include/tipidee/util.h
+++ b/src/include/tipidee/util.h
@@ -19,9 +19,16 @@ enum tipidee_transfercoding_e
TIPIDEE_TRANSFERCODING_UNKNOWN
} ;
+typedef struct tipidee_defaulttext_s tipidee_defaulttext, *tipidee_defaulttext_ref ;
+struct tipidee_defaulttext_s
+{
+ char const *reason ;
+ char const *text ;
+} ;
+
extern int tipidee_util_chunked_read (buffer *, stralloc *, size_t, tain const *, tain *) ;
#define tipidee_util_chunked_read_g(b, sa, max, deadline) tipidee_util_chunked_read(b, sa, max, (deadline), &STAMP)
extern int tipidee_util_httpdate (char const *, tain *) ;
-
+extern int tipidee_util_defaulttext (unsigned int, tipidee_defaulttext *) ;
#endif
diff --git a/src/libtipidee/deps-lib/tipidee b/src/libtipidee/deps-lib/tipidee
index 81cc5f7..b7f88cc 100644
--- a/src/libtipidee/deps-lib/tipidee
+++ b/src/libtipidee/deps-lib/tipidee
@@ -23,5 +23,6 @@ tipidee_response_status.o
tipidee_rql_read.o
tipidee_uri_parse.o
tipidee_util_chunked_read.o
+tipidee_util_defaulttext.o
tipidee_util_httpdate.o
-lskarnet
diff --git a/src/libtipidee/tipidee_util_defaulttext.c b/src/libtipidee/tipidee_util_defaulttext.c
new file mode 100644
index 0000000..d464e48
--- /dev/null
+++ b/src/libtipidee/tipidee_util_defaulttext.c
@@ -0,0 +1,59 @@
+/* ISC license. */
+
+#include <stdlib.h>
+
+#include <tipidee/util.h>
+
+struct blah_s
+{
+ unsigned int status ;
+ char const *reason ;
+ char const *text ;
+} ;
+
+static struct blah_s const data[] =
+{
+ { .status = 200, .reason = "OK", .text = 0 },
+ { .status = 206, .reason = "Partial Content", .text = 0 },
+ { .status = 301, .reason = "Moved Permanently", .text = 0 },
+ { .status = 302, .reason = "Found", .text = 0 },
+ { .status = 304, .reason = "Not Modified", .text = 0 },
+ { .status = 307, .reason = "Temporary Redirect", .text = 0 },
+ { .status = 308, .reason = "Permanent Redirect", .text = 0 },
+ { .status = 400, .reason = "Bad Request", .text = "Bad HTTP request." },
+ { .status = 401, .reason = "Unauthorized", .text = "You need to be authenticated to access this resource." },
+ { .status = 403, .reason = "Forbidden", .text = "Missing credentials to access the resource." },
+ { .status = 404, .reason = "Not Found", .text = "The requested resource was not found." },
+ { .status = 405, .reason = "Method Not Allowed", .text = "This method is not allowed on this resource." },
+ { .status = 408, .reason = "Request Timeout", .text = "The client took too long to formulate its request." },
+ { .status = 412, .reason = "Precondition Failed", .text = 0 },
+ { .status = 413, .reason = "Content Too Large", .text = "Too much data in the request body." },
+ { .status = 414, .reason = "URI Too Long", .text = "The request URI had an oversized component." },
+ { .status = 416, .reason = "Range Not Satisfiable", .text = 0 },
+ { .status = 500, .reason = "Internal Server Error", .text = "There was a server-side issue while processing your request. Sorry." },
+ { .status = 501, .reason = "Not Implemented", .text = "The server does not implement this method." },
+ { .status = 502, .reason = "Bad Gateway", .text = "There was an issue with the backend while processing your request. Sorry." },
+ { .status = 504, .reason = "Gateway Timeout", .text = "The backend took too long to answer. Sorry." },
+ { .status = 505, .reason = "HTTP Version Not Supported", .text = "The server does not implement this version of the protocol." },
+} ;
+
+static int blah_cmp (void const *key, void const *el)
+{
+ unsigned int a = *(unsigned int const *)key ;
+ unsigned int b = ((struct blah_s *)el)->status ;
+ return a < b ? -1 : a > b ;
+}
+
+int tipidee_util_defaulttext (unsigned int status, tipidee_defaulttext *dt)
+{
+ struct blah_s const *p = bsearch(
+ &status,
+ data,
+ sizeof(data) / sizeof(struct blah_s),
+ sizeof(struct blah_s),
+ &blah_cmp) ;
+ if (!p) return 0 ;
+ dt->reason = p->reason ;
+ dt->text = p->text ;
+ return 1 ;
+}
diff --git a/src/tipideed/cgi.c b/src/tipideed/cgi.c
index a875acd..9cd395d 100644
--- a/src/tipideed/cgi.c
+++ b/src/tipideed/cgi.c
@@ -66,6 +66,11 @@ static inline void modify_env (tipidee_rql const *rql, tipidee_headers const *hd
else delenv(rql, "QUERY_STRING") ;
addenv(rql, "SCRIPT_NAME", script) ;
addenv(rql, "SERVER_NAME", rql->uri.host) ;
+ {
+ char proto[9] = "HTTP/1.1" ;
+ if (!rql->http_minor) proto[7] = '0' ;
+ addenv(rql, "SERVER_PROTOCOL", proto) ;
+ }
for (size_t i = 0 ; i < hdr->n ; i++)
{
diff --git a/src/tipideed/tipideed.c b/src/tipideed/tipideed.c
index e7dd3a1..b85f509 100644
--- a/src/tipideed/tipideed.c
+++ b/src/tipideed/tipideed.c
@@ -47,7 +47,7 @@ static void sigchld_handler (int sig)
static inline void prep_env (void)
{
- static char const basevars[] = "PROTO\0TCPCONNNUM\0GATEWAY_INTERFACE=CGI/1.1\0SERVER_PROTOCOL=HTTP/1.1\0SERVER_SOFTWARE=tipidee/" TIPIDEE_VERSION ;
+ static char const basevars[] = "PROTO\0TCPCONNNUM\0GATEWAY_INTERFACE=CGI/1.1\0SERVER_SOFTWARE=tipidee/" TIPIDEE_VERSION ;
static char const sslvars[] = "SSL_PROTOCOL\0SSL_CIPHER\0SSL_TLS_SNI_SERVERNAME\0SSL_PEER_CERT_HASH\0SSL_PEER_CERT_SUBJECT\0HTTPS=on" ;
char const *x = getenv("SSL_PROTOCOL") ;
size_t protolen ;
@@ -500,7 +500,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
case TIPIDEE_METHOD_DELETE : exit_405(&rql, 1) ;
case TIPIDEE_METHOD_TRACE : respond_trace(hdrbuf, &rql, &hdr) ; continue ;
case TIPIDEE_METHOD_CONNECT : exit_501(&rql, "CONNECT method unsupported") ;
- case TIPIDEE_METHOD_PRI : exit_501(&rql, "PRI method attempted with HTTP/1.1") ;
+ case TIPIDEE_METHOD_PRI : exit_501(&rql, "PRI method attempted with HTTP version 1") ;
default : die500x(&rql, 101, "can't happen: unknown HTTP method") ;
}