Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fangliding authored Sep 13, 2024
1 parent 72f00b1 commit 484fbb5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions common/protocol/http/sniff.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func SniffHTTP(b []byte, c context.Context) (*SniffHeader, error) {
}
key := strings.ToLower(string(parts[0]))
value := string(bytes.TrimSpace(parts[1]))
content.SetAttribute(key, value) // Put header in attribute
if content != nil {
content.SetAttribute(key, value) // Put header in attribute
}
if key == "host" {
rawHost := strings.ToLower(value)
dest, err := ParseHost(rawHost, net.Port(80))
Expand All @@ -93,7 +95,7 @@ func SniffHTTP(b []byte, c context.Context) (*SniffHeader, error) {
// Parse request line
// Request line is like this
// "GET /homo/114514 HTTP/1.1"
if len(headers) > 0 {
if len(headers) > 0 && content != nil {
RequestLineParts := bytes.Split(headers[0], []byte{' '})
if len(RequestLineParts) == 3 {
content.SetAttribute(":method", string(RequestLineParts[0]))
Expand Down
3 changes: 2 additions & 1 deletion common/protocol/http/sniff_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package http_test

import (
"context"
"testing"

. "github.com/xtls/xray-core/common/protocol/http"
Expand Down Expand Up @@ -88,7 +89,7 @@ first_name=John&last_name=Doe&action=Submit`,
}

for _, test := range cases {
header, err := SniffHTTP([]byte(test.input))
header, err := SniffHTTP([]byte(test.input), context.TODO())
if test.err {
if err == nil {
t.Errorf("Expect error but nil, in test: %v", test)
Expand Down

0 comments on commit 484fbb5

Please sign in to comment.