HaxeFoundation / HaxeFoundation/haxe
[sys] sys.Http.hx doens't add port number to the request 'Host' header.
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
## Technical info
```
openSuse linux
haxe 4.3.7
geckodriver 0.37.1
```
## Issue description
Found this behaviour when trying to interact with Firefox through webDriver.
The server kept rejecting request with the error `Rejected request with Host header localhost, allowed values are [localhost:4444]`.
Using a netcat server to inspect requests, haxe is sending this:
````
GET /status HTTP/1.1
Host: localhost
Connection: close
````
Comparing with requests sent by HTTPie, which the webDriver server does accept:
````
GET /status HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Host: 127.0.0.1:4444
User-Agent: HTTPie/3.2.4
````
I attempted adding the headers HTTPie adds, but the request kept being rejected.
Editing sys.Http.hx:203 to add the port number to the header allowed the request to be accepted.
```
b.writeString(" HTTP/1.1\r\nHost: " + host + "\r\n"); // current
b.writeString(" HTTP/1.1\r\nHost: " + host + (portString == null? "" : portString) + "\r\n"); // fix
```
## How to reproduce
Run geckodriver (Firefox's webDriver server) with default config.
`$ geckodriver`
Download link: https://github.com/mozilla/geckodriver/releases
Run, example program.
`$ haxe -main Main --interp`
```
import haxe.Http;
class Main {
static public function main():Void
{
var request = new Http("localhost:4444/status");
request.onData = function(data)
{
trace("DATA");
trace(data);
}
request.onError = function(data)
{
trace("ERROR");
trace(data);
}
request.request();
}
}
```
Expected: geckodriver responds with HTTP 200 and json payload stating that the server is ready.
Actual: geckodriver responds with an HTTP 500 and prints `Rejected request with Host header localhost, allowed values are [localhost:4444]` in the terminal it's running on.
Contributor guide
Research direction
Start in sys.Http.hx around line 203, where the request's Host header is assembled, and compare it with the provided portString example. Run geckodriver and the supplied Main.hx reproduction against localhost:4444. Done means the Host header includes the port and geckodriver returns HTTP 200 with its JSON readiness payload.
Written by the indexing model from the issue text.
Assessment
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100