Skip to content

Commit 6a91ed8

Browse files
authored
Merge pull request #23 from liamg/liamg-sizes
add support for non-headered kengths
2 parents 3140c90 + 0ef9ccd commit 6a91ed8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/scan/url_scanner.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,21 +325,27 @@ func (scanner *URLScanner) checkURL(job URLJob) *URLResult {
325325

326326
contentType := resp.Header.Get("Content-Type")
327327

328+
size := -1
329+
328330
if scanner.enableSpidering && (contentType == "" || strings.Contains(contentType, "html")) {
329331
body, err := ioutil.ReadAll(resp.Body)
330332
if err == nil {
331333
for _, link := range findLinks(job.URL, body) {
332334
scanner.queue(URLJob{URL: link})
333335
}
334336
}
335-
} else {
336-
_, _ = io.Copy(ioutil.Discard, resp.Body)
337+
size = len(body)
337338
}
338339

339-
var size int
340-
contentLength := resp.Header.Get("Content-Length")
341-
if contentLength != "" {
342-
size, _ = strconv.Atoi(contentLength)
340+
if size == -1 {
341+
contentLength := resp.Header.Get("Content-Length")
342+
if contentLength != "" {
343+
size, _ = strconv.Atoi(contentLength)
344+
} else {
345+
cdata, _ := ioutil.ReadAll(resp.Body)
346+
size = len(cdata)
347+
cdata = nil
348+
}
343349
}
344350

345351
for _, length := range scanner.negativeLengths {

0 commit comments

Comments
 (0)