Skip to content

Commit

Permalink
Adding changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsilva-cvl committed Jul 23, 2019
1 parent 008ef25 commit 89d4566
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.io.IOException;

import okhttp3.CacheControl;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

Expand All @@ -20,17 +17,15 @@ public class InterceptRequest implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {

// creates a client and a request to perform the Http call
OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build();
Request.Builder requestBuilder = new Request.Builder().url(NEW_URL).cacheControl(CacheControl.FORCE_NETWORK);
Request.Builder requestBuilder = chain.request().newBuilder();

// copies all the original headers into the new request
Headers headers = chain.request().headers();
for (String name : headers.names()) {
requestBuilder.addHeader(name, headers.get(name));
}
//adding a header to the original request
requestBuilder.addHeader("X-Been","Intercepted");

//changing the URL
requestBuilder.url(NEW_URL);

//returns a response
return okHttpClient.newCall(requestBuilder.build()).execute();
return chain.proceed(requestBuilder.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
public void onClick(View v) {
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(createOkhttpClient());
System.out.println("LOADING ");
webView.loadUrl("https://m.media-amazon.com/images/M/MV5BNGNhMDIzZTUtNTBlZi00MTRlLWFjM2ItYzViMjE3YzI5MjljXkEyXkFqcGdeQXVyNzkwMjQ5NzM@._V1_UY268_CR1,0,182,268_AL_.jpg");
}
});
Expand All @@ -83,6 +82,7 @@ public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
CacheControl.FORCE_NETWORK).build();
try {
Response response = okHttpClient.newCall(okHttpRequest).execute();
System.out.println(response.code());
WebResourceResponse webResource = new WebResourceResponse("", "", response.body().byteStream());
return webResource;
} catch (IOException e) {
Expand Down

0 comments on commit 89d4566

Please sign in to comment.