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

Add basic URLFilter for HttpURLConnection #2275

Merged
merged 1 commit into from
Jan 27, 2016

Conversation

chadbrubaker
Copy link
Contributor

This optional filter can be used to allow for blocking HTTP traffic to
certain URLs, for example in order to prevent accessing sensitive
content over HTTP instead of HTTPS.

This behavior is already possible for clients of OkHttpClient, this patch allows legacy clients using the HttpUrlConnection APIs to do basic blocking.

See #2269

@swankjesse
Copy link
Member

Sorry, this use case is too obscure to warrant extra API. If you really need this behavior, write your own URLStreamHandler that delegates to OkHttp’s UrlStreamHandler.

@swankjesse swankjesse closed this Jan 23, 2016
@@ -148,6 +149,30 @@ public void setInstanceFollowRedirectsFalse() throws Exception {
assertResponseCode(connection, 302);
}

@Test
public void testURLFilter() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

Wanna test redirect from HTTPS to HTTP ? I think we have some tests like that lying around somewhere!

@swankjesse swankjesse reopened this Jan 25, 2016
@swankjesse
Copy link
Member

Is there a way we can make this UrlFilter interface non-public and expose this behavior only to AOSP?

@chadbrubaker
Copy link
Contributor Author

We can make it package private to keep it AOSP only.

@chadbrubaker
Copy link
Contributor Author

I made the OkUrlFactory.setUrlFilter method package private, that works fine for AOSP but will keep it from being publicly usable. The interface is still public since it is referenced by HttpURLConnectionImpl but I could move it into okhttp3.internal as well.

@swankjesse
Copy link
Member

Awesome, yes please do.

@chadbrubaker
Copy link
Contributor Author

Done

This optional filter can be used to allow for blocking HTTP traffic to
certain URLs, for example in order to prevent accessing sensitive
content over HTTP instead of HTTPS.
@chadbrubaker
Copy link
Contributor Author

Fixed an unused import that I missed when moving the interface to internal.

swankjesse added a commit that referenced this pull request Jan 27, 2016
Add basic URLFilter for HttpURLConnection
@swankjesse swankjesse merged commit 8cefc27 into square:master Jan 27, 2016
@swankjesse
Copy link
Member

Neat! Thanks for jumping through all the hoops for me!

@chadbrubaker
Copy link
Contributor Author

Thanks! Sorry for not being clearer on the usage from the start.

On Tue, Jan 26, 2016, 18:10 Jesse Wilson notifications@github.com wrote:

Neat! Thanks for jumping through all the hoops for me!


Reply to this email directly or view it on GitHub
#2275 (comment).

amartinz pushed a commit to NamelessRom/android_external_okhttp that referenced this pull request Jun 30, 2016
This was previously commit to AOSP as 27c8053
The upstream commit was contained in OkHttp 3.0 but not 2.7.5.

Previous commit message:

This optional filter can be used to allow for blocking HTTP traffic to
certain URLs, for example in order to prevent accessing sensitive
content over HTTP instead of HTTPS.

square/okhttp#2275

(cherry-picked from upstream commit 2b1f9a20bac5d99acf5a8be36754e5a1dadaf448)

Change-Id: Icb6057e9d32752c948d92c3973a4d67fd48cb43d
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.

None yet

2 participants