smarterclayton / openshift-go-cart

Go cartridge for OpenShift Origin
Other
75 stars 92 forks source link

HTTP vs HTTPS? #36

Closed trapias closed 6 years ago

trapias commented 8 years ago

Hello, I'm successfully testing this gear, binding just like the sample with

bind := fmt.Sprintf("%s:%s", os.Getenv("OPENSHIFT_GO_IP"), os.Getenv("OPENSHIFT_GO_PORT"))

I see my webapp responds both on HTTP and HTTPS this way. Is it possible for me to understand, in my handlers, if the request comes over the one or the other?

I tried monitoring http.Request.TLS, but it's always nil - also for HTTPS requests. I don't think that's because I'm using a free gear, with a shared certificate, is it?

Thanks for any help, al.

fstanis commented 8 years ago

The TLS field will never be set on OpenShift - you can check the HTTP header X-Forwarded-Proto to determine if the request is sent over a secure connection:

func handle(w http.ResponseWriter, r *http.Request) {
  if r.Header.Get("X-Forwarded-Proto") == "https" {
    ...