mirror of
https://github.com/mpolden/echoip.git
synced 2025-01-12 19:27:21 +01:00
Do not cache user agent (#98)
This commit is contained in:
parent
1f140df49f
commit
d576730d08
19
http/http.go
19
http/http.go
@ -94,6 +94,16 @@ func ipFromRequest(headers []string, r *http.Request) (net.IP, error) {
|
|||||||
return ip, nil
|
return ip, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func userAgentFromRequest(r *http.Request) *useragent.UserAgent {
|
||||||
|
var userAgent *useragent.UserAgent
|
||||||
|
userAgentRaw := r.UserAgent()
|
||||||
|
if userAgentRaw != "" {
|
||||||
|
parsed := useragent.Parse(userAgentRaw)
|
||||||
|
userAgent = &parsed
|
||||||
|
}
|
||||||
|
return userAgent
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) newResponse(r *http.Request) (Response, error) {
|
func (s *Server) newResponse(r *http.Request) (Response, error) {
|
||||||
ip, err := ipFromRequest(s.IPHeaders, r)
|
ip, err := ipFromRequest(s.IPHeaders, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -101,6 +111,8 @@ func (s *Server) newResponse(r *http.Request) (Response, error) {
|
|||||||
}
|
}
|
||||||
response, ok := s.cache.Get(ip)
|
response, ok := s.cache.Get(ip)
|
||||||
if ok {
|
if ok {
|
||||||
|
// Not Caching the userAgent as it can vary for a given IP
|
||||||
|
response.UserAgent = userAgentFromRequest(r)
|
||||||
return *response, nil
|
return *response, nil
|
||||||
}
|
}
|
||||||
ipDecimal := iputil.ToDecimal(ip)
|
ipDecimal := iputil.ToDecimal(ip)
|
||||||
@ -115,12 +127,7 @@ func (s *Server) newResponse(r *http.Request) (Response, error) {
|
|||||||
if asn.AutonomousSystemNumber > 0 {
|
if asn.AutonomousSystemNumber > 0 {
|
||||||
autonomousSystemNumber = fmt.Sprintf("AS%d", asn.AutonomousSystemNumber)
|
autonomousSystemNumber = fmt.Sprintf("AS%d", asn.AutonomousSystemNumber)
|
||||||
}
|
}
|
||||||
var userAgent *useragent.UserAgent
|
userAgent := userAgentFromRequest(r)
|
||||||
userAgentRaw := r.UserAgent()
|
|
||||||
if userAgentRaw != "" {
|
|
||||||
parsed := useragent.Parse(userAgentRaw)
|
|
||||||
userAgent = &parsed
|
|
||||||
}
|
|
||||||
response = &Response{
|
response = &Response{
|
||||||
IP: ip,
|
IP: ip,
|
||||||
IPDecimal: ipDecimal,
|
IPDecimal: ipDecimal,
|
||||||
|
Loading…
Reference in New Issue
Block a user