Feature Request - request.continue() #12
Comments
this is what i ended up doing to recreate the request function continueRequestNormally(req){
var xhr = new XHR()
// set target url and method
xhr.open(req.requestMethod, req.requestURL, req.async)
// set headers
Object.keys(req.requestHeaders || {}).forEach(function(headerKey){
xhr.setRequestHeader(headerKey, req.requestHeaders[headerKey])
})
// send and call completion handler
if (req.async) {
xhr.onload = copyResult
xhr.send(req.requestBody)
} else {
xhr.send(req.requestBody)
copyResult()
}
function copyResult() {
var headers = extractResponseHeaders(xhr.getAllResponseHeaders())
req.respond(xhr.status, headers, xhr.response)
}
}
function extractResponseHeaders(rawHeaders){
var headers = {}
var headerKeyValues = rawHeaders.split('\r\n').filter(Boolean)
headerKeyValues.forEach(function(keyValue){
var data = keyValue.split(': ')
headers[data[0]] = data[1]
})
return headers
} |
I would be happy to take a PR that adds a request.continue(), seems legit |
Ultimately I guess we should avoid adding any non-standard methods to XMLHttpRequest, we'd rather add the methods to for example fauxJax.respond(req, ..) but that's maybe extra work. And would require refactoring also/documentation. Tell me what you think, I would be happy to have you as a new contributor :) |
yeah i think something like |
So yes would take a PR that adds request.continue, for now |
do you have some utility already that does |
Huge 👍 Although, this might be more challenging for a universal ™ solution. I tried to add a |
I only want to intercept requests that match a certain pattern. If the requests don't match the pattern it would be nice to have an easy way to get the request to continue normally.
The text was updated successfully, but these errors were encountered: