From 57ead17d54b73cbb0b113ad2980f71fd77637601 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 3 Apr 2021 15:51:15 +0200 Subject: [PATCH] LibWeb: Implement XMLHttpRequest.getResponseHeader() This lets jQuery's AJAX functionality progress further :^) --- Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp | 2 +- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 3 ++- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h | 3 +++ Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index 2e4d8a2114..0e3ca31e85 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -102,7 +102,7 @@ static size_t get_function_length(FunctionType& function) struct Type { String name; bool nullable { false }; - bool is_string() const { return name.is_one_of("DOMString", "USVString", "CSSOMString"); } + bool is_string() const { return name.is_one_of("ByteString", "CSSOMString", "DOMString", "USVString"); } }; struct Parameter { diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 4a967672ce..37a9d5e6db 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -229,7 +229,7 @@ DOM::ExceptionOr XMLHttpRequest::send() // we need to make ResourceLoader give us more detailed updates than just "done" and "error". ResourceLoader::the().load( request, - [weak_this = make_weak_ptr()](auto data, auto&, auto status_code) { + [weak_this = make_weak_ptr()](auto data, auto& response_headers, auto status_code) { if (!weak_this) return; auto& xhr = const_cast(*weak_this); @@ -245,6 +245,7 @@ DOM::ExceptionOr XMLHttpRequest::send() xhr.m_ready_state = ReadyState::Done; xhr.m_status = status_code.value_or(0); + xhr.m_response_headers = move(response_headers); xhr.m_send = false; xhr.dispatch_event(DOM::Event::create(EventNames::readystatechange)); xhr.fire_progress_event(EventNames::load, transmitted, length); diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index 1bdcb93925..3726da2d78 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -76,6 +76,8 @@ public: DOM::ExceptionOr set_request_header(const String& header, const String& value); + String get_response_header(const String& name) { return m_response_headers.get(name).value_or({}); } + private: virtual void ref_event_target() override { ref(); } virtual void unref_event_target() override { unref(); } @@ -98,6 +100,7 @@ private: URL m_url; HashMap m_request_headers; + HashMap m_response_headers; bool m_synchronous { false }; bool m_upload_complete { false }; diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl index 35a63d0532..21ae7a5a54 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl @@ -16,4 +16,6 @@ interface XMLHttpRequest : XMLHttpRequestEventTarget { undefined setRequestHeader(DOMString name, DOMString value); undefined send(); + ByteString? getResponseHeader(ByteString name); + };