@@ -139,6 +139,20 @@ func (c *Conn) genAuthResponse(authData []byte) ([]byte, bool, error) {
139
139
}
140
140
}
141
141
142
+ // generate connection attributes data
143
+ func (c * Conn ) genAttributes () []byte {
144
+ if len (c .attributes ) == 0 {
145
+ return nil
146
+ }
147
+
148
+ attrData := make ([]byte , 0 )
149
+ for k , v := range c .attributes {
150
+ attrData = append (attrData , PutLengthEncodedString ([]byte (k ))... )
151
+ attrData = append (attrData , PutLengthEncodedString ([]byte (v ))... )
152
+ }
153
+ return append (PutLengthEncodedInt (uint64 (len (attrData ))), attrData ... )
154
+ }
155
+
142
156
// See: http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse
143
157
func (c * Conn ) writeAuthHandshake () error {
144
158
if ! authPluginAllowed (c .authPluginName ) {
@@ -195,6 +209,12 @@ func (c *Conn) writeAuthHandshake() error {
195
209
capability |= CLIENT_CONNECT_WITH_DB
196
210
length += len (c .db ) + 1
197
211
}
212
+ // connection attributes
213
+ attrData := c .genAttributes ()
214
+ if len (attrData ) > 0 {
215
+ capability |= CLIENT_CONNECT_ATTRS
216
+ length += len (attrData )
217
+ }
198
218
199
219
data := make ([]byte , length + 4 )
200
220
@@ -264,6 +284,12 @@ func (c *Conn) writeAuthHandshake() error {
264
284
// Assume native client during response
265
285
pos += copy (data [pos :], c .authPluginName )
266
286
data [pos ] = 0x00
287
+ pos ++
288
+
289
+ // connection attributes
290
+ if len (attrData ) > 0 {
291
+ copy (data [pos :], attrData )
292
+ }
267
293
268
294
return c .WritePacket (data )
269
295
}
0 commit comments