From ceda137bf25df26e53e6c64a04a89d450b43eeb1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 28 Sep 2020 11:56:26 +0200 Subject: LibWeb: Support
Use the new support for HTTP method and request body to implement basic support for POST'ed forms. This is pretty cool! :^) --- Libraries/LibWeb/HTML/HTMLFormElement.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'Libraries') diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 566c82022c..f7307d5227 100644 --- a/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -50,8 +50,8 @@ void HTMLFormElement::submit(RefPtr submitter) } auto effective_method = method().to_lowercase(); - if (effective_method != "get") { - if (effective_method == "post" || effective_method == "dialog") { + if (effective_method != "get" && effective_method != "post") { + if (effective_method == "dialog") { dbg() << "Unsupported form method '" << method() << "'"; return; } @@ -69,10 +69,24 @@ void HTMLFormElement::submit(RefPtr submitter) return IterationDecision::Continue; }); - url.set_query(urlencode(parameters)); + if (effective_method == "get") { + url.set_query(urlencode(parameters)); + } // FIXME: We shouldn't let the form just do this willy-nilly. - document().frame()->page().load(url); + + LoadRequest request; + request.set_url(url); + + if (effective_method == "post") { + auto body = urlencode(parameters).to_byte_buffer(); + request.set_method("POST"); + request.set_header("Content-Type", "application/x-www-form-urlencoded"); + request.set_header("Content-Length", String::number(body.size())); + request.set_body(body); + } + + document().frame()->page().load(request); } } -- cgit v1.2.3