1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 17:58:12 +00:00

LibWeb+WebContentr+WebDriver: Move driver response wrapping to LibWeb

Success responses are meant to be wrapped in a JSON object with a single
"value" key. Instead of doing this in both WebContent and WebDriver, do
it once in LibWeb.
This commit is contained in:
Timothy Flynn 2022-11-13 00:52:44 -05:00 committed by Linus Groh
parent 09c59ee7c0
commit 5385cb1287
4 changed files with 43 additions and 55 deletions

View file

@ -150,6 +150,13 @@ static ErrorOr<MatchedRoute, Error> match_route(HTTP::HttpRequest const& request
return Error::from_code(ErrorCode::UnknownCommand, "The command was not recognized.");
}
static JsonValue make_success_response(JsonValue value)
{
JsonObject result;
result.set("value", move(value));
return result;
}
Client::Client(NonnullOwnPtr<Core::Stream::BufferedTCPSocket> socket, Core::Object* parent)
: Core::Object(parent)
, m_socket(move(socket))
@ -244,6 +251,7 @@ ErrorOr<void, Client::WrappedError> Client::handle_request(JsonValue body)
ErrorOr<void, Client::WrappedError> Client::send_success_response(JsonValue result)
{
result = make_success_response(move(result));
auto content = result.serialized<StringBuilder>();
StringBuilder builder;