-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from SimonRichardson/update-port
Allow overloading of headers.
- Loading branch information
Showing
12 changed files
with
397 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package http | ||
|
||
import "net/http" | ||
|
||
// HeadersFunc is type for aligning the creation of a series of client headers. | ||
type HeadersFunc = func(method string, headers http.Header, contentType, authToken string, hasPayload bool) http.Header | ||
|
||
// DefaultHeaders creates a set of http.Headers from the given arguments passed | ||
// in. | ||
// In this case it applies the headers passed in first, then sets the following: | ||
// - X-Auth-Token | ||
// - Content-Type | ||
// - Accept | ||
// - User-Agent | ||
// | ||
func DefaultHeaders(method string, extraHeaders http.Header, contentType, authToken string, payloadExists bool) http.Header { | ||
headers := BasicHeaders() | ||
if extraHeaders != nil { | ||
for header, values := range extraHeaders { | ||
for _, value := range values { | ||
headers.Add(header, value) | ||
} | ||
} | ||
} | ||
if authToken != "" { | ||
headers.Set("X-Auth-Token", authToken) | ||
} | ||
if payloadExists { | ||
headers.Add("Content-Type", contentType) | ||
} | ||
headers.Add("Accept", contentType) | ||
return headers | ||
} | ||
|
||
// BasicHeaders constructs basic http.Headers with expected default values. | ||
func BasicHeaders() http.Header { | ||
headers := make(http.Header) | ||
headers.Add("User-Agent", gooseAgent()) | ||
return headers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.