In my project I've got a use case when I send (I'm the server) a response to a hardware (the client) and I would like to revert some changes if the client disconnect from the wifi before reading the response.
render.Status(r, http.StatusCreated)
render.Respond(w, r, obj)
I do a respond and from this point on I want to check if the response is lost in the wild or found the client.
I've tried to hijacked it:
hj, ok := w.(http.Hijacker)
if !ok {
http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError)
return
}
logs.Println("2")
conn, bufrw, err := hj.Hijack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = conn.Close()
if err != nil {
logs.Println("LOL", err)
}
...
But I can't catch anything... I've tried to check the w.Write() err without success!
Any idea on how to proceed?