Skip to content

Commit 17950bf

Browse files
committed
💚 linting
1 parent c3cad55 commit 17950bf

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

utils/http/header_client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515

1616
type ClientWithHeaders struct {
1717
client IClient
18-
headers headers.Headers
18+
headers *headers.Headers
1919
}
2020

2121
func newClientWithHeaders(underlyingClient IClient, headerValues ...string) (c *ClientWithHeaders, err error) {
2222
c = &ClientWithHeaders{
23-
headers: make(headers.Headers),
23+
headers: headers.NewHeaders(),
2424
}
2525

2626
if underlyingClient == nil {
@@ -123,7 +123,7 @@ func (c *ClientWithHeaders) Close() error {
123123

124124
func (c *ClientWithHeaders) AppendHeader(key, value string) {
125125
if c.headers == nil {
126-
c.headers = make(headers.Headers)
126+
c.headers = headers.NewHeaders()
127127
}
128128
c.headers.AppendHeader(key, value)
129129
}
@@ -132,9 +132,9 @@ func (c *ClientWithHeaders) RemoveHeader(key string) {
132132
if c.headers == nil {
133133
return
134134
}
135-
delete(c.headers, key)
135+
c.headers.RemoveHeader(key)
136136
}
137137

138138
func (c *ClientWithHeaders) ClearHeaders() {
139-
c.headers = make(headers.Headers)
139+
c.headers = headers.NewHeaders()
140140
}

utils/http/header_client_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ func TestClientWithHeadersWithDifferentBodies(t *testing.T) {
223223

224224
clientStruct.AppendHeader("hello", "world")
225225
require.NotEmpty(t, clientStruct.headers)
226-
assert.Equal(t, headers.Header{Key: "hello", Value: "world"}, clientStruct.headers["hello"])
226+
header := clientStruct.headers.GetHeader("hello")
227+
require.NotNil(t, header)
228+
assert.Equal(t, headers.Header{Key: "hello", Value: "world"}, *header)
227229

228230
clientStruct.RemoveHeader("hello")
229231
assert.Empty(t, clientStruct.headers)

utils/http/headers/headers.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,31 @@ func (hs Headers) AppendHeader(key, value string) {
171171
}
172172

173173
func (hs Headers) Append(h *Header) {
174-
hs[headers.Normalize(h.Key)] = *h
174+
hs[headers.Normalize(h.Key)] = *h //nolint:misspell
175175
}
176176

177177
func (hs Headers) Get(key string) string {
178-
_, value := hs.get(key)
179-
return value
178+
found, h := hs.get(key)
179+
if !found {
180+
return ""
181+
}
182+
return h.Value
183+
}
184+
185+
func (hs Headers) GetHeader(key string) (header *Header) {
186+
_, header = hs.get(key)
187+
return
180188
}
181189

182-
func (hs Headers) get(key string) (found bool, value string) {
190+
func (hs Headers) get(key string) (found bool, header *Header) {
183191
h, found := hs[key]
184192
if !found {
185-
h, found = hs[headers.Normalize(key)]
193+
h, found = hs[headers.Normalize(key)] //nolint:misspell
186194
if !found {
187195
return
188196
}
189197
}
190-
value = h.Value
198+
header = &h
191199
return
192200
}
193201

@@ -207,10 +215,10 @@ func (hs Headers) FromRequest(r *http.Request) {
207215
if r == nil {
208216
return
209217
}
210-
hs.FromGoHttpHeaders(&r.Header)
218+
hs.FromGoHTTPHeaders(&r.Header)
211219
}
212220

213-
func (hs Headers) FromGoHttpHeaders(headers *http.Header) {
221+
func (hs Headers) FromGoHTTPHeaders(headers *http.Header) {
214222
if reflection.IsEmpty(headers) {
215223
return
216224
}
@@ -223,7 +231,7 @@ func (hs Headers) FromResponse(resp *http.Response) {
223231
if resp == nil {
224232
return
225233
}
226-
hs.FromGoHttpHeaders(&resp.Header)
234+
hs.FromGoHTTPHeaders(&resp.Header)
227235
}
228236

229237
func (hs Headers) Empty() bool {
@@ -248,7 +256,7 @@ func (hs Headers) AppendToRequest(r *http.Request) {
248256

249257
func (hs Headers) RemoveHeader(key string) {
250258
delete(hs, key)
251-
delete(hs, headers.Normalize(key))
259+
delete(hs, headers.Normalize(key)) //nolint:misspell
252260
}
253261

254262
func (hs Headers) RemoveHeaders(key ...string) {
@@ -283,10 +291,10 @@ func (hs Headers) AllowList(key ...string) *Headers {
283291
// It is possible to provide an allowed list of extra headers which would also be retained.
284292
func (hs Headers) Sanitise(allowList ...string) {
285293
allowedHeaders := mapset.NewSet[string](NormalisedSafeHeaders...)
286-
allowedHeaders.Append(collection.Map[string, string](allowList, headers.Normalize)...)
294+
allowedHeaders.Append(collection.Map[string, string](allowList, headers.Normalize)...) //nolint:misspell
287295
var headersToRemove []string
288296
for key := range hs {
289-
if !allowedHeaders.Contains(headers.Normalize(key)) {
297+
if !allowedHeaders.Contains(headers.Normalize(key)) { //nolint:misspell
290298
headersToRemove = append(headersToRemove, key)
291299
}
292300
}
@@ -518,7 +526,7 @@ func CreateLinkHeader(link, relation, contentType string) string {
518526
// SanitiseHeaders sanitises a collection of request headers not to include any with personal data
519527
func SanitiseHeaders(requestHeader *http.Header) *Headers {
520528
hs := NewHeaders()
521-
hs.FromGoHttpHeaders(requestHeader)
529+
hs.FromGoHTTPHeaders(requestHeader)
522530
hs.Sanitise()
523531
return hs
524532
}

utils/http/headers/headers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ func TestGetHeaders(t *testing.T) {
201201
header := NewHeaders()
202202
test := faker.Word()
203203
header.AppendHeader(HeaderWebsocketProtocol, test)
204-
assert.Equal(t, test, header.Get(headers.Normalize(HeaderWebsocketProtocol)))
204+
assert.Equal(t, test, header.Get(headers.Normalize(HeaderWebsocketProtocol))) //nolint:misspell
205205
assert.True(t, header.HasHeader(HeaderWebsocketProtocol))
206-
assert.True(t, header.HasHeader(headers.Normalize(HeaderWebsocketProtocol)))
206+
assert.True(t, header.HasHeader(headers.Normalize(HeaderWebsocketProtocol))) //nolint:misspell
207207
assert.Empty(t, header.Get(headers.ContentLocation))
208208
assert.False(t, header.HasHeader(headers.ContentLocation))
209-
assert.False(t, header.HasHeader(headers.Normalize(headers.ContentLocation)))
209+
assert.False(t, header.HasHeader(headers.Normalize(headers.ContentLocation))) //nolint:misspell
210210
}
211211

212212
func TestSanitiseHeaders(t *testing.T) {

0 commit comments

Comments
 (0)