Skip to content

Commit

Permalink
Don't send Content-Type in the request - that header applies to respo…
Browse files Browse the repository at this point in the history
…nses.

We could send "Accept: application/json", but that is the default,
and since we vary on Accept, we can increase the cache hit rate
by either always sending the default Accept header, or never sending it.
I'm proposing the latter.

Also, don't send Accept-Language if the client doesn't define a language.
Again, if all clients do this, we get a better hit rate.
  • Loading branch information
kenlalonde committed Jan 14, 2015
1 parent 3f6f7db commit 060c0d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gapipy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'application_key': os.environ.get('GAPI_APPLICATION_KEY'),
'api_root': os.environ.get('GAPI_API_ROOT', 'https://rest.gadventures.com'),
'api_proxy': os.environ.get('GAPI_API_PROXY', ''),
'api_language': os.environ.get('GAPI_LANGUAGE', 'en'),
'api_language': os.environ.get('GAPI_LANGUAGE'),
'cache_backend': os.environ.get('GAPI_CACHE_BACKEND', 'gapipy.cache.SimpleCache'),
'cache_options': {'threshold': 500, 'default_timeout': 3600},
'debug': os.environ.get('GAPI_CLIENT_DEBUG', False),
Expand Down
5 changes: 3 additions & 2 deletions gapipy/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ def _request(self, uri, method, data=None, options=None, additional_headers=None
url = url.replace(api_proxy, '')

headers = {
'Content-Type': 'application/json',
# Why send the default? 'Accept': 'application/json',
'User-Agent': '{0}/{1}'.format(__title__, __version__),
'X-Application-Key': self.client.application_key,
'Accept-Language': self.client.api_language,
}
if self.client.api_language:
headers['Accept-Language'] = self.client.api_language
if additional_headers:
headers.update(additional_headers)

Expand Down

0 comments on commit 060c0d7

Please sign in to comment.