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

Update Host header only when the user intentionally provide a value #6149

Closed
TharmiganK opened this issue Mar 7, 2024 · 1 comment
Closed
Assignees
Labels
module/http Priority/High Team/PCM Protocol connector packages related issues Type/Improvement

Comments

@TharmiganK
Copy link
Contributor

Description:

With this fix: #6133 the host header is not overwritten by the default host name inferred from the client url. But there are use cases like passthrough where we just send back the request. In those scenarios we should use the host name from the client url unless the user overwrites it.

Describe your problem(s)

import ballerina/http;
import ballerina/io;

service /api on new http:Listener(9090) {

    resource function 'default [string... path](@http:Header string host) returns string {
        io:println("Host header: ", host); // This will be: Host header: localhost:9091
        return "Hello, World!";
    }
}

final http:Client clientEP = check new ("localhost:9090");

service /api on new http:Listener(9091) {

    resource function 'default [string... path](http:Request req) returns http:Response|error {
        return clientEP->execute(req.method, req.rawPath, req);
    }
}
$ curl -v http://localhost:9090/api/test

*   Trying [::1]:9091...
* Connected to localhost (::1) port 9091
> GET /api/test HTTP/1.1
> Host: localhost:9091
> User-Agent: curl/8.4.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-type: text/plain
< date: Thu, 7 Mar 2024 15:00:45 +0530
< server: ballerina
< content-length: 13
< 
* Connection #0 to host localhost left intact
Hello, World!

Describe your solution(s)

Use the default host from the client url when the user not provided a value.

@TharmiganK
Copy link
Contributor Author

Fixed with the above PRs

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

No branches or pull requests

1 participant