Allow setting the user agent in pixelapi
This commit is contained in:
parent
40dcfec170
commit
104c99b1b6
@ -19,6 +19,7 @@ type PixelAPI struct {
|
|||||||
apiEndpoint string
|
apiEndpoint string
|
||||||
key string
|
key string
|
||||||
realIP string
|
realIP string
|
||||||
|
realAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Pixeldrain API client to query the Pixeldrain API with
|
// 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
|
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
|
// Standard response types
|
||||||
|
|
||||||
// Error is an error returned by the pixeldrain API. If the request failed
|
// 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 != "" {
|
if p.realIP != "" {
|
||||||
r.Header.Set("X-Real-IP", 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)
|
return p.client.Do(r)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user