Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Understanding HTTP Server by Implementing in Python (muhammadraza.me)
16 points by todsacerdoti on June 12, 2024 | hide | past | favorite | 2 comments


Hey this is pretty similar to an http server I wrote just a bit ago for a project I'm working on.

server lib: https://github.com/kasrasadeghi/pipeline-js/blob/main/kazhtt...

Used here: https://github.com/kasrasadeghi/pipeline-js/blob/main/simple...

I seem to have some kind of issue with ssl_shutdown, I wrote a packet-level proxy in c++ but I still can't figure out the correct incantation to shutdown on both sides correctly. The Python SSL socket shutdown() function doesn't seem to return anything, so we can't tell if it's finished yet.

I wrote this as an alternative to socketserver.py from the standard library, as I didn't like all of the customization points and indirection.

Also one thing to note is that doing .recv(1024) makes it so that the first line of your http request must be less than 1024 bytes long, which (if you have a lot of query parameters, like I do on some requests) might require you to do some slightly stranger loop shenanigans like I do. It was tricky to figure out, and I don't think it's a completely generalizable solution, but I heavily recommend something like it for anyone dealing with the same problem.


Really well done, enjoyed it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: