Skip to content

Commit

Permalink
Replace the string with constants from the http package (istio#45077)
Browse files Browse the repository at this point in the history
Signed-off-by: Zechun Chen <[email protected]>
  • Loading branch information
Fish-pro committed May 24, 2023
1 parent 8841329 commit be636e5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pilot/pkg/xds/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ func sortMCSServices(svcs []model.MCSServiceInfo) []model.MCSServiceInfo {

func (s *DiscoveryServer) clusterz(w http.ResponseWriter, req *http.Request) {
if s.ListRemoteClusters == nil {
w.WriteHeader(400)
w.WriteHeader(http.StatusBadRequest)
return
}
writeJSON(w, s.ListRemoteClusters(), req)
Expand Down
2 changes: 1 addition & 1 deletion pkg/hbone/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (d *dialer) proxyTo(conn io.ReadWriteCloser, req Config, address string) er
remoteID = ids[0]
}
}
if resp.StatusCode != 200 {
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("round trip failed: %v", resp.Status)
}
log.WithLabels("host", r.Host, "remote", remoteID).Info("CONNECT established")
Expand Down
4 changes: 2 additions & 2 deletions pkg/istio-agent/health/health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func TestWorkloadHealthChecker_PerformApplicationHealthCheck(t *testing.T) {
httpServerEventCount := 0
sss := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
if httpServerEventCount < len(httpHealthStatuses) && httpHealthStatuses[httpServerEventCount] {
writer.WriteHeader(200)
writer.WriteHeader(http.StatusOK)
writer.Write([]byte("foobar"))
} else {
writer.WriteHeader(500)
writer.WriteHeader(http.StatusInternalServerError)
}
httpServerEventCount++
}))
Expand Down
6 changes: 3 additions & 3 deletions pkg/wasm/httpfetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestWasmHTTPFetch(t *testing.T) {
name: "download retry",
handler: func(w http.ResponseWriter, r *http.Request, num int) {
if num <= 2 {
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
} else {
fmt.Fprintln(w, "wasm")
}
Expand All @@ -63,7 +63,7 @@ func TestWasmHTTPFetch(t *testing.T) {
{
name: "download max retry",
handler: func(w http.ResponseWriter, r *http.Request, num int) {
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
},
timeout: 5 * time.Second,
wantNumRequest: 5,
Expand All @@ -72,7 +72,7 @@ func TestWasmHTTPFetch(t *testing.T) {
{
name: "download is never tried by immediate context timeout",
handler: func(w http.ResponseWriter, r *http.Request, num int) {
w.WriteHeader(500)
w.WriteHeader(http.StatusInternalServerError)
},
timeout: 0, // Immediately timeout in the context level.
wantNumRequest: 0, // Should not retried because it is already timed out.
Expand Down
2 changes: 1 addition & 1 deletion security/pkg/stsservice/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (s *Server) validateStsRequest(req *http.Request) (security.StsRequestParam
reqDump, _ := httputil.DumpRequest(debugReq, true)
stsServerLog.Debugf("Received STS request: %s", string(reqDump))
}
if req.Method != "POST" {
if req.Method != http.MethodPost {
return reqParam, fmt.Errorf("request method is invalid, should be POST but get %s", req.Method)
}
if req.Header.Get("Content-Type") != URLEncodedForm {
Expand Down

0 comments on commit be636e5

Please sign in to comment.