X-AppEngine-country HTTP Header – Google App Engine

Google App Engine recently announced version 1.5.1 of its App Engine SDK. One of the features that interests me is that of the new header added in every client request.

The official announcement from Google is given below:

App Engine will now include a header with every client request that represents a best-effort attempt to identify the country from which the request originated. This header X-AppEngine-country can allow you to customize content based on the origin of the user.

Location is a big thing in most applications. Typically you can classify Location Based Applications into two types:

  • One that requires coarse grained information. What this means is that it is enough to know if the user is from a particular city or country. There is no need to know the exact co-ordinates.
  • The other type requires access to accurate location information and this typically means getting information about the latitude and longitude. The lat, lon are then used to further fine tune the results or actions.

The X-AppEngine-country is fantastic for applications that need coarse grained location information and would definitely help to avoid some network calls.

To test out, I wrote a simple Google App Engine Java project which has a single page (index.jsp) that simply sniffs the value of this header and prints it out. I was more interested in seeing what it returns. Here is the snippet of code that prints a greeting and the country from where you are accessing the page:

<h2>Hello My Friend from <%=request.getHeader("X-AppEngine-country") %></h2>

Since I live in India, it does a good job and prints out the following (as shown in the screenshot below):

You can try it too.

Some observations/comments:

While this is a good start, here are some points:

  • The country code that it provides are standard country abbreviations. Here is a list. If your application does not deal directly with the country code and requires some other value (e.g. full country name) — you might still have to do a lookup.
  • Several public APIs that require a coarse grained location might still not work with just the country code given here. So some additional translation might be due.
  • I still think this is a great start. And my suggestion to the Google Team if they haven’t already implemented it is to implement the a  Header that I shall take the liberty of calling X-AppEngine-city.
So go ahead and give the Location Test a try from your browser.

Read more Episodes on App Engine Services



2 thoughts on “X-AppEngine-country HTTP Header – Google App Engine

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s