mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibWeb: Support <form method=POST>
Use the new support for HTTP method and request body to implement basic support for POST'ed forms. This is pretty cool! :^)
This commit is contained in:
parent
2946a684ef
commit
ceda137bf2
Notes:
sideshowbarker
2024-07-19 02:08:59 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ceda137bf25
1 changed files with 18 additions and 4 deletions
|
@ -50,8 +50,8 @@ void HTMLFormElement::submit(RefPtr<HTMLInputElement> 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<HTMLInputElement> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue