Skip to content

Instantly share code, notes, and snippets.

@178inaba
Created December 4, 2021 15:46
Show Gist options
  • Save 178inaba/8d2d79c70f84eb06020f0cd39fc8e9b7 to your computer and use it in GitHub Desktop.
Save 178inaba/8d2d79c70f84eb06020f0cd39fc8e9b7 to your computer and use it in GitHub Desktop.
Original http status text by `http.Hijacker`.
package main
import (
"fmt"
"log"
"net/http"
)
func indexHandler(w http.ResponseWriter, req *http.Request) {
hj, ok := w.(http.Hijacker)
if !ok {
http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError)
return
}
conn, bufrw, err := hj.Hijack()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer conn.Close()
fmt.Fprint(bufrw, `HTTP/1.1 808 Double Not Found
Date: Wed, 26 Nov 2014 03:37:57 GMT
Content-Length: 26
Content-Type: application/json; charset=utf-8
{"error_message":"error?"}`)
bufrw.Flush()
}
func main() {
http.HandleFunc("/", indexHandler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment