New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve badges directly from local filesystem #4561

Merged
merged 5 commits into from Aug 27, 2018

Conversation

Projects
None yet
4 participants
@davidfischer
Contributor

davidfischer commented Aug 23, 2018

  • Serves badges directly without a redirect
  • Attaches the cache control header directly to the response as GitHub doesn't respect the cache-control headers on a redirect. GitHub only respects the cache-control header on the 2xx response.
  • A bit of code simplification

This solves an issue that arose because the badges need to be explicitly not cached or have a very short cache TTL. When no cache-control headers are present (as on this badge for example), sometimes other intermediaries -- github in this case -- cache it too long. This PR keeps the cache rules and the response together in the code so this problem doesn't arise again like it did previously in #3323.

Similar to #4559 but reads from a local file instead of possibly remote one.

Fixes #4557

@davidfischer davidfischer requested a review from rtfd/core Aug 23, 2018

@ericholscher

I like this approach, just one question.

Show outdated Hide outdated readthedocs/projects/views/public.py
Show outdated Hide outdated readthedocs/projects/views/public.py
# Unknown project
unknown_project_url = reverse('project_badge', args=['fake-project'])
res = self.client.get(unknown_project_url, {'version': 'latest'})
self.assertContains(res, 'unknown')

This comment has been minimized.

@humitos

humitos Aug 23, 2018

Member

nitpick: can we add a check here that the Content-Type header is the correct one, at least in one of these?

@humitos

humitos Aug 23, 2018

Member

nitpick: can we add a check here that the Content-Type header is the correct one, at least in one of these?

This comment has been minimized.

@davidfischer

davidfischer Aug 23, 2018

Contributor

Ok

@davidfischer
Show outdated Hide outdated readthedocs/projects/views/public.py

davidfischer added some commits Aug 23, 2018

@agjohnson

Looks good, just some nitpicks

Show outdated Hide outdated readthedocs/projects/views/public.py
Show outdated Hide outdated readthedocs/projects/views/public.py

@agjohnson agjohnson added this to the 2.7 milestone Aug 27, 2018

davidfischer added some commits Aug 27, 2018

@agjohnson agjohnson merged commit 20e28ca into master Aug 27, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@agjohnson agjohnson deleted the davidfischer/more-badge-changes branch Aug 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment