h3 0.8.3 → 0.8.4

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.
package/README.md CHANGED
@@ -101,7 +101,7 @@ app.use('/1', eventHandler(() => '<h1>Hello world!</h1>'))
101
101
  .use('/2', eventHandler(() => '<h1>Goodbye!</h1>'))
102
102
 
103
103
  // Legacy middleware with 3rd argument are automatically promisified
104
- app.use(fromNodeMiddleware((req, res, next) => { req.setHeader('X-Foo', 'bar'); next() }))
104
+ app.use(fromNodeMiddleware((req, res, next) => { req.setHeader('x-foo', 'bar'); next() }))
105
105
 
106
106
  // Lazy loaded routes using { lazy: true }
107
107
  app.use('/big', () => import('./big-handler'), { lazy: true })
package/dist/index.cjs CHANGED
@@ -88,7 +88,7 @@ function sendError(event, error, debug) {
88
88
  if (h3Error.statusMessage) {
89
89
  event.res.statusMessage = h3Error.statusMessage;
90
90
  }
91
- event.res.setHeader("Content-Type", MIMES.json);
91
+ event.res.setHeader("content-type", MIMES.json);
92
92
  event.res.end(JSON.stringify(responseBody, null, 2));
93
93
  }
94
94
  function isError(input) {
@@ -195,7 +195,7 @@ function handleCacheHeaders(event, opts) {
195
195
  if (opts.modifiedTime) {
196
196
  const modifiedTime = new Date(opts.modifiedTime);
197
197
  const ifModifiedSince = event.req.headers["if-modified-since"];
198
- event.res.setHeader("Last-Modified", modifiedTime.toUTCString());
198
+ event.res.setHeader("last-modified", modifiedTime.toUTCString());
199
199
  if (ifModifiedSince) {
200
200
  if (new Date(ifModifiedSince) >= opts.modifiedTime) {
201
201
  cacheMatched = true;
@@ -203,16 +203,16 @@ function handleCacheHeaders(event, opts) {
203
203
  }
204
204
  }
205
205
  if (opts.etag) {
206
- event.res.setHeader("Etag", opts.etag);
206
+ event.res.setHeader("etag", opts.etag);
207
207
  const ifNonMatch = event.req.headers["if-none-match"];
208
208
  if (ifNonMatch === opts.etag) {
209
209
  cacheMatched = true;
210
210
  }
211
211
  }
212
- event.res.setHeader("Cache-Control", cacheControls.join(", "));
212
+ event.res.setHeader("cache-control", cacheControls.join(", "));
213
213
  if (cacheMatched) {
214
214
  event.res.statusCode = 304;
215
- event.res.end("");
215
+ event.res.end();
216
216
  return true;
217
217
  }
218
218
  return false;
@@ -236,13 +236,13 @@ function send(event, data, type) {
236
236
  });
237
237
  }
238
238
  function defaultContentType(event, type) {
239
- if (type && !event.res.getHeader("Content-Type")) {
240
- event.res.setHeader("Content-Type", type);
239
+ if (type && !event.res.getHeader("content-type")) {
240
+ event.res.setHeader("content-type", type);
241
241
  }
242
242
  }
243
243
  function sendRedirect(event, location, code = 302) {
244
244
  event.res.statusCode = code;
245
- event.res.setHeader("Location", location);
245
+ event.res.setHeader("location", location);
246
246
  const encodedLoc = location.replace(/"/g, "%22");
247
247
  const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head></html>`;
248
248
  return send(event, html, MIMES.html);
@@ -441,7 +441,7 @@ class H3Event {
441
441
  this.res.statusMessage = response.statusText;
442
442
  }
443
443
  if (response.redirected) {
444
- this.res.setHeader("Location", response.url);
444
+ this.res.setHeader("location", response.url);
445
445
  }
446
446
  if (!response._body) {
447
447
  return this.res.end();
package/dist/index.mjs CHANGED
@@ -86,7 +86,7 @@ function sendError(event, error, debug) {
86
86
  if (h3Error.statusMessage) {
87
87
  event.res.statusMessage = h3Error.statusMessage;
88
88
  }
89
- event.res.setHeader("Content-Type", MIMES.json);
89
+ event.res.setHeader("content-type", MIMES.json);
90
90
  event.res.end(JSON.stringify(responseBody, null, 2));
91
91
  }
92
92
  function isError(input) {
@@ -193,7 +193,7 @@ function handleCacheHeaders(event, opts) {
193
193
  if (opts.modifiedTime) {
194
194
  const modifiedTime = new Date(opts.modifiedTime);
195
195
  const ifModifiedSince = event.req.headers["if-modified-since"];
196
- event.res.setHeader("Last-Modified", modifiedTime.toUTCString());
196
+ event.res.setHeader("last-modified", modifiedTime.toUTCString());
197
197
  if (ifModifiedSince) {
198
198
  if (new Date(ifModifiedSince) >= opts.modifiedTime) {
199
199
  cacheMatched = true;
@@ -201,16 +201,16 @@ function handleCacheHeaders(event, opts) {
201
201
  }
202
202
  }
203
203
  if (opts.etag) {
204
- event.res.setHeader("Etag", opts.etag);
204
+ event.res.setHeader("etag", opts.etag);
205
205
  const ifNonMatch = event.req.headers["if-none-match"];
206
206
  if (ifNonMatch === opts.etag) {
207
207
  cacheMatched = true;
208
208
  }
209
209
  }
210
- event.res.setHeader("Cache-Control", cacheControls.join(", "));
210
+ event.res.setHeader("cache-control", cacheControls.join(", "));
211
211
  if (cacheMatched) {
212
212
  event.res.statusCode = 304;
213
- event.res.end("");
213
+ event.res.end();
214
214
  return true;
215
215
  }
216
216
  return false;
@@ -234,13 +234,13 @@ function send(event, data, type) {
234
234
  });
235
235
  }
236
236
  function defaultContentType(event, type) {
237
- if (type && !event.res.getHeader("Content-Type")) {
238
- event.res.setHeader("Content-Type", type);
237
+ if (type && !event.res.getHeader("content-type")) {
238
+ event.res.setHeader("content-type", type);
239
239
  }
240
240
  }
241
241
  function sendRedirect(event, location, code = 302) {
242
242
  event.res.statusCode = code;
243
- event.res.setHeader("Location", location);
243
+ event.res.setHeader("location", location);
244
244
  const encodedLoc = location.replace(/"/g, "%22");
245
245
  const html = `<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head></html>`;
246
246
  return send(event, html, MIMES.html);
@@ -439,7 +439,7 @@ class H3Event {
439
439
  this.res.statusMessage = response.statusText;
440
440
  }
441
441
  if (response.redirected) {
442
- this.res.setHeader("Location", response.url);
442
+ this.res.setHeader("location", response.url);
443
443
  }
444
444
  if (!response._body) {
445
445
  return this.res.end();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Tiny JavaScript Server",
5
5
  "repository": "unjs/h3",
6
6
  "license": "MIT",