Skip to content

Commit

Permalink
#703 also take tls reqs into account
Browse files Browse the repository at this point in the history
  • Loading branch information
malud committed Feb 3, 2023
1 parent 8ea8f09 commit c991456
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ func (s *HTTPServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

req.URL.Host = req.Host
req.URL.Scheme = "http"
if req.TLS != nil && req.TLS.HandshakeComplete {
req.URL.Scheme += "s"
}

if s.settings.AcceptsForwardedProtocol() {
if xfpr := req.Header.Get("X-Forwarded-Proto"); xfpr != "" {
req.URL.Scheme = xfpr
Expand Down
4 changes: 4 additions & 0 deletions server/http_mtls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func TestHTTPSServer_TLS_ServerCertificate(t *testing.T) {
if res.StatusCode != http.StatusOK {
t.Errorf("Expected statusOK, got: %d", res.StatusCode)
}

if !strings.HasPrefix(res.Header.Get("Location"), "https://") {
t.Errorf("Expected https scheme in url variable value, got: %s", res.Header.Get("Location"))
}
}

func TestHTTPSServer_TLS_ServerClientCertificate(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion server/testdata/mtls/02_couper.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ server {
hosts = ["*:4443"]

endpoint "/" {
response {}
response {
headers = {
location = request.url
}
}
}

tls {
Expand Down

0 comments on commit c991456

Please sign in to comment.