From 8d307cd0ebe8ac2b446d717d048dc11951c3eb29 Mon Sep 17 00:00:00 2001 From: hhm Date: Wed, 17 Sep 2014 06:32:03 -0400 Subject: [PATCH] B"H net_io.c: http serve: return HTTP response codes --- net_io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net_io.c b/net_io.c index 1679ef1..91cf47d 100644 --- a/net_io.c +++ b/net_io.c @@ -695,6 +695,7 @@ int handleHTTPRequest(struct client *c, char *p) { char hdr[512]; int clen, hdrlen; int httpver, keepalive; + int statuscode = 500; char *url, *content; char ctype[48]; char getFile[1024]; @@ -736,6 +737,7 @@ int handleHTTPRequest(struct client *c, char *p) { // "/" -> Our google map application. // "/data.json" -> Our ajax request to update planes. if (strstr(url, "/data.json")) { + statuscode = 200; content = aircraftsToJson(&clen); //snprintf(ctype, sizeof ctype, MODES_CONTENT_TYPE_JSON); } else { @@ -753,6 +755,7 @@ int handleHTTPRequest(struct client *c, char *p) { content = (char *) malloc(sbuf.st_size); if (read(fd, content, sbuf.st_size) != -1) { clen = sbuf.st_size; + statuscode = 200; } else { free(content); } @@ -764,6 +767,7 @@ int handleHTTPRequest(struct client *c, char *p) { if (clen < 0) { char buf[128]; clen = snprintf(buf,sizeof(buf),"Error opening HTML file: %s", strerror(errno)); + statuscode = 404; content = strdup(buf); } @@ -788,7 +792,7 @@ int handleHTTPRequest(struct client *c, char *p) { // Create the header and send the reply hdrlen = snprintf(hdr, sizeof(hdr), - "HTTP/1.1 200 OK\r\n" + "HTTP/1.1 %i \r\n" "Server: Dump1090\r\n" "Content-Type: %s\r\n" "Connection: %s\r\n" @@ -796,6 +800,7 @@ int handleHTTPRequest(struct client *c, char *p) { "Cache-Control: no-cache, must-revalidate\r\n" "Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n" "\r\n", + statuscode, ctype, keepalive ? "keep-alive" : "close", clen);