mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: This fixes an issue where `POST /open-debugger?appId&device&target` does not return a proper status code, meaning that the request will never be answered and clients might hang until the request timeout is hit. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [GENERAL] [FIXED] - Respond with status code `200` when successfully launching RNDT Pull Request resolved: https://github.com/facebook/react-native/pull/46814 Test Plan: - `curl -v -X POST "<deviceUrl>"` - This should show a proper response for the request. before | after --- | ---  |  Reviewed By: NickGerleman Differential Revision: D63837025 Pulled By: huntie fbshipit-source-id: ac72fc793e015f0eec498f4a35b4fb9e301c5b32
80 lines
2.2 KiB
JavaScript
80 lines
2.2 KiB
JavaScript
/**
|
|
* 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
|
|
* @oncall react_native
|
|
*/
|
|
|
|
import type {JSONSerializable} from '../inspector-proxy/types';
|
|
|
|
import {Agent} from 'undici';
|
|
|
|
declare var globalThis: $FlowFixMe;
|
|
|
|
/**
|
|
* A version of `fetch` that is usable with the HTTPS server created in
|
|
* ServerUtils (which uses a self-signed certificate).
|
|
*/
|
|
export async function fetchLocal(
|
|
url: string,
|
|
options?: Partial<Parameters<typeof fetch>[1] & {dispatcher?: mixed}>,
|
|
): ReturnType<typeof fetch> {
|
|
return await fetch(url, {
|
|
...options,
|
|
// Node's native `fetch` comes from undici and supports the same options,
|
|
// including `dispatcher` which we use to make it accept self-signed
|
|
// certificates.
|
|
dispatcher:
|
|
options?.dispatcher ??
|
|
new Agent({
|
|
connect: {
|
|
rejectUnauthorized: false,
|
|
},
|
|
}),
|
|
});
|
|
}
|
|
|
|
export async function fetchJson<T: JSONSerializable>(url: string): Promise<T> {
|
|
const response = await fetchLocal(url);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status} ${response.statusText}`);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
/**
|
|
* Change the global fetch dispatcher to allow self-signed certificates.
|
|
* This runs with Jest's `beforeAll` and `afterAll`, and restores the original dispatcher.
|
|
*/
|
|
export function withFetchSelfSignedCertsForAllTests() {
|
|
const fetchOriginal = globalThis.fetch;
|
|
const selfSignedCertDispatcher = new Agent({
|
|
connect: {
|
|
rejectUnauthorized: false,
|
|
},
|
|
});
|
|
|
|
let fetchSpy;
|
|
|
|
beforeAll(() => {
|
|
// For some reason, setting the `selfSignedCertDispatcher` with `setGlobalDispatcher` doesn't work.
|
|
// Instead of using `setGlobalDispatcher`, we'll use a spy to intercept the fetch calls and add the dispatcher.
|
|
fetchSpy = jest
|
|
.spyOn(globalThis, 'fetch')
|
|
.mockImplementation((url, options) =>
|
|
fetchOriginal(url, {
|
|
...options,
|
|
dispatcher: options?.dispatcher ?? selfSignedCertDispatcher,
|
|
}),
|
|
);
|
|
});
|
|
|
|
afterAll(() => {
|
|
fetchSpy.mockRestore();
|
|
});
|
|
}
|