Tue, 27 Dec 2016 19:50:20 +0100
adds redirect saf
--- a/src/server/daemon/error.c Tue Dec 27 19:36:19 2016 +0100 +++ b/src/server/daemon/error.c Tue Dec 27 19:50:20 2016 +0100 @@ -45,19 +45,25 @@ int nsapi_error_request(Session *sn, Request *rq) { short status = rq->status_num; - sstr_t msg = error_std; - switch(status) { - case 403: { - msg = error_403; - break; - } - case 404: { - msg = error_404; - break; - } - case 500: { - msg = error_500; - break; + sstr_t msg; + if(status < 400) { + msg.ptr = NULL; + msg.length = 0; + } else { + switch(status) { + default: msg = error_std; + case 403: { + msg = error_403; + break; + } + case 404: { + msg = error_404; + break; + } + case 500: { + msg = error_500; + break; + } } } @@ -68,7 +74,9 @@ pblock_nvinsert("content-type", "text/html", rq->srvhdrs); http_start_response(sn, rq); - net_write(sn->csd, msg.ptr, msg.length); + if(msg.length > 0) { + net_write(sn->csd, msg.ptr, msg.length); + } return REQ_PROCEED; }
--- a/src/server/daemon/ws-fn.c Tue Dec 27 19:36:19 2016 +0100 +++ b/src/server/daemon/ws-fn.c Tue Dec 27 19:50:20 2016 +0100 @@ -47,6 +47,7 @@ { "assign-name", assign_name, NULL, NULL, 0}, { "document-root", document_root, NULL, NULL, 0}, { "pfx2dir", pfx2dir, NULL, NULL, 0}, + { "redirect", redirect, NULL, NULL, 0}, { "simple-rewrite", simple_rewrite, NULL, NULL, 0}, { "type-by-extension", object_type_by_extension, NULL, NULL, 0}, { "send-file", send_file, NULL, NULL, 0},
--- a/src/server/safs/nametrans.c Tue Dec 27 19:36:19 2016 +0100 +++ b/src/server/safs/nametrans.c Tue Dec 27 19:50:20 2016 +0100 @@ -158,6 +158,26 @@ } +int redirect(pblock *pb, Session *sn, Request *rq) { + char *from = pblock_findval("from", pb); + char *url = pblock_findval("url", pb); + + if(!from || !url) { + log_ereport(LOG_MISCONFIG, "redirect: missing parameter (from, url)"); + return REQ_ABORTED; + } + + char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); + if(!strcmp(uri, from)) { + pblock_nvinsert("location", url, rq->srvhdrs); + + protocol_status(sn, rq, 302, NULL); + return REQ_ABORTED; + } + + return REQ_NOACTION; +} + /* * provisional rewrite saf */
--- a/src/server/safs/nametrans.h Tue Dec 27 19:36:19 2016 +0100 +++ b/src/server/safs/nametrans.h Tue Dec 27 19:50:20 2016 +0100 @@ -38,6 +38,7 @@ int assign_name(pblock *pb, Session *sn, Request *rq); int document_root(pblock *pb, Session *sn, Request *rq); int pfx2dir(pblock *pb, Session *sn, Request *rq); +int redirect(pblock *pb, Session *sn, Request *rq); int simple_rewrite(pblock *pb, Session *sn, Request *rq);