Overview
You can use this document to learn how to use request headers with serverless scripting.
View a sample request header
You can use request headers in any script with serverless scripting with the following script:
request.headers.get('x-sp-%header%')
The following example displays how you can determine the IP address of a client from the edge:
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
})
async function fetchAndApply(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)
}
Review available headers
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 (up to 2), in order of increasing specificity (matches with subdivisionNames). |
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 |