summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
5 files changed, 75 insertions, 3 deletions
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") ;
}