From 629990daa33ae01adc1d520aa995487e1213bdc3 Mon Sep 17 00:00:00 2001 From: mstmdev Date: Thu, 9 Nov 2023 19:42:05 +0800 Subject: [PATCH] Use status code constant (#864) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What type of PR is this? (check all applicable) - [x] Refactor - [ ] Feature - [ ] Bug Fix - [ ] Optimization - [ ] Documentation Update - [ ] Go Version Update - [ ] Dependency Update ## Description ## Related Tickets & Documents - Related Issue # - Closes # ## Added/updated tests? - [ ] Yes - [x] No - [ ] I need help with writing tests ## Run verifications and test - [ ] `make verify` is passing - [ ] `make test` is passing --- client.go | 2 +- proxy.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 815b0ca5..dbca164a 100644 --- a/client.go +++ b/client.go @@ -399,7 +399,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h } } - if resp.StatusCode != 101 || + if resp.StatusCode != http.StatusSwitchingProtocols || !tokenListContainsValue(resp.Header, "Upgrade", "websocket") || !tokenListContainsValue(resp.Header, "Connection", "upgrade") || resp.Header.Get("Sec-Websocket-Accept") != computeAcceptKey(challengeKey) { diff --git a/proxy.go b/proxy.go index 80f55d1e..b6af21f9 100644 --- a/proxy.go +++ b/proxy.go @@ -75,7 +75,7 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error) return nil, err } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { if err := conn.Close(); err != nil { log.Printf("httpProxyDialer: failed to close connection: %v", err) }