@@ -19,6 +19,8 @@ import (
1919
2020 "github.com/blang/semver"
2121 "github.com/tebeka/selenium/firefox"
22+ "github.com/tebeka/selenium/http/headers"
23+ "github.com/tebeka/selenium/http/mediatypes"
2224 "github.com/tebeka/selenium/log"
2325)
2426
@@ -59,15 +61,15 @@ type remoteWD struct {
5961// server.
6062var HTTPClient = http .DefaultClient
6163
62- // jsonContentType is JSON content type.
63- const jsonContentType = "application/json"
64-
6564func newRequest (method string , url string , data []byte ) (* http.Request , error ) {
6665 request , err := http .NewRequest (method , url , bytes .NewBuffer (data ))
6766 if err != nil {
6867 return nil , err
6968 }
70- request .Header .Add ("Accept" , jsonContentType )
69+ if data != nil {
70+ request .Header .Add (headers .ContentType , mediatypes .ApplicationJSONUtf8 )
71+ }
72+ request .Header .Add (headers .Accept , mediatypes .ApplicationJSON )
7173
7274 return request , nil
7375}
@@ -148,19 +150,19 @@ func executeCommand(method, url string, data []byte) (json.RawMessage, error) {
148150 buf = prettyBuf .Bytes ()
149151 }
150152 }
151- debugLog ("<- %s [%s]\n %s" , response .Status , response .Header ["Content-Type" ], buf )
153+ debugLog ("<- %s [%s]\n %s" , response .Status , response .Header [headers . ContentType ], buf )
152154 }
153155 if err != nil {
154156 return nil , errors .New (response .Status )
155157 }
156158
157- fullCType := response .Header .Get ("Content-Type" )
159+ fullCType := response .Header .Get (headers . ContentType )
158160 cType , _ , err := mime .ParseMediaType (fullCType )
159161 if err != nil {
160- return nil , fmt .Errorf ("got content type header %q, expected %q" , fullCType , jsonContentType )
162+ return nil , fmt .Errorf ("got content type header %q, expected %q" , fullCType , mediatypes . ApplicationJSON )
161163 }
162- if cType != jsonContentType {
163- return nil , fmt .Errorf ("got content type %q, expected %q" , cType , jsonContentType )
164+ if cType != mediatypes . ApplicationJSON {
165+ return nil , fmt .Errorf ("got content type %q, expected %q" , cType , mediatypes . ApplicationJSON )
164166 }
165167
166168 reply := new (serverReply )
0 commit comments