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

ParsedURL does not respect http.agent system property #2

Closed
ghost opened this issue Mar 25, 2021 · 3 comments
Closed

ParsedURL does not respect http.agent system property #2

ghost opened this issue Mar 25, 2021 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 25, 2021

See: https://issues.apache.org/jira/browse/BATIK-1300

The fix is to change org.apache.batik.util.ParsedURL, around line 90, to set globalUserAgent using the http.agent value. If the http.agent value is not set, fall back to a default (e.g., maintain backwards comparability).

@carlosame
Copy link
Member

I'm thinking of something like this:

@@ -83,11 +83,15 @@ public class ParsedURL {
 	 * The default protocol handler. This handler is used when other handlers fail
 	 * or no match for a protocol can be found.
 	 */
 	private static ParsedURLProtocolHandler defaultHandler = new ParsedURLDefaultProtocolHandler();
 
-	private static String globalUserAgent = "EchoSVG/0.1";
+	private static String globalUserAgent;
+
+	static {
+		globalUserAgent = System.getProperty("http.agent", "EchoSVG/0.1");
+	}
 
 	public static String getGlobalUserAgent() {
 		return globalUserAgent;
 	}

That is, changes to http.agent once the class was loaded would not be honored (otherwise it makes little sense to have a setGlobalUserAgent, not to talk of considerations about performance and consistency across requests).

Would that fit your needs?

@carlosame
Copy link
Member

Github closed this automatically after my commit, reopening so you can comment on the applied solution and possible further cleanups.

@carlosame carlosame reopened this Mar 26, 2021
@ghost
Copy link
Author

ghost commented Mar 27, 2021

Looks good. Ideally, we could migrate classes towards immutability, which is more of a clean-up item than a bug fix (e.g., make the global user agent final).

@ghost ghost closed this as completed Mar 27, 2021
This issue was closed.
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

No branches or pull requests

1 participant