Browse Source

bug fixes in sniffer

Darien Raymond 8 năm trước cách đây
mục cha
commit
7c59b2e224
2 tập tin đã thay đổi với 5 bổ sung7 xóa
  1. 4 6
      app/dispatcher/impl/default.go
  2. 1 1
      app/dispatcher/impl/sniffer.go

+ 4 - 6
app/dispatcher/impl/default.go

@@ -70,13 +70,11 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
 	} else {
 		go func() {
 			domain, err := snifer(ctx, sniferList, outbound)
-			if err != nil {
-				log.Trace(newError("failed to snif").Base(err))
-				return
+			if err == nil {
+				log.Trace(newError("sniffed domain: ", domain))
+				destination.Address = net.ParseAddress(domain)
+				ctx = proxy.ContextWithTarget(ctx, destination)
 			}
-			log.Trace(newError("sniffed domain: ", domain))
-			destination.Address = net.ParseAddress(domain)
-			ctx = proxy.ContextWithTarget(ctx, destination)
 			d.routedDispatch(ctx, outbound, destination)
 		}()
 	}

+ 1 - 1
app/dispatcher/impl/sniffer.go

@@ -45,7 +45,7 @@ func SniffHTTP(b []byte) (string, error) {
 		value := strings.ToLower(string(bytes.Trim(parts[1], " ")))
 		if key == "host" {
 			domain := strings.Split(value, ":")
-			return domain[0], nil
+			return strings.TrimSpace(domain[0]), nil
 		}
 	}
 	return "", ErrMoreData