This repository has been archived by the owner on Mar 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobdesc.go
54 lines (50 loc) · 1.81 KB
/
jobdesc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package webanalyze
import (
"net/http"
)
// Job may consist only of a URL, in which case webanalyse will
// proceed to download from that URL, or it may consist of the
// Body and Headers of a request to a URL and the URL itself,
// in which case these fields will be trusted and used for
// analysis without further network traffic.
// If a Job is constructed using the OfflineJob constructor
// then a flag will be set to prevent downloading regardless
// of the contents (or absence) of the Body or Headers fields.
type Job struct {
URL string
Body []byte
Headers http.Header //map[string][]string
Cookies []*http.Cookie
Crawl int
SearchSubdomain bool
forceNotDownload bool
}
// NewOfflineJob constructs a job out of the constituents of a
// webanalyzer analysis; a URL, a body, and response headers.
// This constructor also sets a flag to explicitly prevent
// fetching from the URL even if the body and headers are nil
// or empty. Use this for...offline jobs.
func NewOfflineJob(url, body string, headers map[string][]string) *Job {
return &Job{
URL: url,
Body: []byte(body),
Headers: headers,
Crawl: 0,
SearchSubdomain: false,
forceNotDownload: true,
}
}
// NewOnlineJob constructs a job that may either have a URL only,
// or a URL, Body and Headers. If it contains at least a URL and Body,
// then webanalyzer will not re-download the data, but if a Body is
// absent then downloading will be attempted.
func NewOnlineJob(url, body string, headers map[string][]string, crawlCount int, searchSubdomain bool) *Job {
return &Job{
URL: url,
Body: []byte(body),
Headers: headers,
Crawl: crawlCount,
SearchSubdomain: searchSubdomain,
forceNotDownload: false,
}
}