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 |
---|---|
| The Server Region |
| The Server Hostname |
| The Server's 2 letter Country code based on GeoDB |
| A comma-separated list of character ISO-3166-2 codes for subdivisions |
| A comma-separated list of URL-Encoded names for subdivisions (up to 2), in order of increasing specificity (matches with subdivisionCodes) |
| The Server Platform |
| The Server Time |
| The Server IP |
| The Server Pop |
| The Server Name |
| Unix timestamp marking the beginning of the request. Ex: 1392413033 |
| The time zone taken from IANA time zone database (eg America/New_York) |
| The city or town name |
| The two-character ISO-3166-1 country code |
| The telephone area code (will be deprecated soon) |
| The postal code |
| The Designated Market Area code |
| The two-character code for the continent |
| The country name |
| The latitude |
| A comma-separated list of character ISO-3166-2 codes for subdivisions (up to 2), in order of increasing specificity (matches with subdivisionNames) |
| The longitude |
| A comma-separated list of URL-Encoded names for subdivisions (up to 2), in order of increasing specificity (matches with subdivisionCodes) |
| IP in dot-notation of the client. Ex: 10.10.5.104 |
Updated almost 3 years ago