marklogic-community / roxy

Deployment tool for MarkLogic applications. Also provides optional unit test and XQuery MVC structure
Other
87 stars 66 forks source link

Improve rh:set-content-type mapping of formats/extensions to content types. #857

Open rhdunn opened 6 years ago

rhdunn commented 6 years ago

The issue

Short description of the problem:

The routing-helper.xqy set-content-type helper function maps formats to mimetypes, and if it does not recognise the format, it sets the content type to that format. The format is set in router.xqy, which comes from the file extension in the routes XML in roxy/config/defaults.xqy.

This means that unsupported formats have the file extension as the content type, not their associated mimetype. This includes controllers with a txt extension, as text is mapped, but txt is not.

What are the steps to reproduce the problem?
  1. Create a controller returning an unsupported format (e.g. zip, svg, or txt).
  2. Call the controller with that unsupported format extension (e.g. /foo/bar.zip).
  3. Inspect the returned content-type header (e.g. in the Network tab of a web browser's developer tools). This can also make Firefox report "XML Parsing Error: not well-formed" when handling those files via AJAX/jquery.
Thoughts/comments:

The name set-content-type is misleading, it is really set-format.

It would be useful if the format/file extension to content type could use the MarkLogic mimetype data. This could replace the hand-coded if/else format mapping in set-content-type. Alternatively, the config:ROXY-OPTIONS formats should be set with a similar list of extensions to mimetypes covering common formats.

If the format is not recognised, it should throw an error. This will allow the developers to add the format, instead of the server sending the wrong context type creating a silent, difficult to debug error.

Tech Specs

Which Operating System are you using?

Windows 10

Which version of MarkLogic are you using?

8.0-6.3

Which version of Roxy are you using (see version.txt)?

1.7.4