How to detect if a request is over http or https?

4,116 views
Skip to first unread message

rwx

unread,
Jul 27, 2013, 6:15:28 AM7/27/13
to golan...@googlegroups.com
Hi,
Using net/http, I call ListenAndServe and ListenAndServeTLS with the same handler to serve both http and https,
I wonder how to detect if a request come in is over http or https?
I have read the source code of net/http and searched in nuts, but found nothing. :(
Maybe hijack is a good idea, but not for me.
Any suggestions?

Thanks.

David Symonds

unread,
Jul 28, 2013, 4:10:04 AM7/28/13
to rwx, golan...@googlegroups.com
Read http://golang.org/pkg/net/http/#Request and check the TLS field
of the *http.Request your handler receives.

深蓝

unread,
Jul 28, 2013, 4:56:22 AM7/28/13
to David Symonds, golan...@googlegroups.com
Yes, you're right! Thank you very much!


2013/7/28 David Symonds <dsym...@golang.org>
Reply all
Reply to author
Forward
0 new messages