mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
WebDriver: Implement DELETE /session/{id}/cookie/{name}
endpoint
This commit is contained in:
parent
0d6dc2492d
commit
fefe447cf5
Notes:
sideshowbarker
2024-07-17 05:39:14 +09:00
Author: https://github.com/TobyAsE Commit: https://github.com/SerenityOS/serenity/commit/fefe447cf5 Pull-request: https://github.com/SerenityOS/serenity/pull/15649 Reviewed-by: https://github.com/davidot Reviewed-by: https://github.com/linusg
4 changed files with 31 additions and 0 deletions
|
@ -32,6 +32,7 @@ Vector<Client::Route> Client::s_routes = {
|
|||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "forward" }, &Client::handle_forward },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie" }, &Client::handle_get_all_cookies },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "cookie", ":name" }, &Client::handle_get_named_cookie },
|
||||
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "cookie", ":name" }, &Client::handle_delete_cookie },
|
||||
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "cookie" }, &Client::handle_delete_all_cookies },
|
||||
};
|
||||
|
||||
|
@ -515,6 +516,17 @@ ErrorOr<JsonValue, HttpError> Client::handle_get_named_cookie(Vector<StringView>
|
|||
return make_json_value(cookies);
|
||||
}
|
||||
|
||||
// DELETE /session/{session id}/cookie/{name} https://w3c.github.io/webdriver/#dfn-delete-cookie
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_delete_cookie(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling DELETE /session/<session_id>/cookie/<name>");
|
||||
Session* session = TRY(find_session_with_id(parameters[0]));
|
||||
|
||||
// NOTE: Spec steps handled in Session::delete_cookie().
|
||||
auto result = TRY(session->delete_cookie(parameters[1]));
|
||||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// DELETE /session/{session id}/cookie https://w3c.github.io/webdriver/#dfn-delete-all-cookies
|
||||
ErrorOr<JsonValue, HttpError> Client::handle_delete_all_cookies(Vector<StringView> parameters, JsonValue const&)
|
||||
{
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
ErrorOr<JsonValue, HttpError> handle_forward(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_all_cookies(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_get_named_cookie(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_delete_cookie(Vector<StringView>, JsonValue const& payload);
|
||||
ErrorOr<JsonValue, HttpError> handle_delete_all_cookies(Vector<StringView>, JsonValue const& payload);
|
||||
|
||||
ErrorOr<Session*, HttpError> find_session_with_id(StringView session_id);
|
||||
|
|
|
@ -315,6 +315,23 @@ void Session::delete_cookies(Optional<StringView> const& name)
|
|||
}
|
||||
}
|
||||
|
||||
// DELETE /session/{session id}/cookie/{name} https://w3c.github.io/webdriver/#dfn-delete-cookie
|
||||
ErrorOr<JsonValue, HttpError> Session::delete_cookie(StringView const& name)
|
||||
{
|
||||
// 1. If the current browsing context is no longer open, return error with error code no such window.
|
||||
auto current_window = get_window_object();
|
||||
if (!current_window.has_value())
|
||||
return HttpError { 404, "no such window", "Window not found" };
|
||||
|
||||
// FIXME: 2. Handle any user prompts, and return its value if it is an error.
|
||||
|
||||
// 3. Delete cookies using the url variable name parameter as the filter argument.
|
||||
delete_cookies(name);
|
||||
|
||||
// 4. Return success with data null.
|
||||
return JsonValue();
|
||||
}
|
||||
|
||||
// DELETE /session/{session id}/cookie https://w3c.github.io/webdriver/#dfn-delete-all-cookies
|
||||
ErrorOr<JsonValue, HttpError> Session::delete_all_cookies()
|
||||
{
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
ErrorOr<JsonValue, HttpError> forward();
|
||||
ErrorOr<JsonValue, HttpError> get_all_cookies();
|
||||
ErrorOr<JsonValue, HttpError> get_named_cookie(String const& name);
|
||||
ErrorOr<JsonValue, HttpError> delete_cookie(StringView const& name);
|
||||
ErrorOr<JsonValue, HttpError> delete_all_cookies();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue