-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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 auth interceptor recipe #4336
Conversation
@@ -0,0 +1,58 @@ | |||
package okhttp3.recipes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add copyright
|
||
import java.io.IOException; | ||
|
||
public class BasicAuth { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sicne this is so close to Authenticate sample, I suggest documenting the difference here (peremptive etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to PreemptiveAuth ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
|
||
import java.io.IOException; | ||
|
||
public class BasicAuth { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to PreemptiveAuth ?
public BasicAuth() { | ||
client = new OkHttpClient.Builder() | ||
.addInterceptor( | ||
new BasicAuthInterceptor("publicobject.com", "jesse", "password1")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(2-space indent)
} | ||
} | ||
|
||
class BasicAuthInterceptor implements Interceptor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a nested class? Multiple top-level classes in a single file have problems with certain Java tools.
Renamed and added copyright |
import java.io.IOException; | ||
|
||
public class PreemptiveAuth { | ||
private final OkHttpClient client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind formatting with this?
https://github.com/square/java-code-styles/
We do 2-space indent everywhere.
} | ||
} | ||
|
||
class BasicAuthInterceptor implements Interceptor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind making this a nested class?
@@ -0,0 +1,73 @@ | |||
/* | |||
* Copyright (C) 2014 Square, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 2018
* commit '1f7e796e6e658df34a98276b2092a81de118937d': Cleanup HttpLoggingInterceptor (square#4346) Add a LoggingEventListener and use it in okcurl (square#4353) Preemptive auth for proxy CONNECT Relax handling of Cache-Control: immutable Add some docs for Cache class (square#4375) Fix connection leaks on failed web socket upgrades. Don't specify a crypto provider in HeldCertificate. Confirm that call timeouts don't apply to SSE or web sockets. Add APIs to configure the client's default call timeout. (square#4369) Recover from executor shutdowns gracefully. (square#4365) Make the nested BasicAuthInterceptor static (square#4368) Add basic auth interceptor recipe (square#4336) Whole operation timeouts Make scheme names case-sensitive again. Remove colon when scheme missing in builder toString (square#4361) CipherSuite init speedup (square#4340) Limit the use of regexes in the RFC 7235 challenge parser. Allow incomplete url builder toString usage (square#4357) APIs to set date headers Upgrade Conscrypt to 1.4.0 (was 1.3.0)
#4335