Skip to content

Commit

Permalink
set scheme order based on X-Forwarded-Proto header
Browse files Browse the repository at this point in the history
  • Loading branch information
tgunsch committed Sep 13, 2023
1 parent 7b0e1f5 commit 297ec21
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// @title httPod
// @version 0.0.8
// @version 1.0.0
// @description A simple HTTP Request & HTTPResponse Service, shamelessly stolen from httpbin.org.
// @tag.name HTTP Methods
// @tag.description Testing different HTTP methods
Expand Down Expand Up @@ -90,9 +90,14 @@ func swaggerMiddleware(path string) echo.MiddlewareFunc {
return func(c echo.Context) error {
if strings.HasSuffix(c.Request().URL.Path, "index.html") {

_, host := util.GetSchemeHost(c.Request())
scheme, host := util.GetSchemeHost(c.Request())
docs.SwaggerInfo.Host = host
docs.SwaggerInfo.Schemes = []string{"http", "https"}
switch scheme {
case "https", "HTTPS":
docs.SwaggerInfo.Schemes = []string{"https", "http"}
default:
docs.SwaggerInfo.Schemes = []string{"http", "https"}
}

docs.SwaggerInfo.BasePath = util.GetPath(path, c.Request())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A simple HTTP Request \u0026 HTTPResponse Service, shamelessly stolen from httpbin.org.",
"title": "httPod",
"contact": {},
"version": "0.0.8"
"version": "1.0.0"
},
"paths": {
"/cookies": {
Expand Down
2 changes: 1 addition & 1 deletion internal/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ info:
description: A simple HTTP Request & HTTPResponse Service, shamelessly stolen from
httpbin.org.
title: httPod
version: 0.0.8
version: 1.0.0
paths:
/cookies:
get:
Expand Down

0 comments on commit 297ec21

Please sign in to comment.