unosquare / embedio

A tiny, cross-platform, module based web server for .NET
http://unosquare.github.io/embedio
Other
1.45k stars 175 forks source link

How can I custom the Server header #579

Open mirror222 opened 1 year ago

mirror222 commented 1 year ago

Find the codes below, how can I change the response SERVER header to MYOWN.

Thank you.

image

`

        var server = new WebServer(o => o
                .WithCertificate(null)
                .WithUrlPrefix(url)
                .WithMode(HttpListenerMode.EmbedIO))
            .WithIPBanning(o => o
                .WithMaxRequestsPerSecond(30)                  
                .WithRegexRules("Too many requests 429"))
            .WithLocalSessionManager()
            .WithCors(
                // Origins, separated by comma without last slash
                "http://unosquare.github.io,http://run.plnkr.co",
                // Allowed headers
                "content-type, accept",
                // Allowed methods
                "post")
            .WithWebApi("/api", m => m
                .WithController<PeopleController>())
            .WithModule(new WebSocketChatModule("/chat"))
            .WithModule(new WebSocketTerminalModule("/terminal"))
            .WithStaticFolder("/", HtmlRootPath, true, m => m    //<----------
                .WithContentCaching(UseFileCache)                    
                );

`

etherealbacon commented 1 year ago

Hello and thanks everyone for the efforts with this project.

I am also trying to change the server header. I can see that it is set using the Signature read-only static string here:

https://github.com/unosquare/embedio/blob/2305190014d63f86ca036da85e426714d1e667f8/src/EmbedIO/WebServer-Constants.cs#L27

This looks like the project has deliberately made it difficult to change this?

Is there any way to change it for all responses?

zhangzhezh commented 10 months ago

HttpContext.Response.Headers.Add("Server", "Tengine");