mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 00:12:39 +00:00
Merge pull request #1003 from lucamzanon/fix/navigation-protocol-account-limit
fix: detect HTTP/2 from the initial navigation timing so accounts aren't capped at five
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { getMaxAccounts, MAX_ACCOUNT_SLOTS } from '../account-utils';
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
describe('account limit protocol detection', () => {
|
||||
it('recognizes HTTP/2 from document navigation before resources load', () => {
|
||||
vi.spyOn(performance, 'getEntriesByType').mockImplementation(type => type === 'navigation' ? [{ nextHopProtocol: 'h2' } as PerformanceResourceTiming] : []);
|
||||
expect(getMaxAccounts()).toBe(MAX_ACCOUNT_SLOTS);
|
||||
});
|
||||
it('retains the conservative cap when no multiplexed protocol was observed', () => {
|
||||
vi.spyOn(performance, 'getEntriesByType').mockReturnValue([{ nextHopProtocol: 'http/1.1' } as PerformanceResourceTiming]);
|
||||
expect(getMaxAccounts()).toBe(5);
|
||||
});
|
||||
});
|
||||
@@ -87,7 +87,13 @@ export const MAX_ACCOUNTS_HTTP1 = 5;
|
||||
*/
|
||||
export function isHttp2Available(): boolean {
|
||||
if (typeof performance === 'undefined') return false;
|
||||
const entries = performance.getEntriesByType('resource') as PerformanceResourceTiming[];
|
||||
// The document connection is already known before any subresources finish
|
||||
// loading. Include it so a fresh login/restore doesn't incorrectly cap an
|
||||
// HTTP/2 page at five accounts. Do not assume h2 when timing is unavailable.
|
||||
const entries = [
|
||||
...performance.getEntriesByType('navigation'),
|
||||
...performance.getEntriesByType('resource'),
|
||||
] as PerformanceResourceTiming[];
|
||||
for (let i = entries.length - 1; i >= 0; i--) {
|
||||
const proto = entries[i].nextHopProtocol;
|
||||
if (proto === 'h2' || proto === 'h3') return true;
|
||||
|
||||
Reference in New Issue
Block a user