AEM Cloud Service - Accessing Geo Location Headers in Publish Instance

Geolocation headers added by Fastly CDN are sent in requests to Dispatcher. Well documented here, this post is just to show how to test it with local dispatcher SDK and demo on CS Publish..

1) Add a servlet to output the headers received by Publish 

package apps.eaem.sites.core.servlets;

import org.osgi.service.component.annotations.Component;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.util.Enumeration;

name = "Experience AEM Dump Request headers",
immediate = true,
service = Servlet.class,
property = {
public class DumpHeaders extends SlingAllMethodsServlet {
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws
ServletException, IOException {
try {
Enumeration<String> headers = request.getHeaderNames();

String name = headers.nextElement();
response.getWriter().println(name + "=" + request.getHeader(name));
} catch (Exception e) {

2) Add "x-aem-client-country" and "x-aem-client-continent" in dispatcher\src\conf.dispatcher.d\clientheaders\clientheaders.any

# This file contains the request headers, and can be customized.
# By default, it includes the default client headers.

$include "./default_clientheaders.any"


3) Add the following entry in dispatcher\src\conf.dispatcher.d\filters\filters.any to allow requests to the servlet

/0104 { /type "allow" /method "GET" /url "/bin/eaem/headers" }

4) Use PostMan for adding the headers manually, test if local Dispatcher SDK configuration is correct and passes the headers to Local Publish (on CS, Fastly CDN adds these headers to requests sent to dispatcher)

5) Running a CS build you should see the geo location headers added by Fastly to requests, output by the servlet...

No comments:

Post a Comment