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

Add a feature or option to turn off the Server: tiny-http (Rust) header #209

Open
stackinspector opened this issue Aug 19, 2021 · 4 comments

Comments

@stackinspector
Copy link

I found that the server built with this project always adds a Server: tiny-http (Rust) header to responses and wanted to disable it. At first I guessed that there must be some feature or option at server initialization that would do this, but when I searched through the source code I found nothing that would make adding this header optional.
related source code

@bradfier
Copy link
Member

It will only inject that default header if you haven't set an alternative Server header. You can set this value to whatever you want by providing another Server header, which will not be overwritten.

@stackinspector
Copy link
Author

It will only inject that default header if you haven't set an alternative Server header. You can set this value to whatever you want by providing another Server header, which will not be overwritten.

But how can I create a response that without a Server header?

@harryhaaren
Copy link

Late answer, but better now than never:

let response = response.with_header(tiny_http::Header {
    field: "Server".parse().unwrap(),
    value: ascii::AsciiString::from_ascii("your-server-name-here").unwrap(),
});

Suggest to close this issue, as this is the way you can set your own value, no feature or option required.

@stackinspector
Copy link
Author

the way you can set your own value

how can I create a response that without a Server header?

kolbma added a commit to kolbma/tiny-http that referenced this issue Jan 17, 2024
In tiny-http#209 it has been requested to provide a feature to remove the Server HTTP header from responses.

You can add now a filter to the response with filter_header(HeaderField).
This prevents the header to be sent with the response.

All methods adding header stuff to the response now return a Result with HeaderError if the header got not added.

For adding multiple headers at once, there is now add_headers(Vec) and with_headers(Vec).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants