+htc add popular ContentType instances for convenience

This commit is contained in:
Konrad Malawski 2015-09-30 14:06:23 +02:00
parent 573a69e2b9
commit 9bd11620f0
5 changed files with 60 additions and 33 deletions

View file

@ -5,17 +5,20 @@ package akka.http.javadsl.model;
/**
* Contains the set of predefined content-types.
* Contains the set of predefined content-types for convenience.
* <p>
* If the {@link ContentType} you're looking for is not pre-defined here,
* you can obtain it from a {@link MediaType} by using:
* <p>
* {@code MediaTypes.TEXT_HTML.toContentType()}
* you can obtain it from a {@link MediaType} by using: {@code MediaTypes.TEXT_HTML.toContentType()}
*/
public final class ContentTypes {
public static final ContentType APPLICATION_JSON = MediaTypes.APPLICATION_JSON.toContentType();
public static final ContentType TEXT_PLAIN = MediaTypes.TEXT_PLAIN.toContentType();
public static final ContentType TEXT_PLAIN_UTF8 = akka.http.scaladsl.model.ContentTypes.text$divplain$u0028UTF$minus8$u0029();
public static final ContentType TEXT_HTML = MediaTypes.TEXT_HTML.toContentType();
public static final ContentType APPLICATION_OCTET_STREAM = MediaTypes.APPLICATION_OCTET_STREAM.toContentType();
public static final ContentType APPLICATION_JSON = MediaTypes.APPLICATION_JSON.toContentType();
public static final ContentType APPLICATION_OCTET_STREAM = MediaTypes.APPLICATION_OCTET_STREAM.toContentType();
public static final ContentType TEXT_PLAIN = MediaTypes.TEXT_PLAIN.toContentType();
public static final ContentType TEXT_PLAIN_UTF8 = akka.http.scaladsl.model.ContentTypes.text$divplain$u0028UTF$minus8$u0029();
public static final ContentType TEXT_HTML = MediaTypes.TEXT_HTML.toContentType();
public static final ContentType TEXT_XML = MediaTypes.TEXT_XML.toContentType();
public static final ContentType APPLICATION_X_WWW_FORM_URLENCODED = MediaTypes.APPLICATION_X_WWW_FORM_URLENCODED.toContentType();
public static final ContentType MULTIPART_FORM_DATA = MediaTypes.MULTIPART_FORM_DATA.toContentType();
}

View file

@ -90,10 +90,15 @@ object ContentType {
object ContentTypes {
val `application/json` = ContentType(MediaTypes.`application/json`)
val `application/octet-stream` = ContentType(MediaTypes.`application/octet-stream`)
val `text/plain` = ContentType(MediaTypes.`text/plain`)
val `text/plain(UTF-8)` = ContentType(MediaTypes.`text/plain`, HttpCharsets.`UTF-8`)
val `text/html` = ContentType(MediaTypes.`text/html`)
val `application/octet-stream` = ContentType(MediaTypes.`application/octet-stream`)
val `text/xml` = ContentType(MediaTypes.`text/xml`)
val `application/x-www-form-urlencoded` = ContentType(MediaTypes.`application/x-www-form-urlencoded`)
val `multipart/form-data` = ContentType(MediaTypes.`multipart/form-data`)
// used for explicitly suppressing the rendering of Content-Type headers on requests and responses
val NoContentType = ContentType(MediaTypes.NoMediaType)