Nash
Nash

Reputation: 95

Trying to check if a request header includes a certain ip

I am trying to check if a request header includes a certain ip, but using the matching operator ~ is not working as expected:

if (req.http.X-Forwarded-For && req.http.X-Forwarded-For ~ "^.*" + server.ip + ".*$") {
    # logic
}

I get the error:

Error: │ │ Message from VCC-compiler: │ │ Expected ')' got '+' │ │ (program line 68), at │ │ ('/tmp/vcl' Line 300 Pos 74) │ │ if (req.http.X-Forwarded-For && req.http.X-Forwarded-For ~ "^." + server.ip + ".$") {

Any ideas why that is happening?

Upvotes: 0

Views: 159

Answers (1)

PajE
PajE

Reputation: 759

hum.. server.ip is an IP address, not a string The following code might do the trick

  if (std.strstr(req.http.X-Forwarded-For, server.ip) != "") {
    # logic
  }

Upvotes: 1

Related Questions