/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/dev-middleware/src/__tests__/getBaseUrlFromRequest-test.js
48 строк
1 KB
Sam Zhou
Standardize subtyping error code into `incompatible-type` in react native and metro (#53312)
18 авг 2025, 19:04
18 авг 2025, 19:04
cf664c6
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow strict-local * @format */ import getBaseUrlFromRequest from '../utils/getBaseUrlFromRequest'; test('returns a base url based on req.headers.host', () => { expect( getBaseUrlFromRequest(makeRequest('localhost:8081', false))?.href, ).toEqual('http://localhost:8081/'); }); test('identifies https using socket.encrypted', () => { expect( getBaseUrlFromRequest(makeRequest('secure.net:8443', true))?.href, ).toEqual('https://secure.net:8443/'); }); test('works with ipv6 hosts', () => { expect(getBaseUrlFromRequest(makeRequest('[::1]:8081', false))?.href).toEqual( 'http://[::1]:8081/', ); }); test('returns null on an invalid host header', () => { expect(getBaseUrlFromRequest(makeRequest('local[]host', false))).toBeNull(); }); test('returns null on an empty host header', () => { expect(getBaseUrlFromRequest(makeRequest(null, false))).toBeNull(); }); function makeRequest( host: ?string, encrypted: boolean, ): http$IncomingMessage<> | http$IncomingMessage<tls$TLSSocket> { // $FlowFixMe[incompatible-type] Partial mock of request return { socket: encrypted ? {encrypted: true} : {}, headers: host != null ? {host} : {}, }; }