1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-04-14 01:29:17 -04:00

Some code improvements

* Rewrite empty string checks more idiomatically.
* Change strings.ToLower comparisons to strings.EqualFold.
* Rewrite switch statement with only one case as if.
This commit is contained in:
Kirill Motkov
2019-06-14 16:47:28 +03:00
parent 4c93d36d49
commit 0401a91ef4
26 changed files with 38 additions and 39 deletions

View File

@@ -120,11 +120,11 @@ Start:
}
defaultPort := net.Port(80)
if strings.ToLower(request.URL.Scheme) == "https" {
if strings.EqualFold(request.URL.Scheme, "https") {
defaultPort = net.Port(443)
}
host := request.Host
if len(host) == 0 {
if host == "" {
host = request.URL.Host
}
dest, err := http_proto.ParseHost(host, defaultPort)
@@ -137,7 +137,7 @@ Start:
Status: log.AccessAccepted,
})
if strings.ToUpper(request.Method) == "CONNECT" {
if strings.EqualFold(request.Method, "CONNECT") {
return s.handleConnect(ctx, request, reader, conn, dest, dispatcher)
}
@@ -211,7 +211,7 @@ func (s *Server) handleConnect(ctx context.Context, request *http.Request, reade
var errWaitAnother = newError("keep alive")
func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, writer io.Writer, dest net.Destination, dispatcher routing.Dispatcher) error {
if !s.config.AllowTransparent && len(request.URL.Host) <= 0 {
if !s.config.AllowTransparent && request.URL.Host == "" {
// RFC 2068 (HTTP/1.1) requires URL to be absolute URL in HTTP proxy.
response := &http.Response{
Status: "Bad Request",
@@ -235,7 +235,7 @@ func (s *Server) handlePlainHTTP(ctx context.Context, request *http.Request, wri
http_proto.RemoveHopByHopHeaders(request.Header)
// Prevent UA from being set to golang's default ones
if len(request.Header.Get("User-Agent")) == 0 {
if request.Header.Get("User-Agent") == "" {
request.Header.Set("User-Agent", "")
}