func TestContextMustReader(t *testing.T) { mr := config.NewMockReader() ctx := context.WithValue(context.Background(), config.CtxKeyReader, mr) assert.Exactly(t, mr, config.ContextMustReader(ctx)) defer func() { if r := recover(); r != nil { assert.EqualError(t, r.(error), config.ErrTypeAssertionReaderFailed.Error()) } }() ctx = context.WithValue(context.Background(), config.CtxKeyReader, "Hello") config.ContextMustReader(ctx) }
// IsSecure checks if a request has been sent over a TLS connection. Also checks // if the app runs behind a proxy server and therefore checks the off loader header. func IsSecure(ctx context.Context, r *http.Request) bool { // due to import cycle this function must be in this package if r.TLS != nil { return true } oh := config.ContextMustReader(ctx).GetString(config.Path(PathOffloaderHeader), config.ScopeDefault()) h := r.Header.Get(oh) hh := r.Header.Get("HTTP_" + oh) var isHttps bool switch "https" { case h, hh: isHttps = true } return isHttps }