sedky
February 8, 2021, 2:52pm
2
Not sure if possible natively.
Here’s the list of request meta data we can look at:
https://tyk.io/docs/getting-started/key-concepts/context-variables/
Doesn’t look like “host” is one of them.
You could write a custom plugin to look at the requested server name and inject it as a header ? That way your URL rewrite could have access to that header and write to an API depending on its value.
Here’s a line in a “pre” Go plugin that injects the requested Host name as a header:
// Required
func main() {}
// Main method to be run by Tyk
func CertHeaderInject(w http.ResponseWriter, r *http.Request) {
log.Info("-----------")
log.Info("Attempting to pull Peer Cert Info")
if len(r.TLS.PeerCertificates) > 0 {
// Requested Hostname, same as nginx "$host"
r.Header.Set("x-client-requested-servername", r.TLS.ServerName)
log.Info("x-client-requested-servername: " + r.TLS.ServerName)
// Client Cert Issuer
r.Header.Set("X-Client-Issuer", r.TLS.PeerCertificates[0].Issuer.CommonName)
log.Info("X-Client-Issuer: " + r.TLS.PeerCertificates[0].Issuer.CommonName)
// Client Cert Fingerprint
r.Header.Set("X-Client-Fingerprint", getFingerprintString(sha1.Sum(r.TLS.PeerCertificates[0].Raw)))
log.Info("X-Client-Fingerprint: " + getFingerprintString(sha1.Sum(r.TLS.PeerCertificates[0].Raw)))
} else {
log.Info("No Peer certificates found.")
}