@@ -12,6 +12,7 @@ import (
1212 "github.com/ARM-software/golang-utils/utils/collection"
1313 "github.com/ARM-software/golang-utils/utils/commonerrors"
1414 "github.com/ARM-software/golang-utils/utils/encoding/base64"
15+ "github.com/ARM-software/golang-utils/utils/field"
1516 "github.com/ARM-software/golang-utils/utils/http/headers/useragent"
1617 "github.com/ARM-software/golang-utils/utils/http/schemes"
1718 "github.com/ARM-software/golang-utils/utils/reflection"
@@ -175,19 +176,19 @@ func (hs Headers) Append(h *Header) {
175176}
176177
177178func (hs Headers ) Get (key string ) string {
178- found , h := hs .get (key )
179+ h , found := hs .get (key )
179180 if ! found {
180181 return ""
181182 }
182183 return h .Value
183184}
184185
185186func (hs Headers ) GetHeader (key string ) (header * Header ) {
186- _ , header = hs .get (key )
187+ header , _ = hs .get (key )
187188 return
188189}
189190
190- func (hs Headers ) get (key string ) (found bool , header * Header ) {
191+ func (hs Headers ) get (key string ) (header * Header , found bool ) {
191192 h , found := hs [key ]
192193 if ! found {
193194 h , found = hs [headers .Normalize (key )] //nolint:misspell
@@ -207,28 +208,25 @@ func (hs Headers) Has(h *Header) bool {
207208}
208209
209210func (hs Headers ) HasHeader (key string ) bool {
210- found , _ := hs .get (key )
211+ _ , found := hs .get (key )
211212 return found
212213}
213214
214215func (hs Headers ) FromRequest (r * http.Request ) {
215- if r == nil {
216+ if reflection . IsEmpty ( r ) {
216217 return
217218 }
218219 hs .FromGoHTTPHeaders (& r .Header )
219220}
220221
221222func (hs Headers ) FromGoHTTPHeaders (headers * http.Header ) {
222- if reflection .IsEmpty (headers ) {
223- return
224- }
225- for key , value := range * headers {
223+ for key , value := range field .Optional [http.Header ](headers , http.Header {}) {
226224 hs .AppendHeader (key , value [0 ])
227225 }
228226}
229227
230228func (hs Headers ) FromResponse (resp * http.Response ) {
231- if resp == nil {
229+ if reflection . IsEmpty ( resp ) {
232230 return
233231 }
234232 hs .FromGoHTTPHeaders (& resp .Header )
@@ -307,7 +305,7 @@ func NewHeaders() *Headers {
307305
308306// FromRequest returns request's headers
309307func FromRequest (r * http.Request ) * Headers {
310- if r == nil {
308+ if reflection . IsEmpty ( r ) {
311309 return nil
312310 }
313311 h := NewHeaders ()
@@ -317,7 +315,7 @@ func FromRequest(r *http.Request) *Headers {
317315
318316// FromResponse returns response's headers
319317func FromResponse (resp * http.Response ) * Headers {
320- if resp == nil {
318+ if reflection . IsEmpty ( resp ) {
321319 return nil
322320 }
323321 h := NewHeaders ()
0 commit comments