Skip to content

[BUG] fix: len(buf) => cap(buf) #973

@BaiZe1998

Description

@BaiZe1998

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Description

len(buf) must equal to 0 for AvailableBuffer()

// AvailableBuffer returns an empty buffer with b.Available() capacity.
// This buffer is intended to be appended to and
// passed to an immediately succeeding [Writer.Write] call.
// The buffer is only valid until the next write operation on b.
func (b *Writer) AvailableBuffer() []byte {
	return b.buf[b.n:][:0]
}

i think the len(buf) may switch to cap(buf) ?

https://github.com/gorilla/websocket/blob/main/server.go#L208

buf := brw.Writer.AvailableBuffer()

var writeBuf []byte
if u.WriteBufferPool == nil && u.WriteBufferSize == 0 && len(buf) >= maxFrameHeaderSize+256 {
    // Reuse hijacked write buffer as connection buffer.
    writeBuf = buf
}

i commit a fix pr: #972

Expected Behavior

No response

Steps To Reproduce

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions