rwaldhoff 01/08/23 17:25:29 Modified: httpclient/src/java/org/apache/commons/httpclient/methods Tag: rlwrefactoring PostMethod.java httpclient/src/java/org/apache/commons/httpclient Tag: rlwrefactoring State.java URIUtil.java Log: add some additional pathSafe characters to URIUtil add queryStringValueSafe characters to URIUtil have PostMethod use URIUtil rather than URLEncoder remove legacy URI encoding methods from State Revision Changes Path No revision No revision 1.3.2.8 +8 -8 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java Index: PostMethod.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v retrieving revision 1.3.2.7 retrieving revision 1.3.2.8 diff -u -r1.3.2.7 -r1.3.2.8 --- PostMethod.java 2001/08/16 23:55:47 1.3.2.7 +++ PostMethod.java 2001/08/24 00:25:29 1.3.2.8 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v 1.3.2.7 2001/08/16 23:55:47 rwaldhoff Exp $ - * $Revision: 1.3.2.7 $ - * $Date: 2001/08/16 23:55:47 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v 1.3.2.8 2001/08/24 00:25:29 rwaldhoff Exp $ + * $Revision: 1.3.2.8 $ + * $Date: 2001/08/24 00:25:29 $ * ==================================================================== * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -14,11 +14,11 @@ import java.io.*; import java.util.*; -import java.net.URLEncoder; import org.apache.commons.httpclient.State; import org.apache.commons.httpclient.HttpConnection; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.URIUtil; import java.util.Iterator; import java.util.HashMap; import java.util.List; @@ -242,19 +242,19 @@ Iterator valit = list.iterator(); while(valit.hasNext()) { if(sb.length() > 0) { sb.append("&"); } - sb.append(URLEncoder.encode(name)); + sb.append(URIUtil.encode(name,URIUtil.queryStringValueSafe(),true)); Object val2 = valit.next(); if(null != val2) { sb.append("="); - sb.append(URLEncoder.encode(String.valueOf(val2))); + sb.append(URIUtil.encode(String.valueOf(val2),URIUtil.queryStringValueSafe(),true)); } } } else { if(sb.length() > 0) { sb.append("&"); } - sb.append(URLEncoder.encode(name)); + sb.append(URIUtil.encode(name,URIUtil.queryStringValueSafe())); if(null != value) { sb.append("="); - sb.append(URLEncoder.encode(String.valueOf(value))); + sb.append(URIUtil.encode(String.valueOf(value),URIUtil.queryStringValueSafe(),true)); } } } No revision No revision 1.3.2.4 +4 -72 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/State.java Index: State.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/State.java,v retrieving revision 1.3.2.3 retrieving revision 1.3.2.4 diff -u -r1.3.2.3 -r1.3.2.4 --- State.java 2001/08/20 17:21:19 1.3.2.3 +++ State.java 2001/08/24 00:25:29 1.3.2.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/State.java,v 1.3.2.3 2001/08/20 17:21:19 rwaldhoff Exp $ - * $Revision: 1.3.2.3 $ - * $Date: 2001/08/20 17:21:19 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/State.java,v 1.3.2.4 2001/08/24 00:25:29 rwaldhoff Exp $ + * $Revision: 1.3.2.4 $ + * $Date: 2001/08/24 00:25:29 $ * * ==================================================================== * @@ -73,10 +73,10 @@ * Session state. * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> + * @version $Revision: 1.3.2.4 $ */ public class State { - // ----------------------------------------------------- Instance Variables protected HashMap credMap = new HashMap(); @@ -86,28 +86,8 @@ */ protected Vector cookies = new Vector(); - - /** - * URL encoding switch. - */ - protected boolean encodeURLs = true; - - - /** - * URL encoding charset. - */ - protected String URLEncodingCharset = "UTF8"; - - - /** - * URL decoding charset. - */ - protected String URLDecodingCharset = "UTF8"; - - // ------------------------------------------------------------- Properties - /** * Add a cookie. * If the cookie has already expired, deletes the @@ -131,7 +111,6 @@ } - /** * Add a number of cookies * If the cookie has already expired, deletes the @@ -145,37 +124,12 @@ } } - // FIXME: this breaks encapsulation on the cookie vector public Vector getCookies() { return cookies; } - - /** - * Set the URL encoding flag. - */ - public void setEncodeURLs(boolean encodeURLs) { - this.encodeURLs = encodeURLs; - } - - - /** - * Set URL encoding charset. - */ - public void setURLEncodingCharset(String URLEncodingCharset) { - this.URLEncodingCharset = URLEncodingCharset; - } - - /** - * Set URL decoding charset. - */ - public void setURLDecodingCharset(String URLDecodingCharset) { - this.URLDecodingCharset = URLDecodingCharset; - } - - /** * Set the {@link Credentials} for the given authentication realm. */ public void setCredentials(String realm, Credentials credentials) { @@ -209,28 +163,6 @@ */ public Credentials getDefaultCredentials() { return this.getCredentials(null); - } - - // --------------------------------------------------------- Public Methods - - - /** - * URL encode. - */ - public String URLEncode(String url) { - if (encodeURLs) { - return URLUtil.URLEncode(url, URLEncodingCharset); - } else { - return url; - } - } - - - /** - * URL decode. - */ - public String URLDecode(String url) { - return URLUtil.URLDecode(url, URLDecodingCharset); } 1.1.2.2 +23 -5 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java Index: URIUtil.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- URIUtil.java 2001/08/23 21:45:33 1.1.2.1 +++ URIUtil.java 2001/08/24 00:25:29 1.1.2.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java,v 1.1.2.1 2001/08/23 21:45:33 rwaldhoff Exp $ - * $Revision: 1.1.2.1 $ - * $Date: 2001/08/23 21:45:33 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java,v 1.1.2.2 2001/08/24 00:25:29 rwaldhoff Exp $ + * $Revision: 1.1.2.2 $ + * $Date: 2001/08/24 00:25:29 $ * * ==================================================================== * @@ -83,7 +83,7 @@ * @author Remy Maucherat * @author Park, Sung-Gu * @author Rodney Waldhoff - * @version $Revision: 1.1.2.1 $ $Date: 2001/08/23 21:45:33 $ + * @version $Revision: 1.1.2.2 $ $Date: 2001/08/24 00:25:29 $ */ public class URIUtil { @@ -527,6 +527,10 @@ return pathSafe; } + public static final BitSet queryStringValueSafe() { + return queryStringValueSafe; + } + // ------------------------------------------------------ Private Constants /** @@ -646,12 +650,26 @@ unwise.set('`'); } + private static final BitSet pathReserved = new BitSet(256); + /** Static initializer for {@link #pathReserved}. */ + static { + pathReserved.set('/'); + pathReserved.set(';'); + pathReserved.set('='); + pathReserved.set('?'); + } + // ------------------------------ "Safe" Character Sets : Private Constants private static final BitSet pathSafe = new BitSet(256); static { pathSafe.or(unreserved); - pathSafe.set('/'); + pathSafe.or(pathReserved); + } + + private static final BitSet queryStringValueSafe = new BitSet(256); + static { + queryStringValueSafe.or(unreserved); } // -------------------------------------------------------- Private Methods