An in-app HTTP inspector for Android OkHttp clients
Java
Clone or download
Pull request Compare This branch is 27 commits ahead, 3 commits behind jgilfelt:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
assets
gradle
okhttp-no-op
okhttp
okhttp3-no-op
okhttp3
sample
sample3
.gitignore
CHANGELOG.md
LICENSE.txt
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
ic_launcher-web.png
settings.gradle

README.md

Chuck

本项目对chuck进行修改,支?okhttp2.+,添加了chuck桌面打开方式

Chuck is a simple in-app HTTP inspector for Android OkHttp clients. Chuck intercepts and persists all HTTP requests and responses inside your application, and provides a UI for inspecting their content.

Chuck

Apps using Chuck will display a notification showing a summary of ongoing HTTP activity. Tapping on the notification launches the full Chuck UI. Apps can optionally suppress the notification, and launch the Chuck UI directly from within their own interface. HTTP interactions and their contents can be exported via a share intent.

The main Chuck activity is launched in its own task, allowing it to be displayed alongside the host app UI using Android 7.x multi-window support.

Multi-Window

Chuck requires Android 4.0+ and OkHttp 2.x.

Warning: The data generated and stored when using this interceptor may contain sensitive information such as Authorization or Cookie headers, and the contents of request and response bodies. It is intended for use during development, and not in release builds or other production deployments.

Setup

Add the dependency in your build.gradle file. Add it alongside the no-op variant to isolate Chuck from release builds as follows:

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

 allprojects {
 		repositories {
 			...
 			maven { url 'https://jitpack.io' }
 		}
 	}

Step 2. Add the dependency

okhttp2.+

 dependencies {
   debugCompile 'com.github.sixgodIT.chuck:okhttp:2.3.0'
   releaseCompile 'com.github.sixgodIT.chuck:okhttp-no-op:2.3.0'
 }

okhttp3.+

 dependencies {
   debugCompile 'com.github.sixgodIT.chuck:okhttp3:2.3.0'
   releaseCompile 'com.github.sixgodIT.chuck:okhttp3-no-op:2.3.0'
 }

In your application code, create an instance of ChuckInterceptor (you'll need to provide it with a Context, because Android) and add it as an interceptor when building your OkHttp client:

okhttp2.+

OkHttpClient client = new OkHttpClient();
//使用interceptors不?拦??cookie
//client.interceptors().add((new ChuckInterceptor(context, BuildConfig.APPLICATION_ID));
//networkInterceptors可以拦??cookie。
client.networkInterceptors().add((new ChuckInterceptor(context, BuildConfig.APPLICATION_ID));

okhttp3.+

 OkHttpClient
       .Builder()
       .addNetworkInterceptor(new ChuckInterceptor(context, BuildConfig.APPLICATION_ID))

That's it! Chuck will now record all HTTP interactions made by your OkHttp client. You can optionally disable the notification by calling showNotification(false) on the interceptor instance, and launch the Chuck UI directly within your app with the intent from Chuck.getLaunchIntent().

FAQ

  • Why are some of my request headers missing?
  • Why are retries and redirects not being captured discretely?
  • Why are my encoded request/response bodies not appearing as plain text?

Please refer to this section of the OkHttp wiki. You can choose to use Chuck as either an application or network interceptor, depending on your requirements.

Acknowledgements

Chuck uses the following open source libraries:

  • OkHttp - Copyright Square, Inc.
  • Gson - Copyright Google Inc.
  • Cupboard - Copyright Little Robots.

License

Copyright (C) 2017 Jeff Gilfelt.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.