Skip to content

Commit e827a2c

Browse files
committed
client: Handle NewRequest errors before adding cookies
Previously WriteRequest attempted to add cookies to the httpRequest instance even if an error happened and might have resulted in httpRequest being nil which in turn caused a crash. This patch moves the error handling before looping through the current cookies to avoid this crash from happening. Signed-off-by: Vinzenz Feenstra <[email protected]>
1 parent 07c4ee3 commit e827a2c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

client.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ type clientCodec struct {
4343
func (codec *clientCodec) WriteRequest(request *rpc.Request, args interface{}) (err error) {
4444
httpRequest, err := NewRequest(codec.url.String(), request.ServiceMethod, args)
4545

46+
if err != nil {
47+
return err
48+
}
49+
4650
if codec.cookies != nil {
4751
for _, cookie := range codec.cookies.Cookies(codec.url) {
4852
httpRequest.AddCookie(cookie)
4953
}
5054
}
5155

52-
if err != nil {
53-
return err
54-
}
55-
5656
var httpResponse *http.Response
5757
httpResponse, err = codec.httpClient.Do(httpRequest)
5858

0 commit comments

Comments
 (0)