Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1499

Is it safe to use multiple listeners (HTTP and HTTPS) for a server with the default ServeMux in Go?

$
0
0

I'm trying to set up an HTTP and HTTPS server on a Go application using http.server with default http.ServeMux. Specifically, I want one listener to handle HTTP traffic and the other to handle HTTPS traffic. However, I'm concerned about the safety and performance implications of running both listeners on the same server.

Is it safe and advisable to use multiple listeners in this way? Are there any potential issues with the default http.ServeMux when handling both HTTP and HTTPS requests simultaneously?

I tried creating separate listeners for HTTP and HTTPS.

server := &http.server{  ...} // http serverhttpListener, err := net.Listen("tcp", ":8080") // Http listenerhttpsListener, err := net.Listen("tcp", ":8081") // Https listenerwg := &sync.WaitGroup{}wg.Add(2)// Start the http and https server via different go-routinesgo func(){   defer wg.Done()   server.ServerTLS(httpsListener, certFile, keyFile)}go func(){   defer wg.Done()   server.Serve(httpListener)}wg.Wait()

I expected it to work, but I'm uncertain whether this setup is safe or if it might cause any issues with concurrency, security, or the mux itself.


Viewing all articles
Browse latest Browse all 1499

Trending Articles