Skip to content

Commit

Permalink
Provided setter for encoding in RequestParams, closes android-async-h…
Browse files Browse the repository at this point in the history
  • Loading branch information
smarek committed Dec 24, 2013
1 parent 95258be commit cd1855f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions library/src/main/java/com/loopj/android/http/RequestParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package com.loopj.android.http;

import android.util.Log;

import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.utils.URLEncodedUtils;
Expand Down Expand Up @@ -88,12 +90,27 @@
*/
public class RequestParams {

protected final static String LOG_TAG = "RequestParams";
protected boolean isRepeatable;
protected boolean useJsonStreamer;
protected ConcurrentHashMap<String, String> urlParams;
protected ConcurrentHashMap<String, StreamWrapper> streamParams;
protected ConcurrentHashMap<String, FileWrapper> fileParams;
protected ConcurrentHashMap<String, Object> urlParamsWithObjects;
protected String contentEncoding = HTTP.UTF_8;

/**
* Sets content encoding for return value of {@link #getParamString()} and {@link
* #createFormEntity()} <p>&nbsp;</p> Default encoding is "UTF-8"
*
* @param encoding String constant from {@link org.apache.http.protocol.HTTP}
*/
public void setContentEncoding(final String encoding) {
if (encoding != null)
this.contentEncoding = encoding;
else
Log.d(LOG_TAG, "setContentEncoding called with null attribute");
}

/**
* Constructs a new empty {@code RequestParams} instance.
Expand Down Expand Up @@ -378,9 +395,10 @@ private HttpEntity createJsonStreamerEntity() throws IOException {

private HttpEntity createFormEntity() {
try {
return new UrlEncodedFormEntity(getParamsList(), HTTP.UTF_8);
return new UrlEncodedFormEntity(getParamsList(), contentEncoding);
} catch (UnsupportedEncodingException e) {
return null; // Actually cannot happen when using utf-8
Log.e(LOG_TAG, "createFormEntity failed", e);
return null; // Can happen, if the 'contentEncoding' won't be HTTP.UTF_8
}
}

Expand Down Expand Up @@ -472,7 +490,7 @@ private List<BasicNameValuePair> getParamsList(String key, Object value) {
}

protected String getParamString() {
return URLEncodedUtils.format(getParamsList(), HTTP.UTF_8);
return URLEncodedUtils.format(getParamsList(), contentEncoding);
}

public static class FileWrapper {
Expand Down

0 comments on commit cd1855f

Please sign in to comment.