SagerNet / sing-box

The universal proxy platform
https://sing-box.sagernet.org/
Other
15.38k stars 1.89k forks source link

Support for host in HTTPupgrade header #1842

Closed mikeesierrah closed 2 weeks ago

mikeesierrah commented 2 weeks ago

This PR introduces support for the “Host” header in HTTP upgrade requests, addressing issue #1841 without disrupting the existing codebase and logic of Sing-Box.

In striving for minimal changes, I encountered a case sensitivity issue:

if headersHost := headers.Get("host"); headersHost != "" {
    host = headersHost
}

The code functioned correctly when the key was “Host” but failed to recognize “host”: Example:

"headers": {
    "Host": "domain.com"
}

This works, whereas:

"headers": {
    "host": "domain.com"
}

does not.

To resolve this, I modified a few lines to ensure case-insensitive handling.

I’m open to any feedback. XD

Special thanks to @mmmray for invaluable tips and assistance.

P.S.: I believe this enhancement promotes consistency across transports and simplifies the parser development for Sing-Box.

mikeesierrah commented 2 weeks ago

@hiddify-com id recommend you checking this out and adding this support in your fork