@@ -17,6 +17,8 @@ import (
1717
1818 "github.com/blang/semver"
1919 "github.com/tebeka/selenium/firefox"
20+ "github.com/tebeka/selenium/http/headers"
21+ "github.com/tebeka/selenium/http/mediatypes"
2022 "github.com/tebeka/selenium/log"
2123)
2224
@@ -57,15 +59,15 @@ type remoteWD struct {
5759// server.
5860var HTTPClient = http .DefaultClient
5961
60- // jsonContentType is JSON content type.
61- const jsonContentType = "application/json"
62-
6362func newRequest (method string , url string , data []byte ) (* http.Request , error ) {
6463 request , err := http .NewRequest (method , url , bytes .NewBuffer (data ))
6564 if err != nil {
6665 return nil , err
6766 }
68- request .Header .Add ("Accept" , jsonContentType )
67+ if data != nil {
68+ request .Header .Add (headers .ContentType , mediatypes .ApplicationJSONUtf8 )
69+ }
70+ request .Header .Add (headers .Accept , mediatypes .ApplicationJSON )
6971
7072 return request , nil
7173}
@@ -142,19 +144,19 @@ func (wd *remoteWD) execute(method, url string, data []byte) (json.RawMessage, e
142144 buf = prettyBuf .Bytes ()
143145 }
144146 }
145- debugLog ("<- %s [%s]\n %s" , response .Status , response .Header ["Content-Type" ], buf )
147+ debugLog ("<- %s [%s]\n %s" , response .Status , response .Header [headers . ContentType ], buf )
146148 }
147149 if err != nil {
148150 return nil , errors .New (response .Status )
149151 }
150152
151- fullCType := response .Header .Get ("Content-Type" )
153+ fullCType := response .Header .Get (headers . ContentType )
152154 cType , _ , err := mime .ParseMediaType (fullCType )
153155 if err != nil {
154- return nil , fmt .Errorf ("got content type header %q, expected %q" , fullCType , jsonContentType )
156+ return nil , fmt .Errorf ("got content type header %q, expected %q" , fullCType , mediatypes . ApplicationJSON )
155157 }
156- if cType != jsonContentType {
157- return nil , fmt .Errorf ("got content type %q, expected %q" , cType , jsonContentType )
158+ if cType != mediatypes . ApplicationJSON {
159+ return nil , fmt .Errorf ("got content type %q, expected %q" , cType , mediatypes . ApplicationJSON )
158160 }
159161
160162 reply := new (serverReply )
0 commit comments