This commit is contained in:
jmjatlanta 2017-09-21 11:21:12 -05:00
commit 0eab9cc3fc
2 changed files with 34 additions and 9 deletions

View file

@ -427,10 +427,20 @@ void *api_connection_thread (void *ptr)
if (strcmp (req.buf + req.path, "/")==0 ||
strcmp (req.buf + req.path, "/webui") ||
strcmp (req.buf + req.path, "/webui/")==0) {
path = "/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/"; // WEBUI PAGE
char *redir;
size_t size = sizeof(HTTP_301) + (sizeof(WEBUI_ADDR)*2);
redir = malloc(size);
if (redir) {
snprintf(redir, size, HTTP_301, WEBUI_ADDR, WEBUI_ADDR);
redir[size-1] = '\0'; // just in case
write_dual (s, req.buf + req.http_ver, strchr (redir, ' '));
free (redir);
} else {
write_cstr (s, HTTP_500);
}
} else {
path = req.buf + req.path;
}
if (get_object(params->this_node, path, &obj, &size)) {
if (!send_object(s, obj, size)) {
@ -441,6 +451,7 @@ void *api_connection_thread (void *ptr)
// object not found.
write_dual (s, req.buf + req.http_ver, strchr (HTTP_404, ' '));
}
}
} else if (strcmp(buf + req.method, "POST")==0) {
// TODO: Handle gzip/json POST requests.

View file

@ -39,6 +39,20 @@ struct s_request {
size_t boundary_size;
};
#define WEBUI_ADDR "/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/"
#define HTTP_301 "HTTP/1.1 301 Moved Permanently\r\n" \
"Location: %s\r\n" \
"Content-Type: text/html\r\n\r\n" \
"<a href=\"%s\">Moved Permanently</a>.\r\n\r\n"
#define HTTP_302 "HTTP/1.1 302 Found\r\n" \
"Content-Type: text/html\r\n" \
"Connection: close\r\n" \
"Location: %s\r\n" \
"X-Ipfs-Path: %s\r\n\r\n" \
"<a href=\"%s\">Found</a>.\r\n\r\n"
#define HTTP_400 "HTTP/1.1 400 Bad Request\r\n" \
"Content-Type: text/plain\r\n" \
"Connection: close\r\n\r\n" \