B"H net_io.c: http serve: return HTTP response codes
This commit is contained in:
parent
04f4abda70
commit
8d307cd0eb
7
net_io.c
7
net_io.c
|
@ -695,6 +695,7 @@ int handleHTTPRequest(struct client *c, char *p) {
|
||||||
char hdr[512];
|
char hdr[512];
|
||||||
int clen, hdrlen;
|
int clen, hdrlen;
|
||||||
int httpver, keepalive;
|
int httpver, keepalive;
|
||||||
|
int statuscode = 500;
|
||||||
char *url, *content;
|
char *url, *content;
|
||||||
char ctype[48];
|
char ctype[48];
|
||||||
char getFile[1024];
|
char getFile[1024];
|
||||||
|
@ -736,6 +737,7 @@ int handleHTTPRequest(struct client *c, char *p) {
|
||||||
// "/" -> Our google map application.
|
// "/" -> Our google map application.
|
||||||
// "/data.json" -> Our ajax request to update planes.
|
// "/data.json" -> Our ajax request to update planes.
|
||||||
if (strstr(url, "/data.json")) {
|
if (strstr(url, "/data.json")) {
|
||||||
|
statuscode = 200;
|
||||||
content = aircraftsToJson(&clen);
|
content = aircraftsToJson(&clen);
|
||||||
//snprintf(ctype, sizeof ctype, MODES_CONTENT_TYPE_JSON);
|
//snprintf(ctype, sizeof ctype, MODES_CONTENT_TYPE_JSON);
|
||||||
} else {
|
} else {
|
||||||
|
@ -753,6 +755,7 @@ int handleHTTPRequest(struct client *c, char *p) {
|
||||||
content = (char *) malloc(sbuf.st_size);
|
content = (char *) malloc(sbuf.st_size);
|
||||||
if (read(fd, content, sbuf.st_size) != -1) {
|
if (read(fd, content, sbuf.st_size) != -1) {
|
||||||
clen = sbuf.st_size;
|
clen = sbuf.st_size;
|
||||||
|
statuscode = 200;
|
||||||
} else {
|
} else {
|
||||||
free(content);
|
free(content);
|
||||||
}
|
}
|
||||||
|
@ -764,6 +767,7 @@ int handleHTTPRequest(struct client *c, char *p) {
|
||||||
if (clen < 0) {
|
if (clen < 0) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
clen = snprintf(buf,sizeof(buf),"Error opening HTML file: %s", strerror(errno));
|
clen = snprintf(buf,sizeof(buf),"Error opening HTML file: %s", strerror(errno));
|
||||||
|
statuscode = 404;
|
||||||
content = strdup(buf);
|
content = strdup(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -788,7 +792,7 @@ int handleHTTPRequest(struct client *c, char *p) {
|
||||||
|
|
||||||
// Create the header and send the reply
|
// Create the header and send the reply
|
||||||
hdrlen = snprintf(hdr, sizeof(hdr),
|
hdrlen = snprintf(hdr, sizeof(hdr),
|
||||||
"HTTP/1.1 200 OK\r\n"
|
"HTTP/1.1 %i \r\n"
|
||||||
"Server: Dump1090\r\n"
|
"Server: Dump1090\r\n"
|
||||||
"Content-Type: %s\r\n"
|
"Content-Type: %s\r\n"
|
||||||
"Connection: %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"
|
"Cache-Control: no-cache, must-revalidate\r\n"
|
||||||
"Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n"
|
"Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n"
|
||||||
"\r\n",
|
"\r\n",
|
||||||
|
statuscode,
|
||||||
ctype,
|
ctype,
|
||||||
keepalive ? "keep-alive" : "close",
|
keepalive ? "keep-alive" : "close",
|
||||||
clen);
|
clen);
|
||||||
|
|
Loading…
Reference in a new issue