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..

7
  • What kind of HTTP message would VID be? Commented Apr 27, 2015 at 1: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. Commented Apr 27, 2015 at 1: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... Commented Apr 27, 2015 at 1:43
  • 2
    possible duplicate of Custom HTTP method with Nodejs HTTP Server Commented Apr 27, 2015 at 3: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: github.com/joyent/node/issues/3192 and github.com/joyent/http-parser/pull/158 Commented Apr 27, 2015 at 3:59

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.