scramjet/src/client/requests/xmlhttprequest.ts
2024-07-14 16:22:34 -07:00

23 lines
629 B
TypeScript

import { encodeUrl, rewriteHeaders } from "../shared"
XMLHttpRequest.prototype.open = new Proxy(XMLHttpRequest.prototype.open, {
apply(target, thisArg, argArray) {
if (argArray[1]) argArray[1] = encodeUrl(argArray[1])
return Reflect.apply(target, thisArg, argArray)
},
})
XMLHttpRequest.prototype.setRequestHeader = new Proxy(
XMLHttpRequest.prototype.setRequestHeader,
{
apply(target, thisArg, argArray) {
let headerObject = Object.fromEntries([argArray])
headerObject = rewriteHeaders(headerObject)
argArray = Object.entries(headerObject)[0]
return Reflect.apply(target, thisArg, argArray)
},
}
)