Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌎 Allow https proxy from env var #933

Merged
merged 3 commits into from
Feb 23, 2024
Merged

🌎 Allow https proxy from env var #933

merged 3 commits into from
Feb 23, 2024

Conversation

fwkoch
Copy link
Collaborator

@fwkoch fwkoch commented Feb 22, 2024

This PR moves fetch to a function on session to centralize the logic, then adds HTTPS_PROXY consumption: #919

@@ -10,7 +10,6 @@ export {
export { exec, makeExecutable } from './exec.js';
export { clirun, tic } from './utils.js';
export { isUrl } from './isUrl.js';
export { Session, getSession } from './session.js';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This super minimal session implementation isn't used anywhere (besides a single test file - easily replaced). I just removed it so we did not need to implement fetch in this package.

@@ -111,7 +110,7 @@ export async function buildHtml(session: ISession, opts: any) {
// Fetch all HTML pages and assets by the template
await Promise.all(
routes.map(async (page) => {
const resp = await fetch(page.url);
const resp = await session.fetch(page.url);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure about the implications of using an HTTPS proxy for localhost requests... These potentially happen here (for building static HTML) as well as in myst-execute, when searching for jupyter sessions.

Do we need logic in fetch for these cases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sounds like we do? i.e. skip proxy requests for any localhost / 127.0.0.1 requests based on the url, and proxy all others?

async fetch(url: URL | RequestInfo, init?: RequestInit): Promise<Response> {
const urlOnly = new URL((url as Request).url ?? (url as URL | string));
this.log.debug(`Fetching: ${urlOnly}`);
if (this.proxyAgent && !LOCALHOSTS.includes(urlOnly.hostname)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept this localhost check super simple... We could try to catch more edge cases with something like this: https://github.com/Kikobeats/localhost-url-regex/blob/master/src/index.js and/or we could add a process.env.LOCALHOST or something to allow users to specify if they've changed it....

I feel like all of that is probably overkill though.

@fwkoch
Copy link
Collaborator Author

fwkoch commented Feb 23, 2024

I tested basic functionality running against a simple localhost proxy - all seems to work ok. Good enough to release and see how it goes with "real" proxies, I think.

Copy link
Collaborator

@rowanc1 rowanc1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @fwkoch, merge away when you are ready!

@fwkoch fwkoch merged commit 36decbb into main Feb 23, 2024
4 checks passed
@fwkoch fwkoch deleted the feat/https-proxy branch February 23, 2024 21:59
@stevejpurves
Copy link
Contributor

@fwkoch what did you use for your local proxy in the end (realizing here that a basic http server won't cut it, as it won't handle CONNECT)? I've had trouble getting it to connect to http-configurable-proxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants