Skip to content

Commit

Permalink
Add configs for GeoJSON files (.geojson)
Browse files Browse the repository at this point in the history
Ensure that clients interpret the content of `.geojson` files correctly
by serving them with the `application/vnd.geo+json` content-type.
http://www.iana.org/assignments/media-types/application/vnd.geo+json

Also, ensure that `.geojson` files aren't served with any of the `HTML`
document related headers, but are served compressed, and their specified
character encoding is UTF-8.

Ref: http://geojson.org/geojson-spec.html
  • Loading branch information
alrra committed Jun 20, 2014
1 parent cf1ab4f commit 16d3965
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### HEAD

* Add configs for GeoJSON files (`.geojson`).

### 2.5.0 (June 14, 2014)

* Compress cache manifest files (`.appcache` / `.manifest`).
Expand Down
17 changes: 10 additions & 7 deletions src/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Options -MultiViews
Header set X-UA-Compatible "IE=edge"
# `mod_headers` cannot match based on the content-type, however, this header
# should be send only for HTML documents and not for the other resources
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
Expand Down Expand Up @@ -136,6 +136,7 @@ Options -MultiViews
# Data interchange
AddType application/json json map
AddType application/ld+json jsonld
AddType application/vnd.geo+json geojson

# JavaScript
# Normalize to standard type.
Expand Down Expand Up @@ -221,7 +222,7 @@ AddDefaultCharset utf-8

# Set `UTF-8` as the character encoding for other certain resources.
<IfModule mod_mime.c>
AddCharset utf-8 .atom .css .js .json .jsonld .rss .vtt .webapp .xml
AddCharset utf-8 .atom .css .geojson .js .json .jsonld .rss .vtt .webapp .xml
</IfModule>


Expand All @@ -233,8 +234,8 @@ AddDefaultCharset utf-8
# | Rewrite engine |
# ------------------------------------------------------------------------------

# Turn on the rewrite engine and enable the `FollowSymLinks` option (this is
# necessary in order for the following directives to work).
# Turn on the rewrite engine and enable the `FollowSymLinks` option
# (this is necessary in order for the following directives to work).

# If your web host doesn't allow the `FollowSymlinks` option, you may need to
# comment it out and use `Options +SymLinksIfOwnerMatch`, but be aware of the
Expand Down Expand Up @@ -330,7 +331,7 @@ AddDefaultCharset utf-8

# <IfModule mod_headers.c>
# Header set X-Frame-Options "DENY"
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
# Header unset X-Frame-Options
# </FilesMatch>
# </IfModule>
Expand All @@ -355,7 +356,7 @@ AddDefaultCharset utf-8

# <IfModule mod_headers.c>
# Header set Content-Security-Policy "script-src 'self'; object-src 'self'"
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
# Header unset Content-Security-Policy
# </FilesMatch>
# </IfModule>
Expand Down Expand Up @@ -485,7 +486,7 @@ AddDefaultCharset utf-8
# <IfModule mod_headers.c>
# # (1) (2)
# Header set X-XSS-Protection "1; mode=block"
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
# <FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
# Header unset X-XSS-Protection
# </FilesMatch>
# </IfModule>
Expand Down Expand Up @@ -587,6 +588,7 @@ AddDefaultCharset utf-8
application/ld+json \
application/manifest+json \
application/rss+xml \
application/vnd.geo+json \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
Expand Down Expand Up @@ -651,6 +653,7 @@ FileETag None
# Data interchange
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/ld+json "access plus 0 seconds"
ExpiresByType application/vnd.geo+json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"

Expand Down
13 changes: 8 additions & 5 deletions test/fixtures/content/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ErrorDocument 404 /404.html
Header set X-UA-Compatible "IE=edge"
# `mod_headers` cannot match based on the content-type, however, this header
# should be send only for HTML documents and not for the other resources
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
Expand Down Expand Up @@ -97,6 +97,7 @@ ErrorDocument 404 /404.html
# Data interchange
AddType application/json json map
AddType application/ld+json jsonld
AddType application/vnd.geo+json geojson

# JavaScript
AddType application/javascript js
Expand Down Expand Up @@ -149,7 +150,7 @@ AddDefaultCharset utf-8

# Set `UTF-8` as the character encoding for other certain resources.
<IfModule mod_mime.c>
AddCharset utf-8 .atom .css .js .json .jsonld .rss .vtt .webapp .xml
AddCharset utf-8 .atom .css .geojson .js .json .jsonld .rss .vtt .webapp .xml
</IfModule>


Expand Down Expand Up @@ -206,7 +207,7 @@ AddDefaultCharset utf-8

<IfModule mod_headers.c>
Header set X-Frame-Options "DENY"
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
Header unset X-Frame-Options
</FilesMatch>
</IfModule>
Expand All @@ -217,7 +218,7 @@ AddDefaultCharset utf-8

<IfModule mod_headers.c>
Header set Content-Security-Policy "script-src 'self'; object-src 'self'"
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
Header unset Content-Security-Policy
</FilesMatch>
</IfModule>
Expand Down Expand Up @@ -278,7 +279,7 @@ AddDefaultCharset utf-8

<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
<FilesMatch "\.(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|txt|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
Header unset X-XSS-Protection
</FilesMatch>
</IfModule>
Expand Down Expand Up @@ -321,6 +322,7 @@ AddDefaultCharset utf-8
application/ld+json \
application/manifest+json \
application/rss+xml \
application/vnd.geo+json \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
Expand Down Expand Up @@ -379,6 +381,7 @@ FileETag None
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/ld+json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/vnd.geo+json "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"

# Favicon (cannot be renamed!) and cursor images
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/content/test.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 23.590020, 46.769373 ]
},
"properties": {
"name": "Unirii Square, Cluj-Napoca"
}
}
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ var tests = [
})
},

'test.geojson': {
headers: generateHeaders({
'cache-control': 'max-age=0, no-transform',
'content-type': 'application/vnd.geo+json; charset=utf-8'
})
},

'test.gif': {
headers: generateHeaders({
'access-control-allow-origin': '*',
Expand Down

0 comments on commit 16d3965

Please sign in to comment.