cirospaciari / socketify.py

Bringing Http/Https and WebSockets High Performance servers for PyPy3 and Python3
https://www.socketify.dev
MIT License
1.35k stars 47 forks source link

Can't get rid of Server header: "uWebSockets_20" #177

Open wedobetter opened 2 months ago

wedobetter commented 2 months ago

I have tried to overwrite it:

async def healthcheck(res: Response, _: Request, __=None):
    res.write_status(200)
    return res.end_without_body(True)

def headers_mw(res: Response, _: Request, __=None):
    return res.write_header("Server", "myserver")

basic_router = MiddlewareRouter(app, headers_mw)
basic_router.head("/health", healthcheck)

and I ended up with this:

curl -i -I http://127.0.0.1:9999/health

HTTP/1.1 200 OK
Server:  myserver
Connection: close
Date: Sat, 25 May 2024 19:52:29 GMT
Server: uWebSockets_20
RajaSunrise commented 1 month ago

If you use "Res.Write_Header ()" you are like overwriting the header, so it becomes 2 headers, the other header is run using uwebsocket in the source native.py file that connects uwebsocket

cirospaciari commented 1 month ago

This is a issue with uWS we will move to using a customized version, so we can set the Server header as a server option.

stancikcom commented 4 weeks ago

@cirospaciari why not to simply modify this macro?

#ifndef UWS_HTTPRESPONSE_NO_WRITEMARK
        if (!Super::getLoopData()->noMark) {
            /* We only expose major version */
            writeHeader("uWebSockets", "20");
        }
#endif

in this file in https://github.com/uNetworking/uWebSockets/blob/master/src/HttpResponse.h

RajaSunrise commented 3 weeks ago

wow, that's amazing bro, you must check the uwebsockets code one by one

cirospaciari commented 2 weeks ago

This is pretty easy to fix, before sending the body (write/send/end) we need to check if we already sent the Server header, if not will use the default, will add a option to hide this server header if someone just dont wanna to see "uWebSockets" ou "socketify" on it.