Commit 840b1b40 authored by jan.koester's avatar jan.koester
Browse files

test

parent 3e8681ec
Loading
Loading
Loading
Loading
+19 −4
Changes for src/http/HttpProxyServer.cpp: 19 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ std::string methodName(int requestType) {
        case POSTREQUEST: return "POST";
        case PUTREQUEST: return "PUT";
        case DELETEREQUEST: return "DELETE";
        case OPTIONSREQUEST: return "OPTIONS";
        case HEADREQUEST: return "HEAD";
        case PATCHREQUEST: return "PATCH";
        default: return "UNKNOWN";
    }
}
@@ -327,7 +330,10 @@ void HttpProxyController::RequestEvent(libhttppp::HttpRequest &curreq, const int
            }
        }

        if (method != "GET" && method != "POST" && method != "PUT" && method != "DELETE") {
        static const std::set<std::string> kForwardableMethods = {
            "GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH",
        };
        if (!kForwardableMethods.count(method)) {
            sendError(curreq, HTTP501, "forwarding not implemented for method " + method);
            return;
        }
@@ -402,14 +408,23 @@ void HttpProxyController::RequestEvent(libhttppp::HttpRequest &curreq, const int
            outreq.setHeaderData("x-forwarded-proto")->push_back(_tlsActive ? "https" : "http");

            std::vector<char> body;
            if (method == "POST" || method == "PUT") {
                outreq.setRequestType(method == "POST" ? POSTREQUEST : PUTREQUEST);
            if (method == "POST" || method == "PUT" || method == "PATCH") {
                outreq.setRequestType(method == "POST" ? POSTREQUEST
                                       : method == "PUT" ? PUTREQUEST
                                                          : PATCHREQUEST);
                std::vector<char> requestBody(curreq.RecvData.begin(), curreq.RecvData.end());
                body = (method == "POST")  ? client.Post(outreq, requestBody)
                                           : client.Put(outreq, requestBody);
                       : (method == "PUT") ? client.Put(outreq, requestBody)
                                           : client.Patch(outreq, requestBody);
            } else if (method == "DELETE") {
                outreq.setRequestType(DELETEREQUEST);
                body = client.Delete(outreq);
            } else if (method == "OPTIONS") {
                outreq.setRequestType(OPTIONSREQUEST);
                body = client.Options(outreq);
            } else if (method == "HEAD") {
                outreq.setRequestType(HEADREQUEST);
                body = client.Head(outreq);
            } else {
                outreq.setRequestType(GETREQUEST);
                body = client.Get(outreq);