1

I've read this so question and the example from this so question

Here's my demo:

package main

import (
    "net/http"
)

func main() {
    http.HandleFunc("/", handler1)
    _ = http.ListenAndServe(":8008", nil)
}

func handler1(writer http.ResponseWriter, request *http.Request) {
    hijacker, _ := writer.(http.Hijacker)
    conn, buf, _ := hijacker.Hijack()
    defer conn.Close()
    _, _ = buf.WriteString("hello world")
    _ = buf.Flush()
}

I ran the code with go run serv1.go and sent request with curl, but got HTTP/1.1 502 Bad Gateway. Just wondering if the API has been changed or anything I'd missed?

❯ curl -i "http://localhost:8008/"
HTTP/1.1 502 Bad Gateway
Connection: keep-alive
Keep-Alive: timeout=4
Proxy-Connection: keep-alive
Content-Length: 0
alwaysday1
  • 1,683
  • 5
  • 20
  • 36
  • Using the server and command in the question, curl reports a different and expected error (Received HTTP/0.9 when not allowed). The program does not write an HTTP/1.1 502 as shown in the question. – Charlie Tumahai Jan 21 '23 at 03:43

0 Answers0