THRIFT-4914: Add GetResponseHeadersFromClient helper function

This is the fourth and final part of THRIFT-4914, which handles the
client reading part in the response (server -> client direction).

Client: go

This closes #1926.
This commit is contained in:
Yuxuan 'fishy' Wang 2019-11-09 14:21:10 -08:00 committed by Duru Can Celasun
parent 59694a796f
commit 24fa9d0728

View File

@ -303,3 +303,17 @@ func (p *THeaderProtocol) ReadBinary() (value []byte, err error) {
func (p *THeaderProtocol) Skip(fieldType TType) error {
return p.protocol.Skip(fieldType)
}
// GetResponseHeadersFromClient is a helper function to get the read THeaderMap
// from the last response received from the given client.
//
// If the last response was not sent over THeader protocol,
// a nil map will be returned.
func GetResponseHeadersFromClient(c TClient) THeaderMap {
if sc, ok := c.(*TStandardClient); ok {
if hp, ok := sc.iprot.(*THeaderProtocol); ok {
return hp.transport.readHeaders
}
}
return nil
}