@@ -144,16 +144,25 @@ func (handler *DefaultResponseHandler) handleResponse(dst DeadlineWriter, src De
144144 if err != nil {
145145 return true , err
146146 }
147+ responseHeaderTaggedFields , err := protocol .NewResponseHeaderTaggedFields (requestKeyVersion )
148+ if err != nil {
149+ return true , err
150+ }
151+ unknownTaggedFields , err := responseHeaderTaggedFields .MaybeRead (src )
152+ if err != nil {
153+ return true , err
154+ }
155+ readResponsesHeaderLength := int32 (4 + len (unknownTaggedFields )) // 4 = Length + CorrelationID
147156
148157 responseModifier , err := protocol .GetResponseModifier (requestKeyVersion .ApiKey , requestKeyVersion .ApiVersion , ctx .netAddressMappingFunc )
149158 if err != nil {
150159 return true , err
151160 }
152161 if responseModifier != nil {
153- if int32 ( responseHeader .Length ) > protocol .MaxResponseSize {
162+ if responseHeader .Length > protocol .MaxResponseSize {
154163 return true , protocol.PacketDecodingError {Info : fmt .Sprintf ("message of length %d too large" , responseHeader .Length )}
155164 }
156- resp := make ([]byte , int (responseHeader .Length - 4 ))
165+ resp := make ([]byte , int (responseHeader .Length - readResponsesHeaderLength ))
157166 if _ , err = io .ReadFull (src , resp ); err != nil {
158167 return true , err
159168 }
@@ -162,13 +171,16 @@ func (handler *DefaultResponseHandler) handleResponse(dst DeadlineWriter, src De
162171 return true , err
163172 }
164173 // add 4 bytes (CorrelationId) to the length
165- newHeaderBuf , err := protocol .Encode (& protocol.ResponseHeader {Length : int32 (len (newResponseBuf ) + 4 ), CorrelationID : responseHeader .CorrelationID })
174+ newHeaderBuf , err := protocol .Encode (& protocol.ResponseHeader {Length : int32 (len (newResponseBuf ) + int ( readResponsesHeaderLength ) ), CorrelationID : responseHeader .CorrelationID })
166175 if err != nil {
167176 return true , err
168177 }
169178 if _ , err := dst .Write (newHeaderBuf ); err != nil {
170179 return false , err
171180 }
181+ if _ , err := dst .Write (unknownTaggedFields ); err != nil {
182+ return false , err
183+ }
172184 if _ , err := dst .Write (newResponseBuf ); err != nil {
173185 return false , err
174186 }
@@ -177,8 +189,11 @@ func (handler *DefaultResponseHandler) handleResponse(dst DeadlineWriter, src De
177189 if _ , err := dst .Write (responseHeaderBuf ); err != nil {
178190 return false , err
179191 }
180- // 4 bytes were written as responseHeaderBuf (CorrelationId)
181- if readErr , err = myCopyN (dst , src , int64 (responseHeader .Length - 4 ), ctx .buf ); err != nil {
192+ if _ , err := dst .Write (unknownTaggedFields ); err != nil {
193+ return false , err
194+ }
195+ // 4 bytes were written as responseHeaderBuf (CorrelationId) + tagged fields
196+ if readErr , err = myCopyN (dst , src , int64 (responseHeader .Length - readResponsesHeaderLength ), ctx .buf ); err != nil {
182197 return readErr , err
183198 }
184199 }
0 commit comments