Skip to content

Commit

Permalink
Merge pull request #2011 from yuwenma/followup1979
Browse files Browse the repository at this point in the history
chore: add methods for mock http record `Header`
  • Loading branch information
google-oss-prow[bot] authored Jun 17, 2024
2 parents 913ce7c + b0c1dd3 commit 7695204
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/test/http_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,30 @@ func prettifyJSON(s string, mutators ...JSONMutator) string {
return string(b)
}

func (r *Request) ReplaceHeader(key, value string) {
if http.CanonicalHeaderKey(key) == key {
r.Header.Set(key, value)
} else {
r.Header[key] = []string{value}
}
}

func (r *Response) ReplaceHeader(key, value string) {
if http.CanonicalHeaderKey(key) == key {
r.Header.Set(key, value)
} else {
r.Header[key] = []string{value}
}
}

func (r *Request) AddHeader(key, value string) {
r.Header.Add(key, value)
}

func (r *Response) AddHeader(key, value string) {
r.Header.Add(key, value)
}

func (r *Response) RemoveHeader(key string) {
// The http.header `Del` converts the `key` to `CanonicalHeaderKey`, which means
// it expects the passed-in parameter `key` to be case insensitive, but `Header` itself should
Expand Down

0 comments on commit 7695204

Please sign in to comment.