rpc: add SetHeader method to Client (#21392)
Resolves #20163 Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
@ -85,7 +85,7 @@ type Client struct {
|
||||
|
||||
// writeConn is used for writing to the connection on the caller's goroutine. It should
|
||||
// only be accessed outside of dispatch, with the write lock held. The write lock is
|
||||
// taken by sending on requestOp and released by sending on sendDone.
|
||||
// taken by sending on reqInit and released by sending on reqSent.
|
||||
writeConn jsonWriter
|
||||
|
||||
// for dispatch
|
||||
@ -260,6 +260,19 @@ func (c *Client) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
// SetHeader adds a custom HTTP header to the client's requests.
|
||||
// This method only works for clients using HTTP, it doesn't have
|
||||
// any effect for clients using another transport.
|
||||
func (c *Client) SetHeader(key, value string) {
|
||||
if !c.isHTTP {
|
||||
return
|
||||
}
|
||||
conn := c.writeConn.(*httpConn)
|
||||
conn.mu.Lock()
|
||||
conn.headers.Set(key, value)
|
||||
conn.mu.Unlock()
|
||||
}
|
||||
|
||||
// Call performs a JSON-RPC call with the given arguments and unmarshals into
|
||||
// result if no error occurred.
|
||||
//
|
||||
|
Reference in New Issue
Block a user