@@ -18,9 +18,6 @@ import (
18
18
"fmt"
19
19
"io"
20
20
"math"
21
- "os"
22
- "strconv"
23
- "strings"
24
21
"time"
25
22
)
26
23
@@ -322,31 +319,12 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
322
319
pktLen += n + 1
323
320
}
324
321
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
-
348
322
// 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 )
350
328
351
329
// Calculate packet length and get buffer with that size
352
330
data , err := mc .buf .takeSmallBuffer (pktLen + 4 )
@@ -425,9 +403,9 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
425
403
pos ++
426
404
427
405
// Connection Attributes
428
- data [pos ] = byte (len (connAttrsBuf ))
406
+ data [pos ] = byte (len (mc . connector . encodedAttributes ))
429
407
pos ++
430
- pos += copy (data [pos :], connAttrsBuf )
408
+ pos += copy (data [pos :], [] byte ( mc . connector . encodedAttributes ) )
431
409
432
410
// Send Auth packet
433
411
return mc .writePacket (data [:pos ])
0 commit comments