Skip to content

Commit

Permalink
Skip HTTP inbound PlainHTTP mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Fangliding authored Sep 13, 2024
1 parent 484fbb5 commit 9669ece
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions common/protocol/http/sniff.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func beginWithHTTPMethod(b []byte) error {

func SniffHTTP(b []byte, c context.Context) (*SniffHeader, error) {
content := session.ContentFromContext(c)
ShouldSniffAttr := true
// If content.Attributes have information, that means it comes from HTTP inbound PlainHTTP mode.
// It will set sttributes, so skip it.
if len(content.Attributes) != 0 || content == nil {
ShouldSniffAttr = false
}
if err := beginWithHTTPMethod(b); err != nil {
return nil, err
}
Expand All @@ -80,7 +86,7 @@ func SniffHTTP(b []byte, c context.Context) (*SniffHeader, error) {
}
key := strings.ToLower(string(parts[0]))
value := string(bytes.TrimSpace(parts[1]))
if content != nil {
if ShouldSniffAttr {
content.SetAttribute(key, value) // Put header in attribute
}
if key == "host" {
Expand All @@ -95,7 +101,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 && content != nil {
if len(headers) > 0 && ShouldSniffAttr {
RequestLineParts := bytes.Split(headers[0], []byte{' '})
if len(RequestLineParts) == 3 {
content.SetAttribute(":method", string(RequestLineParts[0]))
Expand Down

0 comments on commit 9669ece

Please sign in to comment.