Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/authprovider/authx/headers_auth.go
2070 views
1
package authx
2
3
import (
4
"net/http"
5
6
"github.com/projectdiscovery/retryablehttp-go"
7
)
8
9
var (
10
_ AuthStrategy = &HeadersAuthStrategy{}
11
)
12
13
// HeadersAuthStrategy is a strategy for headers auth
14
type HeadersAuthStrategy struct {
15
Data *Secret
16
}
17
18
// NewHeadersAuthStrategy creates a new headers auth strategy
19
func NewHeadersAuthStrategy(data *Secret) *HeadersAuthStrategy {
20
return &HeadersAuthStrategy{Data: data}
21
}
22
23
// Apply applies the headers auth strategy to the request
24
func (s *HeadersAuthStrategy) Apply(req *http.Request) {
25
for _, header := range s.Data.Headers {
26
req.Header.Set(header.Key, header.Value)
27
}
28
}
29
30
// ApplyOnRR applies the headers auth strategy to the retryable request
31
func (s *HeadersAuthStrategy) ApplyOnRR(req *retryablehttp.Request) {
32
for _, header := range s.Data.Headers {
33
req.Header.Set(header.Key, header.Value)
34
}
35
}
36
37