Created
July 21, 2016 15:52
-
-
Save DavidEdwards/70ef78102a5b98d15d221a928c70f8fc to your computer and use it in GitHub Desktop.
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
import android.text.TextUtils; | |
import java.io.IOException; | |
import okhttp3.Interceptor; | |
import okhttp3.Response; | |
public class ForceHttpsInterceptor implements Interceptor { | |
@Override | |
public Response intercept(Interceptor.Chain chain) throws IOException { | |
Response originalResponse = chain.proceed(chain.request()); | |
String location = originalResponse.header("location"); | |
if(!TextUtils.isEmpty(location)) { | |
return originalResponse.newBuilder() | |
.header("location", location.replace("http://", "https://")) | |
.build(); | |
} else { | |
return originalResponse; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment