diff --git a/config.example.wikimedia.yaml b/config.example.wikimedia.yaml index 010d14a2a..204671a0d 100644 --- a/config.example.wikimedia.yaml +++ b/config.example.wikimedia.yaml @@ -33,8 +33,11 @@ default_project: &default_project cache_control: s-maxage=86400, max-age=86400 # 10 days Varnish caching, one day client-side purged_cache_control: s-maxage=864000, max-age=86400 - # Cache PDF for 5 minutes since it's not purged - pdf_cache_control: s-maxage=300, max-age=300 + pdf: + # Cache PDF for 5 minutes since it's not purged + cache_control: s-maxage=600, max-age=600 + uri: https://pdf-electron.wmflabs.org/pdf + secret: secret skip_updates: false # A different project template, sharing configuration options. diff --git a/config.test.yaml b/config.test.yaml index b82693fbf..fa0e07560 100644 --- a/config.test.yaml +++ b/config.test.yaml @@ -38,6 +38,11 @@ default_project: &default_project host: http://appservice.wmflabs.org events: {} purged_cache_control: test_purged_cache_control + pdf: + # Cache PDF for 5 minutes since it's not purged + cache_control: s-maxage=600, max-age=600 + uri: https://deployment-pdfrender.deployment-prep.eqiad.wmflabs/pdf + secret: secret skip_updates: false labs_project: &labs_project diff --git a/projects/wmf_default.yaml b/projects/wmf_default.yaml index de1aa74a6..b84a1f24e 100644 --- a/projects/wmf_default.yaml +++ b/projects/wmf_default.yaml @@ -55,8 +55,7 @@ paths: options: '{{merge({"random_cache_control": "s-maxage=2, max-age=1"}, options.mobileapps)}}' - path: v1/pdf.yaml - options: - response_cache_control: '{{options.pdf_cache_control}}' + options: '{{options.pdf}}' /feed: x-modules: - path: v1/feed.js diff --git a/projects/wmf_wiktionary.yaml b/projects/wmf_wiktionary.yaml index 8a24eedae..b350674bd 100644 --- a/projects/wmf_wiktionary.yaml +++ b/projects/wmf_wiktionary.yaml @@ -51,8 +51,7 @@ paths: response_cache_control: '{{options.purged_cache_control}}' host: '{{options.mobileapps.host}}' - path: v1/pdf.yaml - options: - response_cache_control: '{{options.pdf_cache_control}}' + options: '{{options.pdf}}' /transform: x-modules: - path: v1/transform.yaml diff --git a/v1/pdf.yaml b/v1/pdf.yaml index ad18c6fee..d111a6a14 100644 --- a/v1/pdf.yaml +++ b/v1/pdf.yaml @@ -38,12 +38,11 @@ paths: description: The PDF render of an article schema: type: file - # TODO: Add an etag somehow. How??? - #headers: - # ETag: - # description: > - # Syntax: "{revision}/{tid}". - # Example: "701384379/154d7bca-c264-11e5-8c2f-1b51b33b59fc" + headers: + ETag: + description: > + Syntax: "{revision}/{tid}". + Example: "701384379/154d7bca-c264-11e5-8c2f-1b51b33b59fc" '404': description: Unknown page title schema: @@ -54,17 +53,22 @@ paths: $ref: '#/definitions/problem' x-request-handler: + - get_latest_revision: + request: + method: get + uri: /{domain}/sys/page_revisions/page/{title} - get_pdf_from_backend: request: method: get - uri: 'https://pdf-electron.wmflabs.org/pdf?accessKey=secret&url=https://{{domain}}/wiki/{title}' + uri: '{{options.uri}}?accessKey={options.secret}&url=https://{{domain}}/wiki/{title}' return: status: 200 headers: content-disposition: 'attachment; filename={{request.params.title}}.pdf' content-type: '{{get_pdf_from_backend.headers.content-type}}' content-length: '{{get_pdf_from_backend.headers.content-length}}' - cache-control: '{{default(options.response_cache_control, "s-maxage=300, max-age=300")}}' + cache-control: '{{default(options.cache_control, "s-maxage=600, max-age=600")}}' + etag: '{{get_latest_revision.headers.etag}}' body: '{{get_pdf_from_backend.body}}' definitions: