Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
!hco #15915 introduce more shades of HttpEntities
The introduction of BodyParts again showed that not all entity types are useful for every kind of context. There are now these contexts where HttpEntities are used: - requests - responses - body parts And several kinds of entities: - Strict - Default - Chunked - CloseDelimited - IndefiniteLength To increase type safety of the API marker-interfaces are introduced defining which kinds of entities can be used in which contexts: - RequestEntity: Strict, Default, Chunked - ResponseEntity: Strict, Default, Chunked, CloseDelimited - BodyPartEntity: Strict, Default, IndefiniteLength Also, to be able still to provide abstractions over some kinds of entities additional auxiliary interfaces were necessary: - MessageEntity = RequestEntity >: ResponseEntity: Strict, Default, Chunked (type alias for RequestEntity) - UniversalEntity = RequestEntity with ResponseEntity with BodyPartEntity = Strict, Default
- Loading branch information
Showing
40 changed files
with
289 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> | ||
*/ | ||
|
||
package akka.http.model.japi; | ||
|
||
/** Marker-interface for entity types that can be used in a body part */ | ||
public interface BodyPartEntity extends HttpEntity {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> | ||
*/ | ||
|
||
package akka.http.model.japi; | ||
|
||
import java.io.File; | ||
|
||
import akka.util.ByteString; | ||
import org.reactivestreams.Publisher; | ||
|
||
import akka.stream.FlowMaterializer; | ||
import akka.http.model.HttpEntity$; | ||
|
||
/** Constructors for HttpEntity instances */ | ||
public final class HttpEntities { | ||
private HttpEntities() {} | ||
|
||
public static HttpEntityStrict create(String string) { | ||
return HttpEntity$.MODULE$.apply(string); | ||
} | ||
|
||
public static HttpEntityStrict create(byte[] bytes) { | ||
return HttpEntity$.MODULE$.apply(bytes); | ||
} | ||
|
||
public static HttpEntityStrict create(ByteString bytes) { | ||
return HttpEntity$.MODULE$.apply(bytes); | ||
} | ||
|
||
public static HttpEntityStrict create(ContentType contentType, String string) { | ||
return HttpEntity$.MODULE$.apply((akka.http.model.ContentType) contentType, string); | ||
} | ||
|
||
public static HttpEntityStrict create(ContentType contentType, byte[] bytes) { | ||
return HttpEntity$.MODULE$.apply((akka.http.model.ContentType) contentType, bytes); | ||
} | ||
|
||
public static HttpEntityStrict create(ContentType contentType, ByteString bytes) { | ||
return HttpEntity$.MODULE$.apply((akka.http.model.ContentType) contentType, bytes); | ||
} | ||
|
||
public static UniversalEntity create(ContentType contentType, File file) { | ||
return HttpEntity$.MODULE$.apply((akka.http.model.ContentType) contentType, file); | ||
} | ||
|
||
public static HttpEntityDefault create(ContentType contentType, long contentLength, Publisher<ByteString> data) { | ||
return new akka.http.model.HttpEntity.Default((akka.http.model.ContentType) contentType, contentLength, data); | ||
} | ||
|
||
public static HttpEntityCloseDelimited createCloseDelimited(ContentType contentType, Publisher<ByteString> data) { | ||
return new akka.http.model.HttpEntity.CloseDelimited((akka.http.model.ContentType) contentType, data); | ||
} | ||
|
||
public static HttpEntityIndefiniteLength createIndefiniteLength(ContentType contentType, Publisher<ByteString> data) { | ||
return new akka.http.model.HttpEntity.IndefiniteLength((akka.http.model.ContentType) contentType, data); | ||
} | ||
|
||
public static HttpEntityChunked createChunked(ContentType contentType, Publisher<ChunkStreamPart> chunks) { | ||
return new akka.http.model.HttpEntity.Chunked( | ||
(akka.http.model.ContentType) contentType, | ||
Util.<ChunkStreamPart, akka.http.model.HttpEntity.ChunkStreamPart>upcastPublisher(chunks)); | ||
} | ||
|
||
public static HttpEntityChunked createChunked(ContentType contentType, Publisher<ByteString> data, FlowMaterializer materializer) { | ||
return akka.http.model.HttpEntity.Chunked$.MODULE$.fromData( | ||
(akka.http.model.ContentType) contentType, | ||
data, materializer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> | ||
*/ | ||
|
||
package akka.http.model.japi; | ||
|
||
import akka.util.ByteString; | ||
import org.reactivestreams.Publisher; | ||
|
||
/** | ||
* Represents an entity without a predetermined content-length to use in a BodyParts. | ||
*/ | ||
public abstract class HttpEntityIndefiniteLength implements BodyPartEntity { | ||
public abstract Publisher<ByteString> data(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> | ||
*/ | ||
|
||
package akka.http.model.japi; | ||
|
||
/** Marker-interface for entity types that can be used in a request */ | ||
public interface RequestEntity extends ResponseEntity {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> | ||
*/ | ||
|
||
package akka.http.model.japi; | ||
|
||
/** Marker-interface for entity types that can be used in a response */ | ||
public interface ResponseEntity extends HttpEntity {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> | ||
*/ | ||
|
||
package akka.http.model.japi; | ||
|
||
/** Marker-interface for entity types that can be used in any context */ | ||
public interface UniversalEntity extends RequestEntity, ResponseEntity, BodyPartEntity {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.