Copilot can almost write an HTTP server. Here is how I did it:
1. Start a new python file with the line "# This is an implementation of an HTTP server"
2. Press autocomplete a bunch of times and stop somewhere when "enough" libraries are imported
3. Press "#" and let it autocomplete the comment about what comes next (global variables for PORT and BUFFER_SIZE in my case)
4. Again, Press "#" and let it autocomplete a bunch of comments and functions ("get_file_extension", "get_file_content_type", "get_file_size" in my case)
5. At this step, I had to cheat a bit since it was generating too many "get_*" functions, so I started a comment with "# Initialize" and let it autocomplete again to get "init_server_socket"
6. From here on, it generated handle_request, parse_request, get_file_path and send_response automatically.
7. Lastly, I wrote "def main" and let it autocomplete again.
This produced an HTTP server which almost worked. I just had to fix a small issue with "file_path", since it expected that files were stored in the root directory, but I wanted it to load files from the local directory.
The code is not great since it does not handle most errors gracefully and is vulnerable to directory traversal, but I didn't even have to think about the HTTP protocol while writing it, so it is still quite impressive.
A few good points:
It generated a huge selection of MIME types which I probably would have had to look up by hand.
The generated server is multi-threaded!
It automatically reuses the socket, so I do not have to wait a minute every time I restart the server.
Here is the final code: https://bpa.st/CTRA