@nxtedition/lib 21.1.2 → 21.2.1

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/http.js +13 -2
  2. package/package.json +2 -1
package/http.js CHANGED
@@ -7,6 +7,7 @@ import querystring from 'fast-querystring'
7
7
  import compose from 'koa-compose'
8
8
  import http from 'http'
9
9
  import fp from 'lodash/fp.js'
10
+ import cookie from 'cookie'
10
11
  import tp from 'timers/promises'
11
12
 
12
13
  const kAbortController = Symbol('abortController')
@@ -42,6 +43,7 @@ export class Context {
42
43
  #logger
43
44
  #headers
44
45
  #query
46
+ #cookies
45
47
 
46
48
  constructor(req, res, logger) {
47
49
  assert(req)
@@ -85,7 +87,9 @@ export class Context {
85
87
  }
86
88
 
87
89
  get query() {
88
- this.#query ??= this.url.search.length > 1 ? querystring.parse(this.url.search.slice(1)) : {}
90
+ if (this.#query === undefined) {
91
+ this.#query = this.url.search.length > 1 ? querystring.parse(this.url.search.slice(1)) : null
92
+ }
89
93
  return this.#query
90
94
  }
91
95
 
@@ -106,9 +110,16 @@ export class Context {
106
110
  }
107
111
 
108
112
  get headers() {
109
- this.#headers ??= {}
110
113
  return this.#headers
111
114
  }
115
+
116
+ get cookies() {
117
+ if (this.#cookies === undefined) {
118
+ this.#cookies = this.req.headers.cookie ? cookie.parse(this.req.headers.cookie) : null
119
+ }
120
+
121
+ return this.#cookies
122
+ }
112
123
  }
113
124
 
114
125
  export async function request2(ctx, next) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "21.1.2",
3
+ "version": "21.2.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -59,6 +59,7 @@
59
59
  "@elastic/transport": "^8.7.1",
60
60
  "@nxtedition/nxt-undici": "^4.2.13",
61
61
  "content-type": "^1.0.5",
62
+ "cookie": "^0.7.2",
62
63
  "date-fns": "^3.6.0",
63
64
  "fast-querystring": "^1.1.1",
64
65
  "hasha": "^6.0.0",