diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 11 |
1 files changed, 9 insertions, 2 deletions
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "xs_json.h" | 7 | #include "xs_json.h" |
| 8 | #include "xs_socket.h" | 8 | #include "xs_socket.h" |
| 9 | #include "xs_httpd.h" | 9 | #include "xs_httpd.h" |
| 10 | #include "xs_mime.h" | ||
| 10 | 11 | ||
| 11 | #include "snac.h" | 12 | #include "snac.h" |
| 12 | 13 | ||
| @@ -30,7 +31,7 @@ int server_get_handler(d_char *req, char *q_path, | |||
| 30 | char *acpt = xs_dict_get(req, "accept"); | 31 | char *acpt = xs_dict_get(req, "accept"); |
| 31 | 32 | ||
| 32 | if (acpt == NULL) | 33 | if (acpt == NULL) |
| 33 | return 400; | 34 | return 0; |
| 34 | 35 | ||
| 35 | /* is it the server root? */ | 36 | /* is it the server root? */ |
| 36 | if (*q_path == '\0') { | 37 | if (*q_path == '\0') { |
| @@ -126,7 +127,7 @@ void httpd_connection(FILE *f) | |||
| 126 | if (xs_startswith(q_path, p)) | 127 | if (xs_startswith(q_path, p)) |
| 127 | q_path = xs_crop(q_path, strlen(p), 0); | 128 | q_path = xs_crop(q_path, strlen(p), 0); |
| 128 | 129 | ||
| 129 | if (strcmp(method, "GET") == 0) { | 130 | if (strcmp(method, "GET") == 0 || strcmp(method, "HEAD") == 0) { |
| 130 | /* cascade through */ | 131 | /* cascade through */ |
| 131 | if (status == 0) | 132 | if (status == 0) |
| 132 | status = server_get_handler(req, q_path, &body, &b_size, &ctype); | 133 | status = server_get_handler(req, q_path, &body, &b_size, &ctype); |
| @@ -181,6 +182,12 @@ void httpd_connection(FILE *f) | |||
| 181 | if (b_size == 0 && body != NULL) | 182 | if (b_size == 0 && body != NULL) |
| 182 | b_size = strlen(body); | 183 | b_size = strlen(body); |
| 183 | 184 | ||
| 185 | /* if it was a HEAD, no body will be sent */ | ||
| 186 | if (strcmp(method, "HEAD") == 0) { | ||
| 187 | free(body); | ||
| 188 | body = NULL; | ||
| 189 | } | ||
| 190 | |||
| 184 | xs_httpd_response(f, status, headers, body, b_size); | 191 | xs_httpd_response(f, status, headers, body, b_size); |
| 185 | 192 | ||
| 186 | fclose(f); | 193 | fclose(f); |