Skip to content

JSPWIKI-1310 Add the download of the content of an attachment to the REST API - #653

Draft
arturobernalg wants to merge 30 commits into
apache:masterfrom
arturobernalg:feature/JSPWIKI-1310-attachment-content
Draft

arturobernalg wants to merge 30 commits into
apache:masterfrom
arturobernalg:feature/JSPWIKI-1310-attachment-content

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

Part of JSPWIKI-1310. This pull request builds on #589, #590, #645, #646 and #650, so it shows their commits until they are merged; the new commit is the last one.

It adds GET /api/v1/pages/{name}/attachments/{file}, to download the content of an attachment of a page the caller may view. The version parameter selects a version of the attachment.

  • The content is always sent as a download (Content-Disposition: attachment) with X-Content-Type-Options: nosniff, never inline, because an attachment can be a page with script and the API answers on the origin of the wiki. The type is the one the server knows for the extension, or application/octet-stream.
  • The permission to view is checked on the page and on the attachment, before anything is read. A missing page or attachment is 404, a name that leaves the directory is 400, and the errors are JSON like in the rest of the API.
  • AttachmentServlet.encodeFileName is made public, so that the file name in the header is written the same way as by the attachment servlet.
  • openapi.yaml describes it, and ApiV1ServletTest has nine new tests: content, type, length and headers, a web page as attachment, a version, 404 for the attachment and for the page, 401 without sending the content, 400 for a bad file name and a bad version.

I also ran it on a Tomcat 10.1 with the war of this branch: the latest version and version 1 of an attachment come back with the right bytes, an HTML attachment is a download, and the errors are the JSON ones.

ChangeLog.md is updated.

…n OpenAPI file that a test compares with the answers
…o feature/JSPWIKI-1310-plugins-suggestions

# Conflicts:
#	ChangeLog.md
…310-plugins-suggestions

# Conflicts:
#	ChangeLog.md
…o feature/JSPWIKI-1310-plugins-suggestions

# Conflicts:
#	ChangeLog.md
#	jspwiki-main/src/main/java/org/apache/wiki/search/DefaultSearchManager.java
…gestions' into feature/JSPWIKI-1310-pages-read
… into feature/JSPWIKI-1310-pages-list

# Conflicts:
#	jspwiki-main/src/test/java/org/apache/wiki/rest/ApiV1ServletTest.java
…gestions' into feature/JSPWIKI-1310-pages-read
…gestions' into feature/JSPWIKI-1310-pages-read

# Conflicts:
#	ChangeLog.md
… into feature/JSPWIKI-1310-pages-list

# Conflicts:
#	ChangeLog.md
…d a description that broke the JAX-RS generator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant