wip
This commit is contained in:
32
httpconn/server.go
Normal file
32
httpconn/server.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package httpconn
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Accept(w http.ResponseWriter, r *http.Request) (net.Conn, error) {
|
||||
if r.Method != "CONNECT" {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
io.WriteString(w, "405 must CONNECT\n")
|
||||
return nil, http.ErrNotSupported
|
||||
}
|
||||
|
||||
hj, ok := w.(http.Hijacker)
|
||||
if !ok {
|
||||
return nil, http.ErrNotSupported
|
||||
}
|
||||
|
||||
conn, _, err := hj.Hijack()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, _ = io.WriteString(conn, "HTTP/1.0 200 OK\n\n")
|
||||
conn.SetDeadline(time.Time{})
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
Reference in New Issue
Block a user