B"H net_io.c: http serve: return HTTP response codes

This commit is contained in:
hhm 2014-09-17 06:32:03 -04:00
parent 04f4abda70
commit 8d307cd0eb

View file

@ -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);