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

pac-interpreter: Initial implementation #1

Merged
merged 8 commits into from
Oct 12, 2023
Merged

pac-interpreter: Initial implementation #1

merged 8 commits into from
Oct 12, 2023

Conversation

jbaldassari
Copy link
Contributor

@jbaldassari jbaldassari commented Jul 21, 2023

Initial implementation of the PAC interpreter. See README for detailed documentation.

Artifacts are published to the Sonatype repository from which they can be released to Maven Central.

@jbaldassari jbaldassari requested a review from a team July 21, 2023 05:40
@jbaldassari jbaldassari changed the title Initial implementation pac-interpreter: Initial implementation Jul 21, 2023
Copy link

@gcooney gcooney left a comment

Choose a reason for hiding this comment

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

Couple questions and suggestions but overall looks good to me!


- name: Build and test
run: ./gradlew test --console plain

Copy link

Choose a reason for hiding this comment

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

do we want a step to publish the test results as an artifact?

* @return the result of executing the PAC script with the given URL and host.
* @throws PacInterpreterException if an error occurs evaluating the PAC script or parsing the results.
*/
FindProxyResult findProxyForUrl(final String url, final String host) throws PacInterpreterException;
Copy link

Choose a reason for hiding this comment

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

So does this still take the full url in the first argument or is it a relative url?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First argument is the full URL. Second argument is just the hostname (without port). It seems strange, but that's the contract of the FindProxyForURL function in the PAC spec, so it made sense to mirror that.

} catch (IOException e) {
// This file is included in the jar, so if we can't open/read it something is seriously wrong.
// There is likely nothing the caller can do to handle this, so just rethrow as a runtime exception.
throw new RuntimePacInterpreterException(String.format("Failed to read \"%s\" from classpath", PAC_UTILS_PATH), e);
Copy link

Choose a reason for hiding this comment

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

If it's fatal and the user can't do anything should it be an Error instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean an exception that extends java.lang.Error instead of java.lang.RuntimeException? I could do that. There's a java.io.IOError that might make sense here.

return Engine.newBuilder()
// Silence GraalVM warnings
// See: https://www.graalvm.org/latest/reference-manual/js/FAQ/#warning-implementation-does-not-support-runtime-compilation
.option("engine.WarnInterpreterOnly", "false")
Copy link

Choose a reason for hiding this comment

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

looks like there is a performance hit but I assume we are ok with it since the pac interpreter shuold be realtively compute lite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly, and since we'll be caching the PAC itself, I think it won't be too bad. I've looked into how to get this working properly with the Graal JIT, but it's quite complicated. When I get to integrating this into the Link Agent I might see if I can get it working. Now that I'm thinking about it though, I might not want to disable this message permanently. Maybe I'll just document how to disable it via system properties instead.

* James Baldassari <[email protected]> 07/14/2023
*/

function dnsDomainIs(host, domain) {
Copy link

Choose a reason for hiding this comment

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

Any specific changes worth reviewing here. I don't feel it's necesary to review the source code but if there are any deltas I can give them a look over...

Copy link
Contributor Author

@jbaldassari jbaldassari Jul 27, 2023

Choose a reason for hiding this comment

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

Nope, this is all standard stuff straight from Mozilla. The only changes are my two functions at the bottom that use the Graal-JVM integration to do things that JavaScript can't. But those are almost trivial implementations.

Copy link

@xtina xtina left a comment

Choose a reason for hiding this comment

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

@jbaldassari jbaldassari merged commit 78e29de into main Oct 12, 2023
1 check passed
@jbaldassari jbaldassari deleted the initial branch October 12, 2023 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants