@@ -18,9 +18,6 @@ import (
1818 "fmt"
1919 "io"
2020 "math"
21- "os"
22- "strconv"
23- "strings"
2421 "time"
2522)
2623
@@ -322,31 +319,12 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
322319 pktLen += n + 1
323320 }
324321
325- connAttrsBuf := make ([]byte , 0 , 100 )
326-
327- // default connection attributes
328- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , connAttrClientName )
329- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , connAttrClientNameValue )
330- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , connAttrOS )
331- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , connAttrOSValue )
332- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , connAttrPlatform )
333- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , connAttrPlatformValue )
334- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , connAttrPid )
335- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , strconv .Itoa (os .Getpid ()))
336-
337- // user-defined connection attributes
338- for _ , connAttr := range strings .Split (mc .cfg .ConnectionAttributes , "," ) {
339- attr := strings .Split (connAttr , ":" )
340- if len (attr ) != 2 {
341- continue
342- }
343- for _ , v := range attr {
344- connAttrsBuf = appendLengthEncodedString (connAttrsBuf , v )
345- }
346- }
347-
348322 // 1 byte to store length of all key-values
349- pktLen += len (connAttrsBuf ) + 1
323+ // NOTE: Actually, this is length encoded integer.
324+ // But we support only len(connAttrBuf) < 251 for now because takeSmallBuffer
325+ // doesn't support buffer size more than 4096 bytes.
326+ // TODO(methane): Rewrite buffer management.
327+ pktLen += 1 + len (mc .connector .encodedAttributes )
350328
351329 // Calculate packet length and get buffer with that size
352330 data , err := mc .buf .takeSmallBuffer (pktLen + 4 )
@@ -425,9 +403,9 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
425403 pos ++
426404
427405 // Connection Attributes
428- data [pos ] = byte (len (connAttrsBuf ))
406+ data [pos ] = byte (len (mc . connector . encodedAttributes ))
429407 pos ++
430- pos += copy (data [pos :], connAttrsBuf )
408+ pos += copy (data [pos :], [] byte ( mc . connector . encodedAttributes ) )
431409
432410 // Send Auth packet
433411 return mc .writePacket (data [:pos ])
0 commit comments