Use Accept request header instead of user agent to figure out non-browser clients. Funny fact, I borrowed the idea from a fork ('8a3e142cf3/router/generic.go (L33)')

This commit is contained in:
2022-04-30 17:10:22 +02:00
parent 12da27ddab
commit 9070e9a2c2
5 changed files with 124 additions and 57 deletions

View File

@ -16,6 +16,7 @@ type testIPs struct {
}
type contentTypes struct {
html string
text string
json string
}
@ -29,9 +30,12 @@ var (
ipv6ASN: "2a02:a800::1",
}
contentType = contentTypes{
html: "content-type: text/html; charset=utf-8",
text: "text/plain; charset=utf-8",
json: "application/json; charset=utf-8",
}
jsonIPv4 = `{"client_port":"1000","ip":"81.2.69.192","ip_version":4,"country":"United Kingdom","country_code":"GB","city":"London","latitude":51.5142,"longitude":-0.0931,"postal_code":"","time_zone":"Europe/London","asn":0,"asn_organization":"","host":"test","headers":{"X-Real-Ip":["81.2.69.192"]}}`
jsonIPv6 = `{"asn":3352, "asn_organization":"TELEFONICA DE ESPANA", "city":"", "client_port":"1000", "country":"", "country_code":"", "headers":{"X-Real-Ip":["2a02:9000::1"]}, "host":"test", "ip":"2a02:9000::1", "ip_version":6, "latitude":0, "longitude":0, "postal_code":"", "time_zone":""}`
)
const trustedHeader = "X-Real-IP"