| 162 | } |
| 163 | |
| 164 | func (client *HTTPClient) makeRequest(ctx context.Context, fullURL url.URL, opts RequestOptions) (*http.Response, error) { |
| 165 | req, err := http.NewRequestWithContext(ctx, client.method, fullURL.String(), opts.Body) |
| 166 | if err != nil { |
| 167 | return nil, err |
| 168 | } |
| 169 | |
| 170 | if client.cookies != "" { |
| 171 | req.Header.Set("Cookie", client.cookies) |
| 172 | } |
| 173 | |
| 174 | // Use host for VHOST mode on a per-request basis, otherwise the one provided from headers |
| 175 | if opts.Host != "" { |
| 176 | req.Host = opts.Host |
| 177 | } else if client.host != "" { |
| 178 | req.Host = client.host |
| 179 | } |
| 180 | |
| 181 | if client.userAgent != "" { |
| 182 | req.Header.Set("User-Agent", client.userAgent) |
| 183 | } else { |
| 184 | req.Header.Set("User-Agent", client.defaultUserAgent) |
| 185 | } |
| 186 | |
| 187 | // add custom headers |
| 188 | // if ModifiedHeaders are supplied use those, otherwise use the original ones |
| 189 | // currently only relevant on fuzzing |
| 190 | if len(opts.ModifiedHeaders) > 0 { |
| 191 | for _, h := range opts.ModifiedHeaders { |
| 192 | // empty headers are not valid (happens when fuzzing the host header for example because the slice is initialized with the provided header length) |
| 193 | if h.Name == "" { |
| 194 | continue |
| 195 | } |
| 196 | |
| 197 | if client.noCanonicalizeHeaders { |
| 198 | // https://stackoverflow.com/questions/26351716/how-to-keep-key-case-sensitive-in-request-header-using-golang |
| 199 | req.Header[h.Name] = []string{h.Value} |
| 200 | } else { |
| 201 | req.Header.Set(h.Name, h.Value) |
| 202 | } |
| 203 | } |
| 204 | } else { |
| 205 | for _, h := range client.headers { |
| 206 | if client.noCanonicalizeHeaders { |
| 207 | // https://stackoverflow.com/questions/26351716/how-to-keep-key-case-sensitive-in-request-header-using-golang |
| 208 | req.Header[h.Name] = []string{h.Value} |
| 209 | } else { |
| 210 | req.Header.Set(h.Name, h.Value) |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if opts.UpdatedBasicAuthUsername != "" { |
| 216 | req.SetBasicAuth(opts.UpdatedBasicAuthUsername, opts.UpdatedBasicAuthPassword) |
| 217 | } else if client.username != "" { |
| 218 | req.SetBasicAuth(client.username, client.password) |
| 219 | } |
| 220 | |
| 221 | if client.logger.debug { |