MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / handler

Function handler

lib/handlers/get.mjs:25–169  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

23const prepConfig = 'accept=("message/rfc822" "application/ld+json" "text/turtle")'
24
25export default async function handler (req, res, next) {
26 const ldp = req.app.locals.ldp
27 const prep = req.app.locals.prep
28 const includeBody = req.method === 'GET'
29 const negotiator = new Negotiator(req)
30 const baseUri = ldp.resourceMapper.resolveUrl(req.hostname, req.path)
31 const path = res.locals.path || req.path
32 const requestedType = negotiator.mediaType()
33 const possibleRDFType = negotiator.mediaType(RDFs)
34
35 // deprecated kept for compatibility
36 res.header('MS-Author-Via', 'SPARQL')
37
38 res.header('Accept-Patch', 'text/n3, application/sparql-update, application/sparql-update-single-match')
39 res.header('Accept-Post', '*/*')
40 if (!path.endsWith('/') && !hasMagic(path)) res.header('Accept-Put', '*/*')
41
42 // Set live updates
43 if (ldp.live) {
44 res.header('Updates-Via', ldp.resourceMapper.resolveUrl(req.hostname).replace(/^http/, 'ws'))
45 }
46
47 debug(req.originalUrl + ' on ' + req.hostname)
48
49 const options = {
50 hostname: req.hostname,
51 path: path,
52 includeBody: includeBody,
53 possibleRDFType: possibleRDFType,
54 range: req.headers.range,
55 contentType: req.headers.accept
56 }
57
58 let ret
59 try {
60 ret = await ldp.get(options, req.accepts(['html', 'turtle', 'rdf+xml', 'n3', 'ld+json']) === 'html')
61 } catch (err) {
62 // set Accept-Put if container do not exist
63 if (err.status === 404 && path.endsWith('/')) res.header('Accept-Put', 'text/turtle')
64 // use globHandler if magic is detected
65 if (err.status === 404 && hasMagic(path)) {
66 debug('forwarding to glob request')
67 return globHandler(req, res, next)
68 } else {
69 debug(req.method + ' -- Error: ' + err.status + ' ' + err.message)
70 return next(err)
71 }
72 }
73
74 let stream
75 let contentType
76 let container
77 let contentRange
78 let chunksize
79
80 if (ret) {
81 stream = ret.stream
82 contentType = ret.contentType

Callers

nothing calls this directly

Calls 6

translateFunction · 0.90
globHandlerFunction · 0.85
HTTPErrorFunction · 0.85
resolveUrlMethod · 0.80
mapUrlToFileMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected