Commit fc197cb5 authored by jan.koester's avatar jan.koester
Browse files

test

parent 0bf41e87
Loading
Loading
Loading
Loading
+15 −8
Changes for src/http/HttpProxyServer.cpp: 15 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -181,12 +181,8 @@ void HttpProxyController::RequestEvent(libhttppp::HttpRequest &curreq, const int
            }
        }

        // Forwarding: only GET is implemented in this prototype. libhttppp's HttpClient
        // exposes Get/Post/Put/Delete convenience methods but this prototype has not yet
        // wired up reading the inbound request body needed to relay POST/PUT -- see
        // docs/ARCHITECTURE.md §4.
        if (method != "GET") {
            sendError(curreq, HTTP501, "only GET forwarding is implemented in this prototype");
        if (method != "GET" && method != "POST" && method != "PUT" && method != "DELETE") {
            sendError(curreq, HTTP501, "forwarding not implemented for method " + method);
            return;
        }

@@ -217,12 +213,23 @@ void HttpProxyController::RequestEvent(libhttppp::HttpRequest &curreq, const int
            // ctor in libhttppp/src/http.cpp for the fallback ladder.
            libhttppp::HttpClient client(upstream, /*vers=*/3);
            libhttppp::HttpRequest outreq;
            outreq.setRequestType(GETREQUEST);
            outreq.setRequestURL(upstream.getPath());
            outreq.setHeaderData("host")->push_back(upstream.getHost());
            outreq.setHeaderData("connection")->push_back("close");

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

            libhttppp::HttpResponse curres;
            int status = 200;