You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ri...@apache.org on 2007/12/13 21:28:38 UTC
svn commit: r604018 - in
/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec:
HttpDecoder.java HttpMessage.java HttpRequestEncoder.java
Author: rickmcguire
Date: Thu Dec 13 12:28:36 2007
New Revision: 604018
URL: http://svn.apache.org/viewvc?rev=604018&view=rev
Log:
GERONIMO-3638 should allow URL encoding with custom encoding charset other than the default
Patch contributed by Sangjin Lee.
Modified:
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java
geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java?rev=604018&r1=604017&r2=604018&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpDecoder.java Thu Dec 13 12:28:36 2007
@@ -83,7 +83,7 @@
/** The decoder. */
- private CharsetDecoder decoder = Charset.defaultCharset().newDecoder();
+ private CharsetDecoder decoder = Charset.forName(HttpMessage.HTTP_ELEMENT_CHARSET).newDecoder();
/**
* Finds a line from a ByteBuffer that ends with a CR/LF and returns the line as a String.
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java?rev=604018&r1=604017&r2=604018&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java Thu Dec 13 12:28:36 2007
@@ -32,8 +32,11 @@
*/
public class HttpMessage {
- /** The Constant DEFAULT_CHARSET. */
- public static final String DEFAULT_CHARSET = "ISO-8859-1";
+ /** The Constant HTTP_ELEMENT_CHARSET used for encoding the HTTP elements. */
+ public static final String HTTP_ELEMENT_CHARSET = "US-ASCII";
+
+ /** The Constant DEFAULT_URL_ENCODING_CHARSET use for URL encoding. */
+ public static final String DEFAULT_URL_ENCODING_CHARSET = "UTF-8";
/** The Constant CONTENT_TYPE. */
public static final String CONTENT_TYPE = "Content-Type";
@@ -56,8 +59,8 @@
/** The content container. */
protected ByteArrayOutputStream content;
- /** The character charset **/
- protected String charset = DEFAULT_CHARSET;
+ /** The character charset for URL encoding **/
+ protected String urlEncodingCharset = DEFAULT_URL_ENCODING_CHARSET;
/**
* Gets the <code>String</code> content. This method should only be
@@ -284,5 +287,27 @@
public void setContentLength(int contentLength) {
this.contentLength = contentLength;
}
+
+ /**
+ * Gets the charset that is used to do URL encoding/decoding. It is
+ * "UTF-8" by default.
+ *
+ * @return the charset name
+ */
+ public String getUrlEncodingCharset() {
+ return urlEncodingCharset;
+ }
+ /**
+ * Sets the charset that is used to do URL encoding/decoding. In reality,
+ * the only recommended values are "UTF-8", and normally it is neither
+ * necessary nor recommended to use something other than the default. <b>Do
+ * not reset this value</b> unless there is a very clear interoperability
+ * reason to do so.
+ *
+ * @param charset the charset name
+ */
+ public void setUrlEncodingCharset(String charset) {
+ this.urlEncodingCharset = charset;
+ }
}
Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java?rev=604018&r1=604017&r2=604018&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java Thu Dec 13 12:28:36 2007
@@ -28,10 +28,10 @@
import java.util.Map;
import java.util.Set;
+import org.apache.ahc.auth.AuthScope;
+import org.apache.ahc.auth.AuthState;
import org.apache.ahc.util.EncodingUtil;
import org.apache.ahc.util.NameValuePair;
-import org.apache.ahc.auth.AuthState;
-import org.apache.ahc.auth.AuthScope;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
@@ -44,7 +44,7 @@
public class HttpRequestEncoder extends ProtocolEncoderAdapter {
/** The Constant TYPES. */
- private static final Set TYPES;
+ private static final Set<Class<?>> TYPES;
/** The Constant CRLF. */
private static final byte[] CRLF = new byte[] {0x0D, 0x0A};
@@ -53,7 +53,7 @@
private static final String POST_CONTENT_TYPE = "application/x-www-form-urlencoded";
static {
- Set types = new HashSet();
+ Set<Class<?>> types = new HashSet<Class<?>>();
types.add(HttpRequestMessage.class);
TYPES = Collections.unmodifiableSet(types);
}
@@ -100,10 +100,10 @@
for (Map.Entry<String, String> entry : set) {
attrs[i++] = new NameValuePair(entry.getKey(), entry.getValue());
}
- urlAttrs = EncodingUtil.formUrlEncode(attrs, Charset.defaultCharset().toString());
+ urlAttrs = EncodingUtil.formUrlEncode(attrs, msg.getUrlEncodingCharset());
}
- CharsetEncoder encoder = Charset.defaultCharset().newEncoder();
+ CharsetEncoder encoder = Charset.forName(HttpMessage.HTTP_ELEMENT_CHARSET).newEncoder();
buf.putString(msg.getRequestMethod(), encoder);
buf.putString(" ", encoder);
buf.putString(msg.getPath(), encoder);