MCPcopy Create free account
hub / github.com/pires/go-proxyproto / main

Function main

examples/httpserver/httpserver.go:16–51  ·  view source on GitHub ↗

TODO: add httpclient example

()

Source from the content-addressed store, hash-verified

14// TODO: add httpclient example
15
16func main() {
17 server := http.Server{
18 Addr: ":8080",
19 ReadHeaderTimeout: 5 * time.Second,
20 ConnState: func(c net.Conn, s http.ConnState) {
21 if s == http.StateNew {
22 log.Printf("[ConnState] %s -> %s", c.LocalAddr().String(), c.RemoteAddr().String())
23 }
24 },
25 Handler: http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
26 log.Printf("[Handler] remote ip %q", r.RemoteAddr) //nolint:gosec // G706: RemoteAddr is logged intentionally
27 }),
28 }
29
30 ln, err := net.Listen("tcp", server.Addr)
31 if err != nil {
32 panic(err)
33 }
34
35 proxyListener := &proxyproto.Listener{
36 Listener: ln,
37 ReadHeaderTimeout: 10 * time.Second,
38 }
39 defer func() {
40 if err := proxyListener.Close(); err != nil {
41 log.Printf("failed to close proxy listener: %v", err)
42 }
43 }()
44
45 // Create an HTTP server which can handle proxied incoming connections for
46 // both HTTP/1 and HTTP/2. HTTP/2 support relies on TLS ALPN, the reverse
47 // proxy needs to be configured to accept "h2".
48 if err := h2proxy.NewServer(&server, nil).Serve(proxyListener); err != nil {
49 log.Fatalf("failed to serve: %v", err)
50 }
51}

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
ServeMethod · 0.80
StringMethod · 0.45
LocalAddrMethod · 0.45
RemoteAddrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…