You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2009/09/03 23:04:10 UTC
svn commit: r811121 - in /httpcomponents/httpcore/trunk/httpcore/src:
main/java/org/apache/http/entity/StringEntity.java
test/java/org/apache/http/entity/TestStringEntity.java
Author: olegk
Date: Thu Sep 3 21:04:10 2009
New Revision: 811121
URL: http://svn.apache.org/viewvc?rev=811121&view=rev
Log:
HTTPCORE-204: Add StringEntity constructor with MIME-type
Contributed by Gerald Turner <gturner at unzane.com>
Modified:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java?rev=811121&r1=811120&r2=811121&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/StringEntity.java Thu Sep 3 21:04:10 2009
@@ -45,17 +45,25 @@
protected final byte[] content;
- public StringEntity(final String s, String charset)
+ public StringEntity(final String s, String mimeType, String charset)
throws UnsupportedEncodingException {
super();
if (s == null) {
throw new IllegalArgumentException("Source string may not be null");
}
+ if (mimeType == null) {
+ mimeType = HTTP.PLAIN_TEXT_TYPE;
+ }
if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_CHARSET;
}
this.content = s.getBytes(charset);
- setContentType(HTTP.PLAIN_TEXT_TYPE + HTTP.CHARSET_PARAM + charset);
+ setContentType(mimeType + HTTP.CHARSET_PARAM + charset);
+ }
+
+ public StringEntity(final String s, String charset)
+ throws UnsupportedEncodingException {
+ this(s, null, charset);
}
public StringEntity(final String s)
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java?rev=811121&r1=811120&r2=811121&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java Thu Sep 3 21:04:10 2009
@@ -76,7 +76,10 @@
public void testDefaultContent() throws Exception {
String s = "Message content";
- StringEntity httpentity = new StringEntity(s, HTTP.US_ASCII);
+ StringEntity httpentity = new StringEntity(s, "text/csv", "ANSI_X3.4-1968");
+ assertEquals("text/csv; charset=ANSI_X3.4-1968",
+ httpentity.getContentType().getValue());
+ httpentity = new StringEntity(s, HTTP.US_ASCII);
assertEquals("text/plain; charset=US-ASCII",
httpentity.getContentType().getValue());
httpentity = new StringEntity(s);