summaryrefslogtreecommitdiffstats
path: root/httpd.cpp
diff options
context:
space:
mode:
authorfireice-uk <fireice2@o2.pl>2017-03-14 19:41:49 +0000
committerfireice-uk <fireice2@o2.pl>2017-03-14 19:41:49 +0000
commite4f5318768d1987056b156f7eb45596d80af19c3 (patch)
tree3011081eaeacaa5dc8c7f454f727665e777a6cbf /httpd.cpp
parent8d2f179f3e9bd56088c7d961919d06abaa6505ba (diff)
downloadxmr-stak-e4f5318768d1987056b156f7eb45596d80af19c3.zip
xmr-stak-e4f5318768d1987056b156f7eb45596d80af19c3.tar.gz
302 Redirect instead of error
Diffstat (limited to 'httpd.cpp')
-rw-r--r--httpd.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/httpd.cpp b/httpd.cpp
index 84612dd..927bc39 100644
--- a/httpd.cpp
+++ b/httpd.cpp
@@ -101,12 +101,20 @@ int httpd::req_handler(void * cls,
}
else
{
- char buffer[1024];
- snprintf(buffer, sizeof(buffer), "<html><head><title>Error</title></head><body>"
- "<pre>Unkown url %s - please use /h, /r or /c as url</pre></body></html>", url);
-
- rsp = MHD_create_response_from_buffer(strlen(buffer),
- (void*)buffer, MHD_RESPMEM_MUST_COPY);
+ //Do a 302 redirect to /h
+ char loc_path[256];
+ const char* host_val = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "Host");
+
+ if(host_val != nullptr)
+ snprintf(loc_path, sizeof(loc_path), "http://%s/h", host_val);
+ else
+ snprintf(loc_path, sizeof(loc_path), "/h");
+
+ rsp = MHD_create_response_from_buffer(0, nullptr, MHD_RESPMEM_PERSISTENT);
+ int ret = MHD_queue_response(connection, MHD_HTTP_TEMPORARY_REDIRECT, rsp);
+ MHD_add_response_header(rsp, "Location", loc_path);
+ MHD_destroy_response(rsp);
+ return ret;
}
int ret = MHD_queue_response(connection, MHD_HTTP_OK, rsp);
OpenPOWER on IntegriCloud