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

Use UpdateSite implementation for connect and preValidate #10172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

slide
Copy link
Member

@slide slide commented Jan 17, 2025

Different UpdateSites may need to connect to URLs differently, (e.g., authentication, etc.), this adds a method to UpdateSite which creates the URLConnection that will be used for connecting. This allows such things as a password protected UpdateSite which can add the authorization information to the connection prior to returning it. In addition the preValidate method can be overridden in UpdateSite implementations to validate the URL before trying to download it.

Testing done

No direct tests were added, but the full set of tests were run locally on the change.

Proposed changelog entries

  • Developer: Allow UpdateSites to handle the connection for a URL for a download from that update site.

Proposed upgrade guidelines

N/A

Submitter checklist

Preview Give feedback

Before the changes are marked as ready-for-merge:

Maintainer checklist

Preview Give feedback

Different UpdateSites may need to connect to URLs differently, this adds a method to UpdateSite which creates the URLConnection that will be used for connecting. This allows an implementation of a password protected UpdateSite which can add the authorization information to the connection prior to returning it.
* @since TODO
*/
public URLConnection connect(URL src) throws IOException {
return ProxyConfiguration.open(src);
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem ideal ProxyConfiguration.open is deprecated:

public static URLConnection open(URL url) throws IOException {

You could potentially use this instead:

public static HttpRequest.Builder newHttpRequestBuilder(URI uri) {
HttpRequest.Builder httpRequestBuilder = HttpRequest.newBuilder(uri);
if (JenkinsJVM.isJenkinsJVM() && !UserAgentURLConnectionDecorator.DISABLED) {
httpRequestBuilder.setHeader("User-Agent", UserAgentURLConnectionDecorator.getUserAgent());
}
return httpRequestBuilder;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree its not ideal, but the UpdateCenter.connect method returns a URLConnection. Is there a way to get a URLConnection from an HttpRequest.Builder?

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.

2 participants