using native go for cookies

dev
Mzack9999 2020-07-16 12:58:56 +02:00
parent 037aa356a6
commit a23031a2e6
1 changed files with 7 additions and 12 deletions

View File

@ -2,7 +2,6 @@ package extractors
import (
"net/http"
"strings"
"github.com/miekg/dns"
)
@ -30,7 +29,7 @@ func (e *Extractor) Extract(resp *http.Response, body, headers string) map[strin
if len(matches) > 0 {
return matches
}
return e.extractInlineKVal(resp, "set-cookie")
return e.extractCookieKVal(resp, "set-cookie")
}
}
@ -71,17 +70,13 @@ func (e *Extractor) extractKVal(r *http.Response) map[string]struct{} {
return results
}
// extractInlineKVal extracts text from inline corpus
func (e *Extractor) extractInlineKVal(r *http.Response, key string) map[string]struct{} {
// extractCookieKVal extracts text from cookies
func (e *Extractor) extractCookieKVal(r *http.Response, key string) map[string]struct{} {
results := make(map[string]struct{})
for _, v := range r.Header.Values(key) {
for _, token := range strings.Split(v, ";") {
semicolon := strings.Index(token, ":")
key, value := token[:semicolon], token[semicolon:]
for _, k := range e.KVal {
if key == k {
results[value] = struct{}{}
}
for _, k := range e.KVal {
for _, cookie := range r.Cookies() {
if cookie.Name == k {
results[cookie.Value] = struct{}{}
}
}
}