browserify / browserify/http-browserify

HEAD request not working on Edge

オープン
#104 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
JavaScript
スター
245
フォーク
104
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

IncomingMessage から始めます。ここでは fetch のレスポンスボディが getReader() で読み取られます。Edge で HEAD リクエストを再現します。null のレスポンスボディをクラッシュやハングなしに処理し、ボディがあるレスポンスについては既存の動作を維持します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
api
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。