Allow setting the user agent in pixelapi

This commit is contained in:
Wim Brand 2021-09-21 21:39:09 +02:00
parent 40dcfec170
commit 104c99b1b6

View File

@ -19,6 +19,7 @@ type PixelAPI struct {
apiEndpoint string
key string
realIP string
realAgent string
}
// New creates a new Pixeldrain API client to query the Pixeldrain API with
@ -65,6 +66,12 @@ func (p PixelAPI) RealIP(ip string) PixelAPI {
return p
}
// RealAgent sets the real user agent to use when making API requests
func (p PixelAPI) RealAgent(agent string) PixelAPI {
p.realAgent = agent
return p
}
// Standard response types
// Error is an error returned by the pixeldrain API. If the request failed
@ -108,6 +115,9 @@ func (p *PixelAPI) do(r *http.Request) (*http.Response, error) {
if p.realIP != "" {
r.Header.Set("X-Real-IP", p.realIP)
}
if p.realAgent != "" {
r.Header.Set("User-Agent", p.realAgent)
}
return p.client.Do(r)
}