Skip to content

Introduce ResponseConnector as a superset of HttpConnector - #1287

Closed
nedtwigg wants to merge 11 commits into
hub4j:mainfrom
nedtwigg:remove-http-connector
Closed

nedtwigg wants to merge 11 commits into
hub4j:mainfrom
nedtwigg:remove-http-connector

Conversation

@nedtwigg

@nedtwigg nedtwigg commented Nov 4, 2021

Copy link
Copy Markdown

This PR touches a lot of files, but it's pretty straightforward. The commits tell the story as simply as I can tell it, every commit in the chain passes mvn test. It resolves #1085 in a backward-compatible way (along with #1262 and #754).

It introduces a new interface ResponseConnector, with just a single method which functions as a delegate to the getResponseInfo method of GitHubClient which allows GitHubClient to be become final.

@Nonnull
protected ResponseInfo getResponseInfo(GitHubRequest request) throws IOException {
return connector.getResponseInfo(request, authorizationProvider);
}

GitHubHttpUrlConnectionClient now implements ResponseConnector rather than GitHubClient. This means that all of the old HttpConnector stuff can keep working transparently:

public HttpConnector getConnector() {
if (connector instanceof GitHubHttpUrlConnectionClient) {
return ((GitHubHttpUrlConnectionClient) connector).httpConnector;
} else {
return null;
}
}

In order to make it possible to implement ResponseConnector, I had to extract ResponseInfo into its own class and make it and some of its members public. Most of the commits in this PR are pure refactors (refactor commits aren't mixed in with new or changed functionality) so you can see exactly which parts had to become public.

The whole point of the PR is to bypass HttpConnector and users can now swap the new OkHttpResponseConnector instead of (OkHttpConnector + GitHubHttpUrlConnectionClient).

I believe the only breaking change in this PR is to [Abuse/Rate]LimitHandler, but it's a transparent change to all users who are using the built-in policies, and an easy change for users who aren't. The new names in the PR aren't great (e.g. ResponseInfo, ResponseConnector) but I just kept all names to match their name from where they were refactored from. I didn't mark any of the older stuff as deprecated.

One path forward might be to:

  1. Merge and release this PR (with whatever feedback you'd like)
  2. Let it rack up some mileage with users
  3. Deprecate HttpConnector and all its usages
  4. Remove the deprecations in a breaking change, and possibly rename classes at that point as well

@bitwiseman

Copy link
Copy Markdown
Member

Okay, this is embarrassing, but I'm working on basically the same change. I haven't looked at your change in any depth, but the description sounds much the same. I'll get you feedback shortly.

@codecov

codecov Bot commented Nov 8, 2021

Copy link
Copy Markdown

Codecov Report

Merging #1287 (42b4eda) into main (eef3c58) will decrease coverage by 0.19%.
The diff coverage is 79.83%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1287      +/-   ##
============================================
- Coverage     77.50%   77.30%   -0.20%     
- Complexity     1905     1920      +15     
============================================
  Files           189      191       +2     
  Lines          6000     6055      +55     
  Branches        328      336       +8     
============================================
+ Hits           4650     4681      +31     
- Misses         1150     1166      +16     
- Partials        200      208       +8     
Impacted Files Coverage Δ
src/main/java/org/kohsuke/github/GHObject.java 62.50% <ø> (ø)
...rc/main/java/org/kohsuke/github/GitHubRequest.java 89.78% <ø> (ø)
src/main/java/org/kohsuke/github/Requester.java 100.00% <ø> (ø)
...github/extras/okhttp3/OkHttpResponseConnector.java 58.82% <58.82%> (ø)
src/main/java/org/kohsuke/github/GitHubClient.java 87.86% <80.00%> (-1.51%) ⬇️
...ain/java/org/kohsuke/github/AbuseLimitHandler.java 69.23% <100.00%> (ø)
src/main/java/org/kohsuke/github/GHEventInfo.java 93.54% <100.00%> (ø)
src/main/java/org/kohsuke/github/GHRateLimit.java 88.05% <100.00%> (ø)
src/main/java/org/kohsuke/github/GitHub.java 80.54% <100.00%> (ø)
...rc/main/java/org/kohsuke/github/GitHubBuilder.java 91.86% <100.00%> (+0.09%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eef3c58...42b4eda. Read the comment docs.

@nedtwigg

nedtwigg commented Nov 8, 2021

Copy link
Copy Markdown
Author

Lol! Well feel free to dump this PR and just merge yours :) All I care about is that I can do something like OkHttpResponseConnector

@bitwiseman

Copy link
Copy Markdown
Member

@nedtwigg
So, yeah, we basically had the same idea.
I got around the coverage problem by running part of the regular test pass on okhttp.
Some naming differences of course.
I also made the change non-breaking for both API and default behavior.

Would you be willing to review #1290 ? It should look very familiar. 😄

@nedtwigg

nedtwigg commented Nov 8, 2021

Copy link
Copy Markdown
Author

Absolutely! Review incoming.

Comment on lines +404 to +406
protected ResponseInfo getResponseInfo(GitHubRequest request) throws IOException {
return connector.getResponseInfo(request, authorizationProvider);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I chose to treat the request as unmodifiable, whereas your GitHubClient has private GitHubRequest prepareRequest(GitHubRequest request) throws IOException {. In that method you add the auth headers, and also do some accept/encoding stuff that I don't understand very well. Probably my PR is just plain missing those features.

I think this way of handling authorization by passing the provider vs modifying the request is the only substantive difference between the two PRs, and I like your way better.

@nedtwigg

nedtwigg commented Nov 8, 2021

Copy link
Copy Markdown
Author

I like yours better :) Closing as dupe, looking forward to the next release with the new features.

@nedtwigg nedtwigg closed this Nov 8, 2021
@bitwiseman

bitwiseman commented Nov 8, 2021 •

Copy link
Copy Markdown
Member

I chose to treat the request as unmodifiable, whereas your GitHubClient has private GitHubRequest prepareRequest(GitHubRequest request) throws IOException {. In that method you add the auth headers, and also do some accept/encoding stuff that I don't understand very well. Probably my PR is just plain missing those features.

I think this way of handling authorization by passing the provider vs modifying the request is the only substantive difference between the two PRs, and I like your way better.

Requests are immutable, this creates a new request. I'll change the name of the method.

@nedtwigg

nedtwigg commented Nov 8, 2021

Copy link
Copy Markdown
Author

Fwiw I think your name prepare is good. I'll restate the case for passing AuthorizationProvider: GitHubRequest could be a type-level guarantee "this is what the client code requested" vs "this might be what the client code requested, or it might be a mutated copy with auth information and content-negotiation appended on". I was treating GitHubRequest as type-enforced pure-intent, but I think your approach is more practical.

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.

Deprecate all usages of HttpConnector and HttpURLConnection

2 participants