mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:17:35 +00:00
LibWeb: Add support for XMLHttpRequest request headers
Implement XMLHttpRequest.setRequestHeader() and include the headers in the outgoing HTTP request.
This commit is contained in:
parent
0639e77898
commit
c99e35485a
4 changed files with 33 additions and 1 deletions
|
@ -43,6 +43,7 @@ void XMLHttpRequestPrototype::initialize(JS::GlobalObject& global_object)
|
|||
Object::initialize(global_object);
|
||||
define_native_function("open", open, 2);
|
||||
define_native_function("send", send, 0);
|
||||
define_native_function("setRequestHeader", set_request_header, 2);
|
||||
define_native_property("readyState", ready_state_getter, nullptr, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
define_native_property("responseText", response_text_getter, nullptr, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
|
||||
|
@ -93,6 +94,21 @@ JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::send)
|
|||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(XMLHttpRequestPrototype::set_request_header)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto arg0 = vm.argument(0).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto arg1 = vm.argument(1).to_string(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
impl->set_request_header(arg0, arg1);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_GETTER(XMLHttpRequestPrototype::ready_state_getter)
|
||||
{
|
||||
auto* impl = impl_from(vm, global_object);
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(open);
|
||||
JS_DECLARE_NATIVE_FUNCTION(send);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_request_header);
|
||||
|
||||
JS_DECLARE_NATIVE_GETTER(ready_state_getter);
|
||||
JS_DECLARE_NATIVE_GETTER(response_text_getter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue