content-selection-module v1.0.2
Content-Selection-Component
This repo contains two custom 'content-selection' components for the Community Solid Server.
ContentSelectionRedirectHttpHandler
ContentSelectionRedirectHttpHandler uses redirects to point the client to the resource file that best matches the requested content type. The component is only active on specified paths and uses the specified type mappings to create HTTP redirects (3xx status plus location
header). The ContentSelectionRedirectHttpHandler extends the HttpHandler class similar to the RedirectingHttpHandler.
- only HTTP GET
- only on specified server paths
- only file URIs without extension
- (optionally) only if match between accept header and type mappings
Example: GET 'accept: text/html' from /sensor-1/data
-> 303 'location: /sensor-1/data.html' no content
ContentSelectionOperationHandler
ContentSelectionOperationHandler directly delivers the resource file that best matches the requested content type. The component is only active on specified paths and uses the specified type mappings to determine a URI with file extension which is then loaded from the ResourceStore. ContentSelectionOperationHandler extends the abstract OperationHandler class similar to the GetOperationHandler.
Conditions under which the ContentSelectionOperationHandler is active: 1. only HTTP GET 2. only on specified server paths 3. only file URIs without extension 4. only if the target resource does not exist
Example: GET 'accept: text/html' from /sensor-1/data
-> 200 'location: /sensor-1/data.html' with file content
The ContentSelectionOperationHandler incompletely imitates the behavior of the Apache Module mod_negotiation.
Future Work
Conceptual:
- Consider Mapping between HTTP URLs and filenames on a server by TimBL
- ExtensionBasedMapper maps URLs to files with extensions
- Remove limitation to GET requests
- Behavior if no specific content type is requested by the user
- Currently: type mapping should include mapping for default
*/*
- Better: HTTP 300 with HTML overview of available data representations
- Currently: type mapping should include mapping for default
Technical:
- Default type mapings
- Using the mime-types module that CSS uses
- Derived from Apache httpd mime.types
Setup
Install dependencies (CSS, components.js, Jest): npm i
Transpile TypeScript: npm run build
Start the ContentSelectionRedirectHttpHandler: npm run start:redirect
Start the ContentSelectionOperationHandler: npm run start:deliver
Run the tests (for ContentSelectionRedirectHttpHandler): npm test
CURL example: curl -v -H 'accept: text/html' http://localhost:3000/sensor-1/data
Use as NPM package
Clone CSS repo: git clone git@github.com:CommunitySolidServer/CommunitySolidServer.git
Add content-selection-module from NPM: npm i content-selection-module
Install CSS deps: npm i
Start CSS with a base and a content-selection config:node ./bin/server.js -c config/file.json node_modules/content-selection-module/config/contentselection-redirect.json -f .data
or npm start -- -c config/file.json ...
Bug?: Logs from the content-selection-module are not shown
Known Issues
Components.js can cause problems on Windows if the file path contains a whitespace
- Example error
Invalid term IRI WebAclMetadataCollector
- Example error
Flexible config that can be combined with any other CSS config
- Possible if CSS upgrades the componentsjs version to v5.5 or v6.0 (next major release)
- Current workaround: add componentsjs@5.5.1 to dependencies of this package