browserify / browserify/http-browserify
HEAD request not working on Edge
- Vorherrschende Sprache
- JavaScript
- Sterne
- 245
- Forks
- 104
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
When doing a HEAD request with the http library, the javascript just crashes and does not give me any answers.
I tried debugging it myself and found that the library uses fetch to fetch the head. The response of this message is given to IncomingMessage. IncomingMessage assumes that a response has a body. In the case of Edge, the body is just null, because a HEAD request has no body.
Nonetheless, this is accessed in anyway:
```
var reader = response.body.getReader()
function read () {
reader.read().then(function (result) {
if (self._destroyed)
return
if (result.done) {
self.push(null)
return
}
self.push(new Buffer(result.value))
read()
}).catch(function(err) {
self.emit('error', err)
})
}
```
And libraries crashes, causing the HEAD request to hang indefinitely.
To be able to use my own code I added a monkey fix, to temporarily make edge work:
```
window.fetch_old = window.fetch
window.fetch = function () {
var result = window.fetch_old.apply(null, arguments);
result.then_old = result.then;
result.then = function (callback) {
return result.then_old(function(response) {
if(response.body === null){
var body = { "getReader" : function () {
return {
"read" : function (){
return {
"then" : function (callback){
callback({"done":true});
return {"catch" : function(){}};
}
}
}
}
}};
//override body....
var handler = {
get: function(target, name) {
if(name === "body"){
return body;
}
return target[name];
}
};
var response_new = new Proxy(response, handler);
return callback(response_new);
}
return callback(response);
});
}
return result;
};
```
But obviously, it would be great if this could be fixed in the library, instead of my ugly hack.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne bei IncomingMessage, wo der Body der fetch-Antwort mit getReader() gelesen wird, und reproduziere eine HEAD-Anfrage in Edge. Behandle einen null-Antwort-Body, ohne dass es zu einem Absturz oder Hängen kommt, und bewahre dabei das bestehende Verhalten für Antworten mit Body.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100