#How to upgrade already listening HTTP server to HTTPS?

15 messages · Page 1 of 1 (latest)

novel forge
#

servver.ListenAndServe() is called already, then I decide that it should be HTTPS, not HTTP. Is it possible upgrade to HTTPS the existing listening HTTP server providing all necessary stuff like TLSConfig without restarting?

#

How to upgrade already listening HTTP server to HTTPS?

elfin solstice
novel forge
elfin solstice
#

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

elfin solstice
#

I think the question is about doing this change when the http server already started

#

not just how you call ListenAndServeTLS

sand knoll
#

@elfin solstice Oh I guess I misread that

heavy island
#

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

elfin solstice
#

you can implement your own proxy listener