mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-10-30 16:13:22 +00: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:
@@ -11,7 +11,7 @@ import (
|
||||
// ParseXForwardedFor parses X-Forwarded-For header in http headers, and return the IP list in it.
|
||||
func ParseXForwardedFor(header http.Header) []net.Address {
|
||||
xff := header.Get("X-Forwarded-For")
|
||||
if len(xff) == 0 {
|
||||
if xff == "" {
|
||||
return nil
|
||||
}
|
||||
list := strings.Split(xff, ",")
|
||||
@@ -38,7 +38,7 @@ func RemoveHopByHopHeaders(header http.Header) {
|
||||
|
||||
connections := header.Get("Connection")
|
||||
header.Del("Connection")
|
||||
if len(connections) == 0 {
|
||||
if connections == "" {
|
||||
return
|
||||
}
|
||||
for _, h := range strings.Split(connections, ",") {
|
||||
|
||||
@@ -44,7 +44,7 @@ var (
|
||||
|
||||
func beginWithHTTPMethod(b []byte) error {
|
||||
for _, m := range &methods {
|
||||
if len(b) >= len(m) && strings.ToLower(string(b[:len(m)])) == m {
|
||||
if len(b) >= len(m) && strings.EqualFold(string(b[:len(m)]), m) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -81,8 +81,7 @@ func ReadClientHello(data []byte, h *SniffHeader) error {
|
||||
return errNotClientHello
|
||||
}
|
||||
|
||||
switch extension {
|
||||
case 0x00: /* extensionServerName */
|
||||
if extension == 0x00 { /* extensionServerName */
|
||||
d := data[:length]
|
||||
if len(d) < 2 {
|
||||
return errNotClientHello
|
||||
|
||||
@@ -51,7 +51,7 @@ func (g *DomainMatcherGroup) addMatcher(m domainMatcher, value uint32) {
|
||||
}
|
||||
|
||||
func (g *DomainMatcherGroup) Match(domain string) uint32 {
|
||||
if len(domain) == 0 {
|
||||
if domain == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user