Skip to content

Commit

Permalink
Remove http package
Browse files Browse the repository at this point in the history
  • Loading branch information
aziemski committed Aug 18, 2020
1 parent 35b7abd commit f1d0b43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
7 changes: 0 additions & 7 deletions http/headers/headers.go

This file was deleted.

7 changes: 0 additions & 7 deletions http/mediatypes/mediatypes.go

This file was deleted.

19 changes: 10 additions & 9 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (

"github.com/blang/semver"
"github.com/tebeka/selenium/firefox"
"github.com/tebeka/selenium/http/headers"
"github.com/tebeka/selenium/http/mediatypes"
"github.com/tebeka/selenium/log"
)

Expand Down Expand Up @@ -61,15 +59,18 @@ type remoteWD struct {
// server.
var HTTPClient = http.DefaultClient

// jsonContentType is JSON content type.
const jsonContentType = "application/json"

func newRequest(method string, url string, data []byte) (*http.Request, error) {
request, err := http.NewRequest(method, url, bytes.NewBuffer(data))
if err != nil {
return nil, err
}
if data != nil {
request.Header.Add(headers.ContentType, mediatypes.ApplicationJSONUtf8)
request.Header.Add("Content-Type", jsonContentType)
}
request.Header.Add(headers.Accept, mediatypes.ApplicationJSON)
request.Header.Add("Accept", jsonContentType)

return request, nil
}
Expand Down Expand Up @@ -150,19 +151,19 @@ func executeCommand(method, url string, data []byte) (json.RawMessage, error) {
buf = prettyBuf.Bytes()
}
}
debugLog("<- %s [%s]\n%s", response.Status, response.Header[headers.ContentType], buf)
debugLog("<- %s [%s]\n%s", response.Status, response.Header["Content-Type"], buf)
}
if err != nil {
return nil, errors.New(response.Status)
}

fullCType := response.Header.Get(headers.ContentType)
fullCType := response.Header.Get("Content-Type")
cType, _, err := mime.ParseMediaType(fullCType)
if err != nil {
return nil, fmt.Errorf("got content type header %q, expected %q", fullCType, mediatypes.ApplicationJSON)
return nil, fmt.Errorf("got content type header %q, expected %q", fullCType, jsonContentType)
}
if cType != mediatypes.ApplicationJSON {
return nil, fmt.Errorf("got content type %q, expected %q", cType, mediatypes.ApplicationJSON)
if cType != jsonContentType {
return nil, fmt.Errorf("got content type %q, expected %q", cType, jsonContentType)
}

reply := new(serverReply)
Expand Down

0 comments on commit f1d0b43

Please sign in to comment.