Skip to content

Commit

Permalink
fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorLieberman committed Nov 22, 2022
1 parent 0ccda9d commit c1c4952
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
8 changes: 4 additions & 4 deletions conformance/tests/httproute-request-redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ var HTTPRouteRequestRedirect = suite.ConformanceTest{

testCases := []http.ExpectedResponse{{
Request: http.Request{
Path: "/hostname",
UnFollowRedirect: true,
Path: "/hostname-redirect",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
Expand All @@ -57,7 +57,7 @@ var HTTPRouteRequestRedirect = suite.ConformanceTest{
}, {
Request: http.Request{
Path: "/status-code-301",
UnFollowRedirect: true,
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
Expand All @@ -67,7 +67,7 @@ var HTTPRouteRequestRedirect = suite.ConformanceTest{
}, {
Request: http.Request{
Path: "/host-and-status",
UnFollowRedirect: true,
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
Expand Down
4 changes: 2 additions & 2 deletions conformance/tests/httproute-request-redirect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
- matches:
- path:
type: PathPrefix
value: /hostname
value: /hostname-redirect
filters:
- type: RequestRedirect
requestRedirect:
Expand All @@ -37,4 +37,4 @@ spec:
hostname: example.org
backendRefs:
- name: infra-backend-v1
port: 8080
port: 8080
4 changes: 2 additions & 2 deletions conformance/utils/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Request struct {
Method string
Path string
Headers map[string]string
UnFollowRedirect bool
UnfollowRedirect bool
}

// ExpectedRequest defines expected properties of a request that reaches a backend.
Expand Down Expand Up @@ -114,7 +114,7 @@ func MakeRequestAndExpectEventuallyConsistentResponse(t *testing.T, r roundtripp
URL: url.URL{Scheme: "http", Host: gwAddr, Path: path, RawQuery: query},
Protocol: "HTTP",
Headers: map[string][]string{},
UnFollowRedirect: expected.Request.UnFollowRedirect,
UnfollowRedirect: expected.Request.UnfollowRedirect,
}

if expected.Request.Headers != nil {
Expand Down
21 changes: 12 additions & 9 deletions conformance/utils/roundtripper/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Request struct {
Protocol string
Method string
Headers map[string][]string
UnFollowRedirect bool
UnfollowRedirect bool
}

// CapturedRequest contains request metadata captured from an echoserver
Expand All @@ -58,6 +58,8 @@ type CapturedRequest struct {
Pod string `json:"pod"`
}

// RedirectRequest contains a follow up request metadata captured from a redirect
// response.
type RedirectRequest struct {
Scheme string
Hostname string
Expand Down Expand Up @@ -88,7 +90,7 @@ func (d *DefaultRoundTripper) CaptureRoundTrip(request Request) (*CapturedReques
cReq := &CapturedRequest{}
client := http.DefaultClient

if request.UnFollowRedirect {
if request.UnfollowRedirect {
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
Expand Down Expand Up @@ -173,13 +175,7 @@ func (d *DefaultRoundTripper) CaptureRoundTrip(request Request) (*CapturedReques
return cReq, cRes, nil
}

var startLineRegex = regexp.MustCompile(`(?m)^`)

func formatDump(data []byte, prefix string) string {
data = startLineRegex.ReplaceAllLiteral(data, []byte(prefix))
return string(data)
}

// IsRedirect returns true if a given status code is a redirect code supported by the gateway api.
func IsRedirect(statusCode int) bool {
// Gateway allows only 301, and 302
switch statusCode {
Expand All @@ -190,3 +186,10 @@ func IsRedirect(statusCode int) bool {

return false
}

var startLineRegex = regexp.MustCompile(`(?m)^`)

func formatDump(data []byte, prefix string) string {
data = startLineRegex.ReplaceAllLiteral(data, []byte(prefix))
return string(data)
}

0 comments on commit c1c4952

Please sign in to comment.