Request Header Variables

You can use request headers in any script with the following script:

request.headers.get('x-sp-%header%')

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 NameDescription
x-sp-server-region The Server Region
x-sp-server-fqdnThe Server Hostname
x-sp-server-countrycodeThe Server's 2 letter Country code based on GeoDB
x-sp-server-subdivisionCodeA comma-separated list of character ISO-3166-2 codes for subdivisions
x-sp-server-geo-subdivisionNamesA comma-separated list of URL-Encoded names for subdivisions (up to 2), in order of increasing specificity (matches with subdivisionCodes)
x-sp-server-platformThe Server Platform
x-sp-server-epochThe Server Time
x-sp-server-ipThe Server IP
x-sp-server-popThe Server Pop
x-sp-server-nameThe Server Name
x-sp-client-request-startTimeUnix 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-cityThe city or town name
x-sp-client-geo-countryCodeThe two-character ISO-3166-1 country code
x-sp-client-geo-areaCodeThe telephone area code (will be deprecated soon)
x-sp-client-geo-postalCodeThe postal code
x-sp-client-geo-dmaCodeThe Designated Market Area code
x-sp-client-geo-continentCodeThe two-character code for the continent
x-sp-client-geo-countryNameThe country name
x-sp-client-geo-latitudeThe latitude
x-sp-client-geo-subdivisionCodesA 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-longitudeThe longitude
x-sp-client-geo-subdivisionNamesA 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