intor 2.3.26 → 2.3.27
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/dist/express/src/adapters/express/middleware/create-intor.js +2 -1
- package/dist/express/src/server/shared/utils/parse-cookie-header.js +22 -0
- package/dist/types/src/server/index.d.ts +1 -0
- package/dist/types/src/server/shared/utils/index.d.ts +1 -0
- package/dist/types/src/server/shared/utils/parse-cookie-header.d.ts +4 -0
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ import 'p-limit';
|
|
|
9
9
|
import 'node:fs/promises';
|
|
10
10
|
import 'intor-translator';
|
|
11
11
|
import { getTranslator } from '../../../server/helpers/get-translator.js';
|
|
12
|
+
import { parseCookieHeader } from '../../../server/shared/utils/parse-cookie-header.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Resolves locale-aware routing for the current execution context.
|
|
@@ -31,7 +32,7 @@ function createIntor(config, options) {
|
|
|
31
32
|
const { locale, localeSource, pathname } = await resolveInbound(config, req.path, false, {
|
|
32
33
|
host: req.hostname,
|
|
33
34
|
query: normalizeQuery(req.query),
|
|
34
|
-
cookie: req.
|
|
35
|
+
cookie: parseCookieHeader(req.headers.cookie)[config.cookie.name],
|
|
35
36
|
detected: localeFromAcceptLanguage || config.defaultLocale,
|
|
36
37
|
});
|
|
37
38
|
// --------------------------------------------------
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a raw HTTP Cookie header into a key-value record.
|
|
3
|
+
*/
|
|
4
|
+
function parseCookieHeader(cookieHeader) {
|
|
5
|
+
if (!cookieHeader)
|
|
6
|
+
return {};
|
|
7
|
+
const record = {};
|
|
8
|
+
// Split the Cookie header into individual key-value pairs
|
|
9
|
+
const pairs = cookieHeader.split(";");
|
|
10
|
+
for (const pair of pairs) {
|
|
11
|
+
// Locate the first "=" to separate key and value
|
|
12
|
+
const index = pair.indexOf("=");
|
|
13
|
+
if (index === -1)
|
|
14
|
+
continue;
|
|
15
|
+
const key = pair.slice(0, index).trim();
|
|
16
|
+
const value = pair.slice(index + 1).trim();
|
|
17
|
+
record[key] = decodeURIComponent(value);
|
|
18
|
+
}
|
|
19
|
+
return record;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { parseCookieHeader };
|
|
@@ -2,3 +2,4 @@ export { intor, type IntorValue } from "./intor";
|
|
|
2
2
|
export { loadMessages } from "./messages";
|
|
3
3
|
export { type TranslatorInstanceServer } from "./translator";
|
|
4
4
|
export { getTranslator, type GetTranslatorParams, loadMessagesFromUrl, } from "./helpers";
|
|
5
|
+
export { parseCookieHeader } from "./shared/utils";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseCookieHeader } from "./parse-cookie-header";
|