Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTTP] Make the Host header overwritable #6133

Closed
TharmiganK opened this issue Mar 5, 2024 · 0 comments · Fixed by ballerina-platform/module-ballerina-http#1880
Closed
Assignees
Labels
module/http Team/PCM Protocol connector packages related issues Type/Improvement

Comments

@TharmiganK
Copy link
Contributor

Description:

Currently if the user intentionally add the Host header, we are overwriting it with the default host provided in the client URL. This is because the Host header has its own semantics in HTTP domain[1] and since in it is a not recommended to allow overwriting it programatically[2].

[1] https://www.rfc-editor.org/rfc/rfc9110#section-7.2
[2] https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name

Describe your problem(s)

import ballerina/http;
import ballerina/io;

public function main() returns error? {
    http:Client httpEp = check new (url = "https://sarinda.requestcatcher.com/test");
    string getResponse = check httpEp->/.get(headers = {"host":"sarinda.choreo.dev","host1":"sarinda.host1.choreo.dev"});
    io:println(getResponse);
}

Tracelogs for request:

GET /test/ HTTP/1.1
host1: sarinda.host1.choreo.dev
host: sarinda.requestcatcher.com
user-agent: ballerina
connection: keep-alive 

Describe your solution(s)

Let the user overwrite the Host header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/http Team/PCM Protocol connector packages related issues Type/Improvement
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant