braid-blob 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +37 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -39,7 +39,15 @@ braid_blob.serve = async (req, res, options = {}) => {
39
39
 
40
40
  if (our_v == null) {
41
41
  res.statusCode = 404
42
- return res.end('')
42
+ res.setHeader('Content-Type', 'text/plain')
43
+ return res.end('File Not Found')
44
+ }
45
+
46
+ if (meta.content_type && req.headers.accept &&
47
+ !isAcceptable(meta.content_type, req.headers.accept)) {
48
+ res.statusCode = 406
49
+ res.setHeader('Content-Type', 'text/plain')
50
+ return res.end(`Content-Type of ${meta.content_type} not in Accept: ${req.headers.accept}`)
43
51
  }
44
52
 
45
53
  // Set Version header;
@@ -164,4 +172,32 @@ async function slurp(req) {
164
172
  })
165
173
  }
166
174
 
175
+ function isAcceptable(contentType, acceptHeader) {
176
+ // If no Accept header or Accept is */*, accept everything
177
+ if (!acceptHeader || acceptHeader === '*/*') return true;
178
+
179
+ // Parse the Accept header into individual media types
180
+ const acceptTypes = acceptHeader.split(',').map(type => type.trim());
181
+
182
+ for (const acceptType of acceptTypes) {
183
+ // Remove quality values (e.g., "text/html;q=0.9" -> "text/html")
184
+ const cleanAcceptType = acceptType.split(';')[0].trim();
185
+
186
+ // Exact match
187
+ if (cleanAcceptType === contentType) return true;
188
+
189
+ // Wildcard subtype match (e.g., "image/*" matches "image/png")
190
+ if (cleanAcceptType.endsWith('/*')) {
191
+ const acceptMain = cleanAcceptType.slice(0, -2);
192
+ const contentMain = contentType.split('/')[0];
193
+ if (acceptMain === contentMain) return true;
194
+ }
195
+
196
+ // Full wildcard
197
+ if (cleanAcceptType === '*/*') return true;
198
+ }
199
+
200
+ return false;
201
+ }
202
+
167
203
  module.exports = braid_blob
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-blob",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Library for collaborative blobs over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-blob",