Request Header Variables

Additional headers detailing information about the request are present on the event.request object passed to the script. A script can access this information like any other header. For example, the below script returns a 403 when the request is coming from ip 192.168.1.100 and returns normally otherwise

addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
  if (request.headers.get("x-sp-client-ip") !== "192.168.1.100") {
    return new Response("Access Denied", {
      status: 403,
      statusText: "Forbidden"
    });
  }

  return fetch(request);
}

These are all of the headers available to scripts:

Header Name

Description

x-sp-server-region

The Server Region

x-sp-server-fqdn

The Server Hostname

x-sp-server-countrycode

The Server's 2 letter Country code based on GeoDB

x-sp-server-subdivisionCode

A comma-separated list of character ISO-3166-2 codes for subdivisions

x-sp-server-geo-subdivisionNames

A comma-separated list of URL-Encoded names for subdivisions (up to 2), in order of increasing specificity (matches with subdivisionCodes)

x-sp-server-platform

The Server Platform

x-sp-server-epoch

The Server Time

x-sp-server-ip

The Server IP

x-sp-server-pop

The Server Pop

x-sp-server-name

The Server Name

x-sp-client-request-startTime

Unix timestamp marking the beginning of the request. Ex: 1392413033

x-sp-client-geo-timeZone

The time zone taken from IANA time zone database (eg America/New_York)

x-sp-client-geo-city

The city or town name

x-sp-client-geo-countryCode

The two-character ISO-3166-1 country code

x-sp-client-geo-areaCode

The telephone area code (will be deprecated soon)

x-sp-client-geo-postalCode

The postal code

x-sp-client-geo-dmaCode

The Designated Market Area code

x-sp-client-geo-continentCode

The two-character code for the continent

x-sp-client-geo-countryName

The country name

x-sp-client-geo-latitude

The latitude

x-sp-client-geo-subdivisionCodes

A comma-separated list of character ISO-3166-2 codes for subdivisions (up to 2), in order of increasing specificity (matches with subdivisionNames)

x-sp-client-geo-longitude

The longitude

x-sp-client-geo-subdivisionNames

A comma-separated list of URL-Encoded names for subdivisions (up to 2), in order of increasing specificity (matches with subdivisionCodes)

x-sp-client-ip

IP in dot-notation of the client. Ex: 10.10.5.104


What’s Next