The essential part of the code I am using:
- Code: Select all
var sHost = 'localhost';
var oSocket = new Socket;
oSocket.open( sHost + ':80', 'UTF-8' );
oSocket.write( 'GET /index.html HTTP/1.1\r\nHost: ' + sHost + '\r\n\r\n' );
var sReply = oSocket.read( );
alert( sReply );
When I use this code with sHost = 'www.jang.nl' (one of my domains, hosted by One.com), I get the contents of the requested page (preceded by the usual headers). But running it with sHost set to 'localhost' gives the Bad Request response. Asking for localhost/index.html page in a local web browser gives the page contents without any problems.
Checking the access log, I see the following lines - first line for the request by the local web browser, second line when using the socket:
::1 - - [23/Sep/2021:09:19:32 +0100] "GET /index.html HTTP/1.1" 304 - "-" "Mozilla (etc)"
::1 - - [23/Sep/2021:09:19:52 +0100] "GET /index.html HTTP/1.1\n" 400 331 "-" "-"
My question: is there any setting for any of the Apache config files that may be causing this ? To me it seems obvious that the \n should not be there in the protocol identifier string, but why is that string not stripped as defined by the protocol ?