diff options
| author | 2024-05-27 16:25:20 +0200 | |
|---|---|---|
| committer | 2024-05-27 19:01:04 +0200 | |
| commit | 26fbda787d0d5c8ba9259f79f4d2f937bd6c8ead (patch) | |
| tree | 8615eda88a882eb4959abf707a693374f22d9752 /xs_httpd.h | |
| parent | Use ISO C99 __func__ instead of GNU __FUNCTION__ (diff) | |
| download | penes-snac2-26fbda787d0d5c8ba9259f79f4d2f937bd6c8ead.tar.gz penes-snac2-26fbda787d0d5c8ba9259f79f4d2f937bd6c8ead.tar.xz penes-snac2-26fbda787d0d5c8ba9259f79f4d2f937bd6c8ead.zip | |
Translate status codes to canonical status texts
Use those in HTTP responses instead of "OK"/"ERROR".
Apps like Tokodon show only the status text in unexpected responses.
Diffstat (limited to '')
| -rw-r--r-- | xs_httpd.h | 6 |
1 files changed, 3 insertions, 3 deletions
| @@ -5,7 +5,7 @@ | |||
| 5 | #define _XS_HTTPD_H | 5 | #define _XS_HTTPD_H |
| 6 | 6 | ||
| 7 | xs_dict *xs_httpd_request(FILE *f, xs_str **payload, int *p_size); | 7 | xs_dict *xs_httpd_request(FILE *f, xs_str **payload, int *p_size); |
| 8 | void xs_httpd_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b_size); | 8 | void xs_httpd_response(FILE *f, int status, const char *status_text, xs_dict *headers, xs_str *body, int b_size); |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | #ifdef XS_IMPLEMENTATION | 11 | #ifdef XS_IMPLEMENTATION |
| @@ -95,14 +95,14 @@ xs_dict *xs_httpd_request(FILE *f, xs_str **payload, int *p_size) | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | 97 | ||
| 98 | void xs_httpd_response(FILE *f, int status, xs_dict *headers, xs_str *body, int b_size) | 98 | void xs_httpd_response(FILE *f, int status, const char *status_text, xs_dict *headers, xs_str *body, int b_size) |
| 99 | /* sends an httpd response */ | 99 | /* sends an httpd response */ |
| 100 | { | 100 | { |
| 101 | xs *proto; | 101 | xs *proto; |
| 102 | const xs_str *k; | 102 | const xs_str *k; |
| 103 | const xs_val *v; | 103 | const xs_val *v; |
| 104 | 104 | ||
| 105 | proto = xs_fmt("HTTP/1.1 %d %s", status, status / 100 == 2 ? "OK" : "ERROR"); | 105 | proto = xs_fmt("HTTP/1.1 %d %s", status, status_text); |
| 106 | fprintf(f, "%s\r\n", proto); | 106 | fprintf(f, "%s\r\n", proto); |
| 107 | 107 | ||
| 108 | int c = 0; | 108 | int c = 0; |