hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1162317 - in /httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http: entity/ContentType.java protocol/HTTP.java
Date Sat, 27 Aug 2011 09:32:09 GMT
Author: olegk
Date: Sat Aug 27 09:32:07 2011
New Revision: 1162317

URL: http://svn.apache.org/viewvc?rev=1162317&view=rev
Log:
HTTPCORE-271: default ContentTypes
Contributed by William R. Speirs <bill.speirs at gmail.com>

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HTTP.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java?rev=1162317&r1=1162316&r2=1162317&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
Sat Aug 27 09:32:07 2011
@@ -50,16 +50,45 @@ import org.apache.http.protocol.HTTP;
 @Immutable
 public final class ContentType {
 
-    public static final ContentType DEFAULT_TEXT = new ContentType(
-            HTTP.PLAIN_TEXT_TYPE, HTTP.DEFAULT_CONTENT_CHARSET);
-    public static final ContentType DEFAULT_BINARY = new ContentType(
-            "application/octet-stream", null);
+    // constants
+    public static final ContentType APPLICATION_ATOM_XML = new ContentType(
+    		"application/atom+xml", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType APPLICATION_FORM_URLENCODED = new ContentType(
+    		"application/x-www-form-urlencoded", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType APPLICATION_JSON = new ContentType(
+    		"application/json", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType APPLICATION_OCTET_STREAM = new ContentType(
+    		"application/octet-stream", null);
+    public static final ContentType APPLICATION_SVG_XML = new ContentType(
+    		"application/svg+xml", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType APPLICATION_XHTML_XML = new ContentType(
+    		"application/xhtml+xml", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType APPLICATION_XML = new ContentType(
+    		"application/xml", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType MULTIPART_FORM_DATA = new ContentType(
+    		"multipart/form-data", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType TEXT_HTML = new ContentType(
+    		"text/html", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType TEXT_PLAIN = new ContentType(
+    		"text/plain", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType TEXT_XML = new ContentType(
+    		"text/xml", HTTP.DEFAULT_CONTENT_CHARSET);
+    public static final ContentType WILDCARD = new ContentType(
+    		"*/*", null);
+
+    // defaults
+    public static final ContentType DEFAULT_TEXT = TEXT_PLAIN;
+    public static final ContentType DEFAULT_BINARY = APPLICATION_OCTET_STREAM;
 
     private final String mimeType;
     private final String charset;
 
+    /**
+     * Given a mime type and a character set, constructs a ContentType.
+     * @param mimeType The mime type to use for the ContentType header.
+     * @param charset The optional character set to use with the ContentType header.
+     */
     ContentType(final String mimeType, final String charset) {
-        super();
         this.mimeType = mimeType;
         this.charset = charset;
     }
@@ -72,6 +101,10 @@ public final class ContentType {
         return this.charset;
     }
 
+    /**
+     * Converts a ContentType to a string which can be used as a ContentType header.
+     * If a charset is provided by the ContentType, it will be included in the string.
+     */
     @Override
     public String toString() {
         StringBuilder buf = new StringBuilder();

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HTTP.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HTTP.java?rev=1162317&r1=1162316&r2=1162317&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HTTP.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HTTP.java
Sat Aug 27 09:32:07 2011
@@ -27,6 +27,8 @@
 
 package org.apache.http.protocol;
 
+import org.apache.http.entity.ContentType;
+
 /**
  * Constants and static helpers related to the HTTP protocol.
  *
@@ -79,7 +81,7 @@ public final class HTTP {
     public final static String CHARSET_PARAM = "; charset=";
 
     /** Default content type */
-    public final static String DEFAULT_CONTENT_TYPE = OCTET_STREAM_TYPE;
+    public final static String DEFAULT_CONTENT_TYPE = ContentType.APPLICATION_OCTET_STREAM.toString();
 
     public static boolean isWhitespace(char ch) {
         return ch == SP || ch == HT || ch == CR || ch == LF;



Mime
View raw message