Closed
Description
I'd like to extract part of ListenAndServe
and ListenAndServeTLS
into separate
Listen
and ListenTLS
methods, respectively. This would make it possible to call
syscall.Setuid
after listening on a privileged port.
For example:
package main
import (
"fmt"
"net/http"
"syscall"
)
func handle(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello! I'm UID 501.")
}
func main() {
s := http.Server{
Addr: ":80",
Handler: http.HandlerFunc(handle),
}
ln, err := s.Listen()
if err != nil {
panic(err)
}
syscall.Setuid(501)
s.Serve(ln)
}
I have written a patch, but wanted to check if it's a reasonable idea before submitting it.