how can I listen a path without '/' in http module

Viewed 106

I can touch my code when http request look like this:

POST /init HTTP/1.1  
Host: 127.0.0.1  
Connection: keep-alive  
Content-Length: 1343 

The http request looks like this:

POST init HTTP/1.1 // what different is : the path without a '/'  
Host: 127.0.0.1  
Connection: keep-alive  
Content-Length: 1343  

My node.js code is:

http.createServer(function (req, res) {
  console.log('sth')
}).listen(3000); 

Unfortunately, I cannot change the code issuing the init request.

1 Answers

Please, see this question: Do HTTP paths have to start with a slash?

Apparently, yes, the starting slash is required for it to be a valid HTTP request.

As this is technically invalid HTTP, most libraries won't support it.

It seems that Apache tolerates paths without slash... maybe using it as a reverse proxy as a workaround?

Another possibility would be to fork the HTTP server library and modify it to tolerate paths without slashes... you may want to look at this post: https://softwareengineering.stackexchange.com/questions/349656/implement-a-http-server-on-top-of-nodejs-tcp-apis-for-learning-purposes

Related