MCPcopy Create free account
hub / github.com/dumorewithcode/purl / makeRequest

Method makeRequest

main.go:87–129  ·  view source on GitHub ↗
(url string)

Source from the content-addressed store, hash-verified

85}
86
87func (r requestData) makeRequest(url string) {
88 req, err := http.NewRequest("GET", url, nil)
89 if err != nil {
90 fmt.Fprintf(os.Stderr, "%s\n", err)
91 return
92 }
93
94 req.Header.Set("User-Agent", getUserAgent())
95
96 if r.cookie != "" {
97 req.Header.Set("Cookie", r.cookie)
98 }
99
100 if r.cookieFromFile != "" {
101 req.Header.Set("Cookie", r.cookieFromFile)
102 }
103
104 if len(r.headers) > 0 {
105 for _, header := range r.headers {
106 if strings.Contains(header, ":") {
107 //Split by first occurrence of colon(:), any other colons after that will be ignored
108 name, value := header[:strings.IndexByte(header, ':')], header[strings.IndexByte(header, ':')+1:]
109 req.Header.Set(strings.TrimSpace(name), strings.TrimSpace(value))
110 }
111 }
112 }
113
114 if r.headerFromFile != "" {
115 if strings.Contains(r.headerFromFile, ":") {
116 //Split by first occurrence of colon(:), any other colons after that will be ignored
117 name, value := r.headerFromFile[:strings.IndexByte(r.headerFromFile, ':')], r.headerFromFile[strings.IndexByte(r.headerFromFile, ':')+1:]
118 req.Header.Set(strings.TrimSpace(name), strings.TrimSpace(value))
119 }
120 }
121
122 resp, err := r.client.Do(req)
123 if err != nil {
124 fmt.Fprintf(os.Stderr, "%s\n", err)
125 return
126 }
127 defer resp.Body.Close()
128 io.Copy(ioutil.Discard, resp.Body)
129}
130
131func main() {
132 var (

Callers 1

mainFunction · 0.95

Calls 2

getUserAgentFunction · 0.85
SetMethod · 0.80

Tested by

no test coverage detected