Skip to content

Commit 81e501e

Browse files
committed
fix header bug and add gzip support
1 parent 7429cce commit 81e501e

File tree

15 files changed

+118
-106
lines changed

15 files changed

+118
-106
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ Tested in Android 5.1, 6.0.
1414
<dependency>
1515
<groupId>com.panxw.volley</groupId>
1616
<artifactId>library</artifactId>
17-
<version>1.0.1</version>
17+
<version>1.0.2</version>
1818
</dependency>
1919

2020
#####for Gradle
2121
dependencies {
22-
compile 'com.panxw.volley:library:1.0.1'
22+
compile 'com.panxw.volley:library:1.0.2'
2323
}
2424

2525
#####latest jars for download
26-
[com.panxw.volley-1.0.1-classes.jar](https://github.com/panxw/android-volley-manager/blob/master/release/com.panxw.volley-1.0.1-classes.jar?raw=true)
26+
[com.panxw.volley-1.0.2-classes.jar](https://github.com/panxw/android-volley-manager/blob/master/release/com.panxw.volley-1.0.2-classes.jar?raw=true)
2727

2828
##Sample
2929
#####init RequestManager in your Application
@@ -42,67 +42,78 @@ Tested in Android 5.1, 6.0.
4242

4343
#####use RequestManager to load data
4444
public class MainActivity extends Activity implements RequestListener {
45-
private static final String OUT_FILE = "upload.txt";
46-
private static final String OUT_DATA = "sadf464764sdf3ds1f3adsf78921355u2390q3rtheslafkhsdafhreasof";
47-
private static final String POST_URL = "http://allthelucky.ap01.aws.af.cm/memoServer";
45+
46+
private static final String TAG = "VolleyTest";
47+
48+
private static final String GET_URL = "http://www.panxw.com/about.html";
49+
50+
private static final String POST_URL = "http://www.panxw.com/index.php";
51+
4852
private static final String POST_JSON = "{\"action\":\"test\", \"info\":\"hello world\"}";
49-
private static final String GET_URL = "https://raw.githubusercontent.com/panxw/android-volley-manager/master/test.txt";
53+
54+
private static final String OUT_FILE = "upload.txt";
55+
56+
private static final String OUT_DATA = "df464764sdf3ds1f3adsf789213557r12-34912-482130487321";
57+
5058
private static final String UPLOAD_URL = "http://www.splashpadmobile.com/upload.php";
59+
5160
private LoadController mLoadController = null;
52-
61+
5362
@Override
5463
protected void onCreate(Bundle savedInstanceState) {
5564
super.onCreate(savedInstanceState);
5665
setContentView(R.layout.activity_main);
57-
58-
this.testPost();
66+
5967
this.testGet();
68+
this.testPost();
6069
this.testFileUpload();
6170
}
62-
63-
private void testPost() {//test post
64-
mLoadController = RequestManager.getInstance().post(POST_URL, POST_JSON, this, 0);
65-
}
66-
67-
private void testGet() {//test GET
71+
72+
private void testGet() {
6873
mLoadController = RequestManager.getInstance().get(GET_URL, this, 1);
6974
}
70-
71-
private void testFileUpload() {//test POST(with file) in RequestMap
75+
76+
private void testPost() {
77+
mLoadController = RequestManager.getInstance().post(POST_URL, POST_JSON,
78+
this, 0);
79+
}
80+
81+
private void testFileUpload() {
7282
MainActivity.prepareFile(this);
73-
83+
7484
RequestMap params = new RequestMap();
7585
File uploadFile = new File(this.getFilesDir(), OUT_FILE);
7686
params.put("uploadedfile", uploadFile);
7787
params.put("share", "1");
78-
79-
mLoadController = RequestManager.getInstance().post(UPLOAD_URL, params, this, 2);
88+
89+
mLoadController = RequestManager.getInstance().post(UPLOAD_URL, params,
90+
this, 2);
8091
}
81-
92+
8293
@Override
8394
public void onSuccess(String response, Map<String, String> headers,
8495
String url, int actionId) {
85-
System.out.println("actionId:" + actionId + ", OnSucess!\n" + response);
96+
Log.d(TAG, "actionId:" + actionId + ", OnSucess!\n" + response);
8697
}
87-
98+
8899
@Override
89100
public void onError(String errorMsg, String url, int actionId) {
90-
System.out.println("actionId:" + actionId + ", onError!\n" + errorMsg);
101+
Log.d(TAG, "actionId:" + actionId + ", onError!\n" + errorMsg);
91102
}
92-
103+
93104
@Override
94105
public void onRequest() {
95-
System.out.println("request send...");
106+
Log.d(TAG, "request send...");
96107
}
97-
108+
98109
@Override
99110
public void onBackPressed() {
100111
super.onBackPressed();
101112
if (mLoadController != null) {
102113
mLoadController.cancel();
103114
}
104115
}
105-
116+
106117
private static void prepareFile(Context context) {
107118
FileOutputStream fos = null;
108119
try {
@@ -124,6 +135,7 @@ Tested in Android 5.1, 6.0.
124135
}
125136
}
126137
}
138+
127139
}
128140

129141
####Author

android-volley-manager.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</configuration>
99
</facet>
1010
</component>
11-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
1212
<exclude-output />
1313
<content url="file://$MODULE_DIR$">
1414
<excludeFolder url="file://$MODULE_DIR$/.gradle" />

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ developerName = pan
4040
developerEmail = winfirm@163.com
4141

4242
# bintray.gradle use
43-
libraryVersion = 1.0.1
43+
libraryVersion = 1.0.2
4444

4545
licenseLabel = ["Apache-2.0"]
4646

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ apply plugin: 'com.jfrog.bintray'
44

55
version = libraryVersion
66
android {
7-
compileSdkVersion 20
8-
buildToolsVersion '20.0.0'
7+
compileSdkVersion 22
8+
buildToolsVersion '22.0.1'
99
resourcePrefix 'android_lib_'
1010
defaultConfig {
1111
minSdkVersion 9

library/library.iml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.panxw.volley" external.system.module.version="1.0.0" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.panxw.volley" external.system.module.version="1.0.1" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -27,7 +27,7 @@
2727
</configuration>
2828
</facet>
2929
</component>
30-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
30+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
3131
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
3232
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
3333
<exclude-output />
@@ -65,34 +65,19 @@
6565
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
6767
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
68-
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
6968
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
7069
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
7170
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
72-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
7371
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
74-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
75-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
7672
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
77-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
78-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
79-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
8073
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
81-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
82-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
83-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
84-
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
8574
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
8675
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8776
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
88-
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
8977
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
90-
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
91-
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
92-
<excludeFolder url="file://$MODULE_DIR$/build/test-results" />
9378
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
9479
</content>
95-
<orderEntry type="jdk" jdkName="Android API 20 Platform" jdkType="Android SDK" />
80+
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
9681
<orderEntry type="sourceFolder" forTests="false" />
9782
</component>
9883
</module>

library/src/main/java/com/android/volley/Request.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.UnsupportedEncodingException;
2929
import java.net.URLEncoder;
3030
import java.util.Collections;
31+
import java.util.HashMap;
3132
import java.util.Map;
3233

3334
/**
@@ -115,6 +116,11 @@ public interface Method {
115116
/** An opaque token tagging this request; used for bulk cancellation. */
116117
private Object mTag;
117118

119+
/**
120+
* map for request headers
121+
*/
122+
private Map<String, String> mHeaders = new HashMap<String, String>();
123+
118124
/**
119125
* Creates a new request with the given URL and error listener. Note that
120126
* the normal response listener is not provided here as delivery of responses
@@ -360,8 +366,8 @@ public boolean isCanceled() {
360366
* provide these values.
361367
* @throws AuthFailureError In the event of auth failure
362368
*/
363-
public Map<String, String> getHeaders() throws AuthFailureError {
364-
return Collections.emptyMap();
369+
public Map<String, String> getHeaders() throws AuthFailureError{
370+
return mHeaders;
365371
}
366372

367373
/**

library/src/main/java/com/android/volley/http/HttpResponse.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import java.util.zip.GZIPInputStream;
88

99
public class HttpResponse {
10+
public static final int SC_CONTINUE=100;
11+
public static final int SC_OK = 200;
12+
public static final int SC_NO_CONTENT=204;
1013
public static final int SC_MOVED_PERMANENTLY = 301;
1114
public static final int SC_MOVED_TEMPORARILY = 302;
1215
public static final int SC_NOT_MODIFIED = 304;
1316
public static final int SC_FORBIDDEN = 403;
1417
public static final int SC_UNAUTHORIZED = 401;
15-
public static final int SC_OK = 200;
1618

1719
private int responseCode;
1820
private String responseMessage;
@@ -56,18 +58,14 @@ public void setResponseMessage(String responseMessage) {
5658
this.responseMessage = responseMessage;
5759
}
5860

59-
public void checkGzip() throws IOException{
61+
public boolean isGzipEnable(){
6062
if(httpHeaders != null) {
6163
String acceptEncoding = httpHeaders.get("Content-Encoding");
6264
if(acceptEncoding != null && acceptEncoding.contains("gzip")) {
63-
if(entityFromConnection != null) {
64-
InputStream is = entityFromConnection.getContent();
65-
if(is != null) {
66-
entityFromConnection.setContent(new GZIPInputStream(is));
67-
}
68-
}
65+
return true;
6966
}
7067
}
68+
return false;
7169
}
7270

7371
}

library/src/main/java/com/android/volley/manager/ByteArrayRequest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ protected Map<String, String> getParams() throws AuthFailureError {
5151
return null;//process as json, xml or MultipartRequestParams
5252
}
5353

54-
@Override
55-
public Map<String, String> getHeaders() throws AuthFailureError {
56-
Map<String, String> headers = super.getHeaders();
57-
if (null == headers || headers.equals(Collections.emptyMap())) {
58-
headers = new HashMap<String, String>();
59-
}
60-
return headers;
61-
}
62-
6354
@Override
6455
public String getBodyContentType() {
6556
if (httpEntity != null) {

library/src/main/java/com/android/volley/manager/RequestManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ public LoadController sendRequest(int method, final String url, Object data,
199199
if(requestHeaders.get(ACCEPT_ENCODING) == null) {
200200
requestHeaders.put(ACCEPT_ENCODING, GZIP);
201201
}
202-
203202
try {
204203
request.getHeaders().putAll(requestHeaders);
205204
} catch (AuthFailureError e) {
206205
e.printStackTrace();
207206
}
208207

208+
//set request retry policy
209209
RetryPolicy retryPolicy = new DefaultRetryPolicy(timeoutCount,
210210
retryTimes, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
211211
request.setRetryPolicy(retryPolicy);

0 commit comments

Comments
 (0)