#How to upgrade already listening HTTP server to HTTPS?
15 messages · Page 1 of 1 (latest)
You can't do that with ListenAndServe.
You need to use a net.Listener so you have access to the raw TCP listener
are you mean to implement http.Server logic manually around net.Listener?
first you accept connections and forward them to a stub type implements net.Listener and pass it to http.Serve
Then when you want to switch you return an error from there and can forward the connections to tls.Server which is then wrapped in http.Serve
I think the question is about doing this change when the http server already started
not just how you call ListenAndServeTLS
@elfin solstice Oh I guess I misread that

http.ListenAndServe is a short cut of http.Serve(net.Listen())
I recommend you to create another http.Server with same configs, shutdown the first http server with context.Background() (which means never close the existing connection, but reject new connections), then ServeTLS it with the listener (accept new https connections).
fine, I forgot you cannot reuse the listener after you shutdown http.Server
So then maybe wrap the net.Listener, or create another listener that on the same address for https server
you can implement your own proxy listener