0

As i asked, I just want to know how to get invalid message from client in nodejs http server.

For example, normally client send "GET / HTTP/1.1\r\n\r\n" to server, But if i sent "VID / HTTP/1.1\r\n\r\n" like this, there is no react in server. I already checked that server computer gets "VID / HTTP/1.1\r\n\r\n" message using wire-shark.

Thank you for your help.

I looked the solution that using 404 response, But It not worked.

look at this server creation code

function server(Route,connect){ console.log("start server function");

function onRequest(req, response) { //req:clientrequest ,response : server response;
    console.log("ans server");
    Route(req,connect,response,hnd.Hnd);
}
http.createServer(onRequest).listen(port);

}

when I send message "GET /HTTP/1.1\r\n\r\n" from client, server console write "ans server". But not VID

VID is one kind of example that I assume protocol..

  • What kind of HTTP message would `VID` be? – Klaus D. Apr 27 '15 at 01:38
  • @KlausD.: Invalid. Look at the title. AFAIK Node will simply close a connection that opens with an invalid message; OP seems to be looking for a way to handle it with a `400` response. – Amadan Apr 27 '15 at 01:43
  • I think the OP believes that an HTTP "VID" (instead of "GET", "POST", "PUT" etc.) should cause an HTTP 400: Bad Request. Perhaps he wants to see how the client handles different error conditions. I'm not sure that's true ... but I can't suggest any good ways to deliberately trigger an HTTP 400... – FoggyDay Apr 27 '15 at 01:43
  • Are you looking for a way to implement custom HTTP commands? – slebetman Apr 27 '15 at 03:11
  • @slebetman : yes that's the point – anaiskaril Apr 27 '15 at 03:41
  • 2
    possible duplicate of [Custom HTTP method with Nodejs HTTP Server](http://stackoverflow.com/questions/10381084/custom-http-method-with-nodejs-http-server) – slebetman Apr 27 '15 at 03:58
  • 1
    I've voted to close and link it to the appropriate question (see above). Unfortunately, you'll have to modify node in C and compile your own custom node.js. There have been requests for adding an API for this but so far it looks like it's not going anywhere: https://github.com/joyent/node/issues/3192 and https://github.com/joyent/http-parser/pull/158 – slebetman Apr 27 '15 at 03:59

1 Answers1

0

@slebetman : Thank you for your solution.

I've voted to close and link it to the appropriate question (see above). Unfortunately, you'll have to modify node in C and compile your own custom node.js. There have been requests for adding an API for this but so far it looks like it's not going anywhere: github.com/joyent/node/issues/3192 and github.com/joyent/http-parser/pull/158 – slebetman