mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-25 01:51:28 +00:00
Fix: Apply mutex when visiting Attributes as well (#3921)
https://github.com/XTLS/Xray-core/pull/3921#issuecomment-2445689462
This commit is contained in:
parent
ceb6eac8e7
commit
9f8bb47633
|
@ -63,7 +63,7 @@ func SniffHTTP(b []byte, c context.Context) (*SniffHeader, error) {
|
||||||
ShouldSniffAttr := true
|
ShouldSniffAttr := true
|
||||||
// If content.Attributes have information, that means it comes from HTTP inbound PlainHTTP mode.
|
// If content.Attributes have information, that means it comes from HTTP inbound PlainHTTP mode.
|
||||||
// It will set attributes, so skip it.
|
// It will set attributes, so skip it.
|
||||||
if content == nil || len(content.Attributes) != 0 {
|
if content == nil || content.AttributeLen() != 0 {
|
||||||
ShouldSniffAttr = false
|
ShouldSniffAttr = false
|
||||||
}
|
}
|
||||||
if err := beginWithHTTPMethod(b); err != nil {
|
if err := beginWithHTTPMethod(b); err != nil {
|
||||||
|
|
|
@ -128,8 +128,24 @@ func (c *Content) SetAttribute(name string, value string) {
|
||||||
|
|
||||||
// Attribute retrieves additional string attributes from content.
|
// Attribute retrieves additional string attributes from content.
|
||||||
func (c *Content) Attribute(name string) string {
|
func (c *Content) Attribute(name string) string {
|
||||||
|
c.mu.Lock()
|
||||||
|
c.isLocked = true
|
||||||
|
defer func() {
|
||||||
|
c.isLocked = false
|
||||||
|
c.mu.Unlock()
|
||||||
|
}()
|
||||||
if c.Attributes == nil {
|
if c.Attributes == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return c.Attributes[name]
|
return c.Attributes[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Content) AttributeLen() int {
|
||||||
|
c.mu.Lock()
|
||||||
|
c.isLocked = true
|
||||||
|
defer func() {
|
||||||
|
c.isLocked = false
|
||||||
|
c.mu.Unlock()
|
||||||
|
}()
|
||||||
|
return len(c.Attributes)
|
||||||
|
}
|
Loading…
Reference in a new issue