Wrong host path parsing
Author: Alisa-lisaCreated Jul 11, 2023Updated Jan 24, 2025
I've just encountered an unexpected behavior. My tests fail with 404 response whenever I try to target an url containing port like: http://localhost:XXXX/some_path.
Curl request: curl -XGET 'http://localhost:8080/api/v1/health' results in following output:
2023-10-11 23:10:30 127.0.0.1:56008 GET /api/v1/health HTTP/1.1
┌─Incoming request
│ GET /api/v1/health HTTP/1.1
│ Accept: */*
│ Host: localhost:8080
│ User-Agent: curl/8.1.2
┌─Outgoing response
│ HTTP/1.1 200 OK
│ Content-Length: 9
│ Content-Type: text/plain; charset=utf-8
│ Date: Tue, 11 Jul 2023 23:10:30 +0200When using oha with: oha -n 1 'http://localhost:8080/api/v1/health' i get following response:
2023-11-11 23:11:21 127.0.0.1:58418 GET http://localhost:8080/api/v1/health HTTP/1.1
┌─Incoming request
│ GET http://localhost:8080/api/v1/health HTTP/1.1
│ Accept: */*
│ Accept-Encoding: gzip, compress, deflate, br
│ Host: localhost:8080
┌─Outgoing response
│ HTTP/1.1 200 OK
│ Content-Length: 9
│ Content-Type: text/plain; charset=utf-8
│ Date: Tue, 11 Jul 2023 23:11:21 +0200As you can see, the path in case of oha-request contains domain and port, which is incorrect and will result in 404 response.
Source: hatoo/oha