Put headers & meta in lowercase

pull/57/head
Aloïs Micard 4 years ago
parent 0826b6e680
commit 29ed1f2f5f
No known key found for this signature in database
GPG Key ID: 1A0EB82F071F5EFE

@ -79,7 +79,12 @@ func handleMessage(apiClient api.Client) messaging.MsgHandler {
if err != nil {
return fmt.Errorf("error while extracting resource: %s", err)
}
resDto.Headers = resMsg.Headers
// Lowercase headers
resDto.Headers = map[string]string{}
for key, value := range resMsg.Headers {
resDto.Headers[strings.ToLower(key)] = value
}
// Submit to the API
_, err = apiClient.AddResource(resDto)
@ -138,7 +143,7 @@ func extractResource(msg messaging.NewResourceMsg) (api.ResourceDto, []string, e
}
}
meta[name] = value
meta[strings.ToLower(name)] = value
})
// Extract & normalize URLs

@ -18,7 +18,7 @@ This is sparta
<a href="https://google.com/test?test=test#12">
<meta name="description" content="Zhello world">
<meta name="Description" content="Zhello world">
<meta property="og:url" content="https://example.org">
`
@ -84,7 +84,7 @@ This is sparta (hosted on https://example.org)
<a href="https://google.com/test?test=test#12">
<meta name="description" content="Zhello world">
<meta name="DescriptIon" content="Zhello world">
<meta property="og:url" content="https://example.org">`
mockCtrl := gomock.NewController(t)
@ -110,7 +110,7 @@ This is sparta (hosted on https://example.org)
Title: "Creekorful Inc",
Meta: map[string]string{"description": "Zhello world", "og:url": "https://example.org"},
Description: "Zhello world",
Headers: map[string]string{"Server": "Traefik", "Content-Type": "application/html"},
Headers: map[string]string{"server": "Traefik", "content-type": "application/html"},
}}).Return(api.ResourceDto{}, nil)
// make sure we are pushing found URLs
@ -136,14 +136,13 @@ type resMatcher struct {
func (rm *resMatcher) Matches(x interface{}) bool {
arg := x.(api.ResourceDto)
return arg.Title ==
rm.target.Title &&
return arg.Title == rm.target.Title &&
arg.URL == rm.target.URL &&
arg.Body == rm.target.Body &&
arg.Description == rm.target.Description &&
exactMatch(arg.Meta, rm.target.Meta) &&
arg.Headers["Server"][0] == rm.target.Headers["Server"][0] &&
arg.Headers["Content-Type"] == rm.target.Headers["Content-Type"] // TODO allow other headers comparison
arg.Headers["server"] == rm.target.Headers["server"] &&
arg.Headers["content-type"] == rm.target.Headers["content-type"] // TODO allow other headers comparison
}
func (rm *resMatcher) String() string {

Loading…
Cancel
Save