@@ -100,6 +100,7 @@ namespace Babylon::Polyfills::Internal
100100 InstanceAccessor (" responseType" , &XMLHttpRequest::GetResponseType, &XMLHttpRequest::SetResponseType),
101101 InstanceAccessor (" responseURL" , &XMLHttpRequest::GetResponseURL, nullptr ),
102102 InstanceAccessor (" status" , &XMLHttpRequest::GetStatus, nullptr ),
103+ InstanceMethod (" getResponseHeader" , &XMLHttpRequest::GetResponseHeader),
103104 InstanceMethod (" addEventListener" , &XMLHttpRequest::AddEventListener),
104105 InstanceMethod (" removeEventListener" , &XMLHttpRequest::RemoveEventListener),
105106 InstanceMethod (" abort" , &XMLHttpRequest::Abort),
@@ -128,8 +129,8 @@ namespace Babylon::Polyfills::Internal
128129
129130 Napi::Value XMLHttpRequest::GetResponse (const Napi::CallbackInfo&)
130131 {
131- gsl::span<const std::byte> responseBuffer{m_request.ResponseBuffer ()};
132- auto arrayBuffer{Napi::ArrayBuffer::New (Env (), responseBuffer.size ())};
132+ const gsl::span<const std::byte> responseBuffer{m_request.ResponseBuffer ()};
133+ const auto arrayBuffer{Napi::ArrayBuffer::New (Env (), responseBuffer.size ())};
133134 std::memcpy (arrayBuffer.Data (), responseBuffer.data (), arrayBuffer.ByteLength ());
134135 return std::move (arrayBuffer);
135136 }
@@ -149,6 +150,13 @@ namespace Babylon::Polyfills::Internal
149150 m_request.ResponseType (ResponseType::StringToEnum (value.As <Napi::String>().Utf8Value ()));
150151 }
151152
153+ Napi::Value XMLHttpRequest::GetResponseHeader (const Napi::CallbackInfo& info)
154+ {
155+ const auto headerName = info[0 ].As <Napi::String>().Utf8Value ();
156+ const auto header = m_request.GetResponseHeader (headerName);
157+ return header ? Napi::Value::From (Env (), header.value ()) : info.Env ().Null ();
158+ }
159+
152160 Napi::Value XMLHttpRequest::GetResponseURL (const Napi::CallbackInfo&)
153161 {
154162 return Napi::Value::From (Env (), m_request.ResponseUrl ().data ());
@@ -161,8 +169,8 @@ namespace Babylon::Polyfills::Internal
161169
162170 void XMLHttpRequest::AddEventListener (const Napi::CallbackInfo& info)
163171 {
164- std::string eventType = info[0 ].As <Napi::String>().Utf8Value ();
165- Napi::Function eventHandler = info[1 ].As <Napi::Function>();
172+ const std::string eventType = info[0 ].As <Napi::String>().Utf8Value ();
173+ const Napi::Function eventHandler = info[1 ].As <Napi::Function>();
166174
167175 const auto & eventHandlerRefs = m_eventHandlerRefs[eventType];
168176 for (auto it = eventHandlerRefs.begin (); it != eventHandlerRefs.end (); ++it)
@@ -178,9 +186,9 @@ namespace Babylon::Polyfills::Internal
178186
179187 void XMLHttpRequest::RemoveEventListener (const Napi::CallbackInfo& info)
180188 {
181- std::string eventType = info[0 ].As <Napi::String>().Utf8Value ();
182- Napi::Function eventHandler = info[1 ].As <Napi::Function>();
183- auto itType = m_eventHandlerRefs.find (eventType);
189+ const std::string eventType = info[0 ].As <Napi::String>().Utf8Value ();
190+ const Napi::Function eventHandler = info[1 ].As <Napi::Function>();
191+ const auto itType = m_eventHandlerRefs.find (eventType);
184192 if (itType != m_eventHandlerRefs.end ())
185193 {
186194 auto & eventHandlerRefs = itType->second ;
@@ -205,13 +213,13 @@ namespace Babylon::Polyfills::Internal
205213 try
206214 {
207215 // printfs for debugging CI, will be removed
208- auto inputURL{info[1 ].As <Napi::String>()};
216+ const auto inputURL{info[1 ].As <Napi::String>()};
209217 // If the input URL contains any true % characters, encode them as %25
210- auto encodedPercentURL{Napi::String::New (info.Env (), EncodePercent (inputURL.Utf8Value ()))};
218+ const auto encodedPercentURL{Napi::String::New (info.Env (), EncodePercent (inputURL.Utf8Value ()))};
211219 // Decode the input URL to get a completely unencoded URL
212- auto decodedURL{info.Env ().Global ().Get (" decodeURI" ).As <Napi::Function>().Call ({encodedPercentURL})};
220+ const auto decodedURL{info.Env ().Global ().Get (" decodeURI" ).As <Napi::Function>().Call ({encodedPercentURL})};
213221 // Re-encode the URL to make sure that every illegal character is encoded
214- auto finalURL{info.Env ().Global ().Get (" encodeURI" ).As <Napi::Function>().Call ({decodedURL}).As <Napi::String>()};
222+ const auto finalURL{info.Env ().Global ().Get (" encodeURI" ).As <Napi::Function>().Call ({decodedURL}).As <Napi::String>()};
215223 m_request.Open (MethodType::StringToEnum (info[0 ].As <Napi::String>().Utf8Value ()), finalURL.Utf8Value ());
216224 SetReadyState (ReadyState::Opened);
217225 }
@@ -257,7 +265,7 @@ namespace Babylon::Polyfills::Internal
257265
258266 void XMLHttpRequest::RaiseEvent (const char * eventType)
259267 {
260- auto it = m_eventHandlerRefs.find (eventType);
268+ const auto it = m_eventHandlerRefs.find (eventType);
261269 if (it != m_eventHandlerRefs.end ())
262270 {
263271 const auto & eventHandlerRefs = it->second ;
0 commit comments