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 OkHttp for network calls #431

Merged
merged 5 commits into from
Oct 16, 2024
Merged

Conversation

rajdeepnanua-okta
Copy link
Contributor

No description provided.

@rajdeepnanua-okta rajdeepnanua-okta force-pushed the use_okhttp_networking branch 2 times, most recently from 3adae66 to 172f537 Compare October 16, 2024 20:15
@rajdeepnanua-okta rajdeepnanua-okta force-pushed the use_okhttp_networking branch 5 times, most recently from 42e8450 to c41f294 Compare October 16, 2024 21:09
@@ -1,5 +1,4 @@
{
"private": true,
Copy link
Contributor Author

@rajdeepnanua-okta rajdeepnanua-okta Oct 16, 2024

Choose a reason for hiding this comment

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

This isn't a private package, and CI publish script throws an error with the new yarn if this is still set to true. To match the previous behavior where CI does publish this package to our internal artifactory, I had to remove this.

Comment on lines +39 to +41
- run: brew install git-lfs
- run: git lfs install
- run: git lfs pull
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Despite my efforts here, CircleCI is still broken. I will address this in a separate commit.

@@ -12,166 +12,161 @@

package com.oktareactnative;

import android.annotation.SuppressLint;
import static com.okta.oidc.net.ConnectionParameters.USER_AGENT;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new implementation is mostly taken from here: https://github.com/okta/okta-oidc-android/blob/ce298473dc2b1e2eaced212c98f3d3acee636f5c/app/src/main/java/com/okta/oidc/example/OkHttp.java
There are a few changes to the reference implementation, namely customizable timeouts, and user-agent response headers as required by this SDK

Comment on lines +61 to 66
if (sOkHttpClient == null) {
sOkHttpClient = new OkHttpClient.Builder()
.connectTimeout(connectTimeoutMs, TimeUnit.MILLISECONDS)
.readTimeout(readTimeoutMs, TimeUnit.MILLISECONDS)
.build();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's perfectly okay if this code gets called by multiple callers at the same time. okHttpClient doesn't need to be singleton for correctness, but only for performance reasons.

}

@Override
public InputStream connect(@NonNull Uri uri, @NonNull ConnectionParameters params)
throws Exception {
Request request = buildRequest(uri, params);
mCall = sOkHttpClient.newCall(request);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

mCall is a class level variable here. It's only useful to keep track of it in case of cancellation. We can only track and cancel one call at a time with this implementation, but this was also a limitation with the previous implementation.
This SDK also doesn't make use of the cancel function

@rajdeepnanua-okta rajdeepnanua-okta merged commit c593218 into master Oct 16, 2024
5 checks passed
@rajdeepnanua-okta rajdeepnanua-okta deleted the use_okhttp_networking branch October 16, 2024 22:01
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.

3 participants