I have this server in golang :
package main
import (
"fmt"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(204)
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
w.Header().Set("Connection", "close")
fmt.Println(r.Close)
}
func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8080", nil)
}
Then I wanted to try to quickly benchmark how it can handle requests whit this python script:
import requests
payload = "test"
while True:
r = requests.post("http://127.0.0.1:8080/test", data = payload)
r.connection.close()
After multiple loops it cannot assign new ports. I deduce that my server doesn't close connection (or my client).
How should I manage connection from server side?