Skip to content

Commit

Permalink
Merge pull request #87 from xsnippet/remove-vary-header
Browse files Browse the repository at this point in the history
Remove Vary header from response
  • Loading branch information
malor committed Apr 29, 2018
2 parents 603bc63 + 31760cf commit 42c023c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
20 changes: 0 additions & 20 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,9 @@
:license: MIT, see LICENSE for details
"""

import pytest

from xsnippet.api.application import create_app


@pytest.mark.parametrize('name, value', [
('Accept', 'application/json'),
('Accept-Encoding', 'gzip'),
('Api-Version', '1.0'),
])
async def test_http_vary_header(name, value, testapp):
resp = await testapp.get('/', headers={
name: value,
})

parts = set([
hdr.strip() for hdr in resp.headers['Vary'].split(',')
])

assert name in parts
await resp.release()


async def test_deprecated_routes(testapp):
app = create_app()

Expand Down
29 changes: 0 additions & 29 deletions xsnippet/api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,6 @@
from . import database, routes, middlewares


async def _inject_vary_header(request, response):
"""Inject a ``Vary`` HTTP header to response if needed.
Depends on whether request has varies HTTP headers or not, we may or may
not inject a ``Vary`` HTTP header into response. Since XSnippet API
implements content negotiation and API versioning, we've got to pass at
least ``Accept`` and ``Api-Version`` HTTP headers.
:param request: an http request instance
:type request: :class:`~aiohttp.web.Request`
:param response: an http response instance
:type response: :class:`~aiohttp.web.Response`
"""
known = set([
'Accept',
'Accept-Encoding',
'Api-Version',
])
found = [header for header in known if header in request.headers]

if found:
response.headers['Vary'] = ', '.join(found)


@picobox.pass_('conf')
@picobox.pass_('database', as_='db')
def create_app(conf, db):
Expand All @@ -65,8 +40,4 @@ def create_app(conf, db):
app.router.add_routes(routes.v1)
app.on_startup.append(functools.partial(database.setup, db=db))

# We need to respond with Vary header time to time in order to avoid
# issues with cache on client side.
app.on_response_prepare.append(_inject_vary_header)

return app

0 comments on commit 42c023c

Please sign in to comment.