Skip to content

Commit

Permalink
Parse url path to extract query parameters from filename when calling…
Browse files Browse the repository at this point in the history
… embed.FS (#103)

* add oauth redirect test case

* fix: parse url path to exclude query params from filename
  • Loading branch information
sapk authored Aug 26, 2023
1 parent 1bc40aa commit 05e75a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package httpSwagger
import (
"html/template"
"net/http"
"net/url"
"path/filepath"
"regexp"

Expand Down Expand Up @@ -213,7 +214,13 @@ func Handler(configFns ...func(*Config)) http.HandlerFunc {
case "":
http.Redirect(w, r, matches[1]+"/"+"index.html", http.StatusMovedPermanently)
default:
r.URL.Path = matches[2]
var err error
r.URL, err = url.Parse(matches[2])
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)

return
}
http.FileServer(http.FS(swaggerFiles.FS)).ServeHTTP(w, r)
}
}
Expand Down
4 changes: 4 additions & 0 deletions swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func TestWrapHandler(t *testing.T) {
assert.Equal(t, http.StatusOK, w5.Code)
assert.Equal(t, w5.Header()["Content-Type"][0], "application/javascript")

w6 := performRequest(http.MethodGet, test.RootFolder+"oauth2-redirect.html?state=0&session_state=1&code=2", router)
assert.Equal(t, http.StatusOK, w6.Code)
assert.Equal(t, w6.Header()["Content-Type"][0], "text/html; charset=utf-8")

assert.Equal(t, http.StatusNotFound, performRequest(http.MethodGet, test.RootFolder+"notfound", router).Code)

assert.Equal(t, 301, performRequest(http.MethodGet, test.RootFolder, router).Code)
Expand Down

0 comments on commit 05e75a5

Please sign in to comment.