itube-specs 0.0.1026 → 0.0.1027

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "itube-specs",
3
3
  "type": "module",
4
- "version": "0.0.1026",
4
+ "version": "0.0.1027",
5
5
  "main": "./nuxt.config.ts",
6
6
  "types": "./types/index.d.ts",
7
7
  "scripts": {
@@ -18,6 +18,7 @@ export default defineEventHandler((event) => {
18
18
  subdomains,
19
19
  codes,
20
20
  defaultCode,
21
+ protocol: getRequestProtocol(event, { xForwardedProto: true }),
21
22
  });
22
23
 
23
24
  if (vary) setResponseHeader(event, 'Vary', 'Accept-Language, Cookie');
@@ -25,12 +25,18 @@ describe('resolveLocaleRedirect', () => {
25
25
  subdomains: { ru: 'ru', ja: 'jp', de: 'de' },
26
26
  codes: CODES,
27
27
  defaultCode: 'en',
28
+ protocol: 'https',
28
29
  };
29
30
 
30
31
  it('уводит с базового домена на поддомен языка браузера', () => {
31
32
  expect(resolveLocaleRedirect(base)).toEqual({ vary: true, location: 'https://jp.a.com/videos?page=2' });
32
33
  });
33
34
 
35
+ it('протокол — как у запроса: локально без прокси остаётся http', () => {
36
+ expect(resolveLocaleRedirect({ ...base, headers: { ...base.headers, host: 'localhost:3200' }, protocol: 'http' }).location)
37
+ .toBe('http://jp.localhost:3200/videos?page=2');
38
+ });
39
+
34
40
  it('язык браузера — дефолтный: без редиректа, но с Vary', () => {
35
41
  expect(resolveLocaleRedirect({ ...base, headers: { ...base.headers, 'accept-language': 'en-US' } })).toEqual({ vary: true });
36
42
  });
@@ -52,6 +52,8 @@ export interface ILocaleRedirectInput {
52
52
  subdomains: LocaleSubdomains
53
53
  codes: readonly string[]
54
54
  defaultCode: string
55
+ /** Протокол запроса (`getRequestProtocol` с учётом x-forwarded-proto): без прокси локально — http. */
56
+ protocol: string
55
57
  }
56
58
 
57
59
  export interface ILocaleRedirectDecision {
@@ -69,7 +71,7 @@ export interface ILocaleRedirectDecision {
69
71
  * переключателем, а cookie могла не доехать: на localhost она живёт только на своём поддомене.
70
72
  */
71
73
  export function resolveLocaleRedirect(input: ILocaleRedirectInput): ILocaleRedirectDecision {
72
- const { method, path, headers, langCookie, subdomains, codes, defaultCode } = input;
74
+ const { method, path, headers, langCookie, subdomains, codes, defaultCode, protocol } = input;
73
75
  const skip = { vary: false };
74
76
 
75
77
  if (method !== 'GET') return skip;
@@ -97,7 +99,6 @@ export function resolveLocaleRedirect(input: ILocaleRedirectInput): ILocaleRedir
97
99
  const target = localeDomain(detected, baseDomainFromHost(host, subdomains), subdomains);
98
100
  if (target === host) return { vary: true };
99
101
 
100
- const protocol = headers['x-forwarded-proto'] || 'https';
101
102
 
102
103
  return { vary: true, location: `${protocol}://${target}${path}` };
103
104
  }