[Python] using socket.shutdown(1) is preventing web server from sending responses

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm making a proxy which sits between the browser and the web. There's a snippet of code I can't seem to get to work.

    #send request to web server
    web_client.send(request)
    #signal client is done with sending
    web_client.shutdown(1)


    If I use shutdown(1), the proxy has a great improvement in performance and speed. However, some web servers do not send responses if I use shutdown. Console output:

    request sent to host wix.com
    got response packet of len 0
    got response packet of len 0
    breaking loop


    and the browser displays

    The connection was reset
    The connection to the server was reset while the page was loading.


    However, if I remove shutdown(1), there are no problems of sort. Console output:

    got response packet of len 1388
    got response packet of len 1388
    got response packet of len 1388
    got response packet of len 989
    got response packet of len 0
    got response packet of len 0
    breaking loop


    and the browser normally displays the website. Why is this happening? This is only happening on certain hosts.

    Continue reading...

Compartilhe esta Página