-
Notifications
You must be signed in to change notification settings - Fork 68
Restore missing OkHttp3 Additions in okhttp-android and okhttp-jvm #1434
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
Open
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/okhttp3-additions-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+423
−6
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f80e53e
Initial plan
Copilot 83b99eb
Restore OkHttp3 Additions for okhttp-android and okhttp-jvm
Copilot 86d04a3
Remove unused imports from restored Additions
Copilot 1af6b19
Increment okhttp, okhttp-android, okhttp-jvm nuget versions to 5.3.2.3
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
source/com.squareup.okhttp3/okhttp-android/Additions/Call.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using System; | ||
| using Android.Runtime; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Square.OkHttp3 | ||
| { | ||
| public static class CallExtensions | ||
| { | ||
| public static Task<Response> ExecuteAsync(this ICall call) | ||
| { | ||
| var tcs = new TaskCompletionSource<Response>(); | ||
|
|
||
| call.Enqueue( | ||
| (c, response) => | ||
| { | ||
| tcs.SetResult(response); | ||
| }, | ||
| (c, exception) => | ||
| { | ||
| if (call.IsCanceled) | ||
| { | ||
| tcs.SetCanceled(); | ||
| } | ||
| else | ||
| { | ||
| tcs.SetException(exception); | ||
| } | ||
| }); | ||
|
|
||
| return tcs.Task; | ||
| } | ||
|
|
||
| public static void Enqueue(this ICall call, Action<ICall, Response> onResponse, Action<ICall, Java.IO.IOException> onFailure) | ||
| { | ||
| call.Enqueue(new ActionCallback(onResponse, onFailure)); | ||
| } | ||
|
|
||
| private class ActionCallback : Java.Lang.Object, global::Square.OkHttp3.ICallback | ||
| { | ||
| private readonly Action<ICall, Response> onResponse; | ||
| private readonly Action<ICall, Java.IO.IOException> onFailure; | ||
|
|
||
| public ActionCallback(Action<ICall, Response> onResponse, Action<ICall, Java.IO.IOException> onFailure) | ||
| { | ||
| this.onResponse = onResponse; | ||
| this.onFailure = onFailure; | ||
| } | ||
|
|
||
| public void OnResponse(ICall call, Response response) | ||
| { | ||
| if (onResponse != null) | ||
| { | ||
| onResponse(call, response); | ||
| } | ||
| } | ||
|
|
||
| public void OnFailure(ICall call, Java.IO.IOException exception) | ||
| { | ||
| if (onFailure != null) | ||
| { | ||
| onFailure(call, exception); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
source/com.squareup.okhttp3/okhttp-android/Additions/Dispatcher.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| namespace Square.OkHttp3 | ||
| { | ||
| partial class Dispatcher | ||
| { | ||
| public void SetIdleCallback(Java.Lang.IRunnable idleCallback) => | ||
| IdleCallback = idleCallback; | ||
| } | ||
| } | ||
103 changes: 103 additions & 0 deletions
103
source/com.squareup.okhttp3/okhttp-android/Additions/OkHttpClient.Builder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using Java.Net; | ||
| using Javax.Net.Ssl; | ||
|
|
||
| namespace Square.OkHttp3 | ||
| { | ||
| partial class OkHttpClient | ||
| { | ||
| partial class Builder | ||
|
jonathanpeppers marked this conversation as resolved.
|
||
| { | ||
| public Builder AddInterceptor(Func<IInterceptorChain, Response> interceptor) | ||
| { | ||
| return AddInterceptor(new InterceptorImpl(interceptor)); | ||
| } | ||
|
|
||
| public Builder AddNetworkInterceptor(Func<IInterceptorChain, Response> interceptor) | ||
| { | ||
| return AddNetworkInterceptor(new InterceptorImpl(interceptor)); | ||
| } | ||
|
|
||
| public Builder Authenticator(Func<Route, Response, Request> authenticate) | ||
| { | ||
| return Authenticator(new AuthenticatorImpl(authenticate)); | ||
| } | ||
|
|
||
| public Builder ProxyAuthenticator(Func<Route, Response, Request> authenticate) | ||
| { | ||
| return ProxyAuthenticator(new AuthenticatorImpl(authenticate)); | ||
| } | ||
|
|
||
| public Builder Dns(Func<string, IList<InetAddress>> lookup) | ||
| { | ||
| return Dns(new DnsImpl(lookup)); | ||
| } | ||
|
|
||
| public Builder HostnameVerifier(Func<string, ISSLSession, bool> verify) | ||
| { | ||
| return HostnameVerifier(new HostnameVerifierImpl(verify)); | ||
| } | ||
|
|
||
| private class AuthenticatorImpl : Java.Lang.Object, IAuthenticator | ||
| { | ||
| private readonly Func<Route, Response, Request> authenticate; | ||
|
|
||
| public AuthenticatorImpl(Func<Route, Response, Request> authenticate) | ||
| { | ||
| this.authenticate = authenticate; | ||
| } | ||
|
|
||
| public Request Authenticate(Route p0, Response p1) | ||
| { | ||
| return authenticate(p0, p1); | ||
| } | ||
|
jonathanpeppers marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private class InterceptorImpl : Java.Lang.Object, IInterceptor | ||
| { | ||
| private readonly Func<IInterceptorChain, Response> interceptor; | ||
|
|
||
| public InterceptorImpl(Func<IInterceptorChain, Response> interceptor) | ||
| { | ||
| this.interceptor = interceptor; | ||
| } | ||
|
|
||
| public Response Intercept(IInterceptorChain p0) | ||
| { | ||
| return interceptor(p0); | ||
| } | ||
| } | ||
|
|
||
| private class DnsImpl : Java.Lang.Object, IDns | ||
| { | ||
| private readonly Func<string, IList<InetAddress>> lookup; | ||
|
|
||
| public DnsImpl(Func<string, IList<InetAddress>> lookup) | ||
| { | ||
| this.lookup = lookup; | ||
| } | ||
|
|
||
| public IList<InetAddress> Lookup(string p0) | ||
| { | ||
| return lookup(p0); | ||
| } | ||
| } | ||
|
|
||
| private class HostnameVerifierImpl : Java.Lang.Object, IHostnameVerifier | ||
| { | ||
| private readonly Func<string, ISSLSession, bool> verify; | ||
|
|
||
| public HostnameVerifierImpl(Func<string, ISSLSession, bool> verify) | ||
| { | ||
| this.verify = verify; | ||
| } | ||
|
|
||
| public bool Verify(string hostname, ISSLSession session) | ||
| { | ||
| return verify(hostname, session); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
source/com.squareup.okhttp3/okhttp-android/Additions/ResponseBody.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Android.Runtime; | ||
|
|
||
| namespace Square.OkHttp3 | ||
| { | ||
| partial class ResponseBody | ||
|
jonathanpeppers marked this conversation as resolved.
|
||
| { | ||
| public Task<byte[]> BytesAsync() | ||
| { | ||
| return Task.Run(() => Bytes()); | ||
| } | ||
|
|
||
| public Task<string> StringAsync() | ||
| { | ||
| return Task.Run(() => String()); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using System; | ||
| using Android.Runtime; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Square.OkHttp3 | ||
| { | ||
| public static class CallExtensions | ||
| { | ||
| public static Task<Response> ExecuteAsync(this ICall call) | ||
| { | ||
| var tcs = new TaskCompletionSource<Response>(); | ||
|
|
||
| call.Enqueue( | ||
| (c, response) => | ||
| { | ||
| tcs.SetResult(response); | ||
| }, | ||
| (c, exception) => | ||
| { | ||
| if (call.IsCanceled) | ||
| { | ||
| tcs.SetCanceled(); | ||
| } | ||
| else | ||
| { | ||
| tcs.SetException(exception); | ||
| } | ||
| }); | ||
|
|
||
| return tcs.Task; | ||
| } | ||
|
|
||
| public static void Enqueue(this ICall call, Action<ICall, Response> onResponse, Action<ICall, Java.IO.IOException> onFailure) | ||
| { | ||
| call.Enqueue(new ActionCallback(onResponse, onFailure)); | ||
| } | ||
|
|
||
| private class ActionCallback : Java.Lang.Object, global::Square.OkHttp3.ICallback | ||
| { | ||
| private readonly Action<ICall, Response> onResponse; | ||
| private readonly Action<ICall, Java.IO.IOException> onFailure; | ||
|
|
||
| public ActionCallback(Action<ICall, Response> onResponse, Action<ICall, Java.IO.IOException> onFailure) | ||
| { | ||
| this.onResponse = onResponse; | ||
| this.onFailure = onFailure; | ||
| } | ||
|
|
||
| public void OnResponse(ICall call, Response response) | ||
| { | ||
| if (onResponse != null) | ||
| { | ||
| onResponse(call, response); | ||
| } | ||
| } | ||
|
|
||
| public void OnFailure(ICall call, Java.IO.IOException exception) | ||
| { | ||
| if (onFailure != null) | ||
| { | ||
| onFailure(call, exception); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
source/com.squareup.okhttp3/okhttp-jvm/Additions/Dispatcher.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| namespace Square.OkHttp3 | ||
| { | ||
| partial class Dispatcher | ||
|
jonathanpeppers marked this conversation as resolved.
|
||
| { | ||
| public void SetIdleCallback(Java.Lang.IRunnable idleCallback) => | ||
| IdleCallback = idleCallback; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.