Haxe and Node.js http mismatch
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- node.js
- 领域
- backend, networking
调研方向
从生成的 haxe.Http.prototype.request 入口点开始,跟踪 Jsonhx HTTP 请求如何为 Node.js 构建主机、路径和 POST 数据。重现经过身份验证的请求,并将发出的选项与服务器预期的请求进行比较;当主机能够解析、POST 数据未被放入路径中,且服务器不再返回解析错误时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Bear with me here, I'm not sure if I totally understand all of the layers of abstraction going on in the code : )
So, I've been trying to send off some authenticated HTTP requests using the Jsonhx JSON-RPC library. I keep getting error: Http Request Error: Error: getaddrinfo ENOTFOUND
Some googling shows this to be an issue with how Node.js does it's DNS lookups:
I've seen this happen when your host (which you pass in as httpaction) has the scheme (so "http://") in front of it. Your host should strictly be the domain like "www.google.com" not "http://www.google.com" or "www.google.com/hello-world" or "http://www.google.com/hello-world".
Keep it just the domain.
Sure enough, when I pop into the debugger and climb up the call chain to haxe.Http.prototype it displays the host variable as user:pass@localhost:8336.
I switched to a hand-rolled my own authentication header mechanism, that specific error went away, and WireShark picked up on actual HTTP requests being sent (before it saw nothing). I fairly certain that this fixed the problem.
But now I am running into weird error 500 parse errors from my server where the path variable has POST data in it. I dove into the produced code and found weird logic (see inline comments in code below) which I tried tweaking, but I couldn't coax a proper method call out of it. However, appears to be standard code produced by the Haxe JS converter, so I don't know if it is in any way related and now I'm unsure if my fix from above is specific to nodejs-std or not. : (
haxe.Http.prototype = {
...
,request: function(post) {
var _g = this;
var me = this;
var options = { };
var uri = this.postData; //WTF?
var is_secure = this.url.substring(0,8) == "https://";
if(this.url.substring(0,7) == "http://") this.url = HxOverrides.substr(this.url,7,null); else if(is_secure) this.url = HxOverrides.substr(this.url,8,null);
var urlTokens = this.url.split("/");
var host = urlTokens.shift();
if(urlTokens.length > 0) options.path = "/" + urlTokens.join("/"); else options.path = "/";
var hostTokens = host.split(":");
if(hostTokens != null && hostTokens.length > 1) {
options.host = hostTokens[0];
options.port = Std.parseInt(hostTokens[1]);
} else options.host = host;
if(uri != null) post = true; else { // ?
var $it0 = this.params.keys();
while( $it0.hasNext() ) {
var p = $it0.next();
if(uri == null) uri = ""; else uri += "&";
uri += encodeURIComponent(p) + "=" + StringTools.urlEncode(this.params.get(p));
}
}
if(uri != null) {
var question = this.url.split("?").length <= 1;
options.path += (question?"?":"&") + uri;
uri = null; // Stopping the debugger here reveals options.path = "/?{ DATA FROM POST}"
}
if(post) options.method = "POST"; else options.method = "GET";
if(this.headers.get("Content-Type") == null && post && this.postData == null) this.headers.set("Content-Type","application/x-www-form-urlencoded");
if(this.headers.iterator().hasNext()) {
if(options.headers == null) options.headers = { };
var $it1 = this.headers.keys();
while( $it1.hasNext() ) {
var h = $it1.next();
Reflect.setField(options.headers,h,this.headers.get(h));
}
}
var service = null;
if(is_secure) service = js.Node.require("https"); else service = js.Node.require("http");
var request = service.request(options,function(response) {
var responseData = "";
response.setEncoding("utf8");
var s;
try {
s = response.statusCode;
} catch( e ) {
s = 0;
}
if(response.statusCode != null) me.onStatus(response.statusCode);
if(response.statusCode != null && response.statusCode >= 200 && response.statusCode < 400) {
} else switch(s) {
case 0:
me.onError("Failed to connect or resolve host");
break;
case 12029:
me.onError("Failed to connect to host");
break;
case 12007:
me.onError("Unknown host");
break;
default:
me.onError("Http Error #" + response.statusCode);
}
response.on("data",function(chunk) {
responseData += chunk;
});
response.once("end",function() {
response.removeAllListeners("data");
response.removeAllListeners("end");
if(responseData != null) _g.onData(responseData);
responseData = null;
});
response.once("close",function() {
if(responseData != null) _g.onData(responseData);
responseData = null;
});
response.once("error",function(error) {
me.onError("Http Response Error: " + Std.string(error));
});
});
request.on("error",function(error1) {
me.onError("Http Request Error: " + Std.string(error1));
});
request.end();
}
,onData: function(data) {
}
,onError: function(msg) {
}
,onStatus: function(status) {
}
};
- 主要语言
- Haxe
- 星标
- 43
- 派生
- 30
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dionjwa/nodejs-std 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 55/100
dionjwa/nodejs-std#35 ·
-
难度 2/5 1-3 小时 新手友好度 35/100
dionjwa/nodejs-std#33 ·
-
Usage examples未关闭
难度 3/5 1-2 天 新手友好度 20/100
dionjwa/nodejs-std#26 ·
-
难度 2/5 1-3 小时 新手友好度 35/100
dionjwa/nodejs-std#21 ·
-
难度 4/5 3-5 天 新手友好度 20/100
dionjwa/nodejs-std#19 ·
查看 dionjwa/nodejs-std 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
SciML/Evolutionary.jl#182 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
simonw/llm-mistral#43 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
rossoctl/context-guru#346 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 90/100
prime-radiant-inc/evener#2883 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
GoogleChromeLabs/project-sesame#216 ·
维护者通常 12 天内回复