Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http Handler貌似执行了两次。 #26

Closed
smallnewer opened this issue Aug 25, 2014 · 2 comments
Closed

http Handler貌似执行了两次。 #26

smallnewer opened this issue Aug 25, 2014 · 2 comments

Comments

@smallnewer
Copy link

代码如下:

var http = require('http');

var svr = new http.Server(9005, function(r){
    console.log(r.query.id)
    r.response.write('x');
});
svr.run();

浏览器中打开网址http://localhost:9005/?qq=2&id=3
命令行中输入如下:

3
undefined

貌似是执行了两次。第二次r.query为空。因此无法输出id。

如果上面的代码改为

var http = require('http');

var svr = new http.Server(9005, function(r){
    // console.log(r.query.id)
    r.response.write(r.query.id);
});
svr.run();

浏览器中看到输出只有3,没有undefined。

初次接触,不知是何缘故。

@fibjs
Copy link
Collaborator

fibjs commented Aug 25, 2014

确认 bug,正在检查,多谢。

@fibjs
Copy link
Collaborator

fibjs commented Aug 25, 2014

执行了两次是正确的,因为浏览器会请求 http://localhost:9005/?qq=2&id=3http://localhost:9005/favicon.ico,因此第二次请求会出现 undefined。

@fibjs fibjs closed this as completed Aug 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant