Documentation ¶
Overview ¶
http is listening on two sockets if the server is set to use a wildcard bind to accept both IPv4 and IPv6 traffic. This enables the proper use of ListenAndServe from net/http of the standard library in a portable approach.
By default, OpenBSD, NetBSD, DragonflyBSD and others do not route IPv4 traffic to AF_INET6 sockets. This default behavior intentionally violates RFC 2553 for security reasons.
It is recommended to listen to two sockets, one for AF_INET and another for AF_INET6, when you would like to accept both IPv4 and IPv6 traffic.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServeIPv4 ¶
ListenAndServeIPv4 uses IPv4only.
Example ¶
ListenAndServeIPv4 with specific IPv4 for http on non-default port 8080.
package main import ( "net/http" httpd "catinello.eu/http" ) func main() { if err := httpd.ListenAndServeIPv4(&http.Server{Addr: "192.0.2.10:8080"}); err != nil { panic(err) } }
Output:
func ListenAndServeIPv4TLS ¶
ListenAndServeIPv4TLS uses IPv4only and uses TLS.
func ListenAndServeIPv6 ¶
ListenAndServeIPv6 uses IPv6only.
Example ¶
ListenAndServeIPv6 with specific IPv6 for http on non-default port 8080.
package main import ( "net/http" httpd "catinello.eu/http" ) func main() { if err := httpd.ListenAndServeIPv6(&http.Server{Addr: "[2001:db8::1010]:8080"}); err != nil { panic(err) } }
Output:
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds the *http.Server config and all dual-stack information.
func (*Server) Bind ¶
Bind is primarily set via *http.Server config, but can be manipulated by passing a addr:port string (192.0.2.10:8443 / [2001:db8::1010]:8080) which disables the other network stack that the address is not attributable to.
Example ¶
Bind to IPv6 localhost only on port 8080.
package main import ( "net/http" httpd "catinello.eu/http" ) func main() { web := httpd.New(&http.Server{}) if err := web.Bind("[::1]:8080"); err != nil { panic(err) } if err := web.ListenAndServe(); err != nil { panic(err) } }
Output:
func (*Server) DisableIPv4 ¶
func (s *Server) DisableIPv4()
DisableIPv4 turns off the IPv4 listening and serve.
Example ¶
package main import ( "fmt" "net/http" httpd "catinello.eu/http" ) func main() { web := httpd.New(&http.Server{}) web.DisableIPv4() fmt.Println(web.Stack()) }
Output: false true
func (*Server) DisableIPv6 ¶
func (s *Server) DisableIPv6()
DisableIPv6 turns off the IPv6 listening and serve.
Example ¶
package main import ( "fmt" "net/http" httpd "catinello.eu/http" ) func main() { web := httpd.New(&http.Server{}) web.DisableIPv6() fmt.Println(web.Stack()) }
Output: true false
func (*Server) ListenAndServe ¶
ListenAndServe
https://pkg.go.dev/net/http#ListenAndServe
Example ¶
ListenAndServe with wildcard on http default port 80.
package main import ( "net/http" httpd "catinello.eu/http" ) func main() { web := httpd.New(&http.Server{}) if err := web.ListenAndServe(); err != nil { panic(err) } }
Output: