Skip to content

Instantly share code, notes, and snippets.

@amadeu01
Created October 20, 2017 12:31
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 amadeu01/0bc9bcceb3bd655187fd9188b8a7f7ae to your computer and use it in GitHub Desktop.
Save amadeu01/0bc9bcceb3bd655187fd9188b8a7f7ae to your computer and use it in GitHub Desktop.
import java.io.IOException;
import br.com.agileprocess.agileroutes.BuildConfig;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class UserAgentInterceptor implements Interceptor {
public UserAgentInterceptor() {}
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
Request.Builder builder = original.newBuilder()
.addHeader("User-Agent", System.getProperty("http.agent"))
.addHeader("Mobile-Version-Name", BuildConfig.VERSION_NAME)
.addHeader("Mobile-Version-Code", String.valueOf(BuildConfig.VERSION_CODE))
.method(original.method(), original.body());
Request request = builder.build();
return chain.proceed(request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment