Skip to content

Instantly share code, notes, and snippets.

@DavidEdwards
Created July 21, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidEdwards/70ef78102a5b98d15d221a928c70f8fc to your computer and use it in GitHub Desktop.
Save DavidEdwards/70ef78102a5b98d15d221a928c70f8fc to your computer and use it in GitHub Desktop.
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