Many content distribution networks give you tools to target your content based on the country the user is in when they make a request to your web application. Here are some examples:
Use the header CloudFront-Viewer-Country
def my_view(request):
country = request.META.get('HTTP_CLOUDFRONT_VIEWER_COUNTRY', None)
import (
"context"
"fmt"
"github.com/dherbst/geo-targeting/src/geo"
"net/http"
)
func init() {
http.HandleFunc("/country", func(w http.ResponseWriter, r *http.Request) {
ctx := geo.WithCountry(context.Background(), r)
country, _ := geo.CountryFromContext(ctx)
fmt.Fprintf(w, "Country=%v\n", country)
})
}
Use the header X-AppEngine-Country
Use the edgescape header X-Akamai-Edgescape
, look for country_code
in the string.
Add %{geo_country}
to a header using the advanced rules engine.
Use the header CF-IPCountry
.