+htc #19708 provides default marshaller for akka.Done (200, empty text response)
This commit is contained in:
parent
4dd6efc6a8
commit
3d718cf1f1
4 changed files with 13 additions and 1 deletions
|
|
@ -5,6 +5,7 @@
|
|||
package docs.http.scaladsl.server.directives
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
import akka.http.scaladsl.marshalling.ToResponseMarshallable
|
||||
import docs.http.scaladsl.server.RoutingSpec
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ class MarshallingSpec extends FreeSpec with Matchers with BeforeAndAfterAll with
|
|||
"StringMarshaller should marshal strings to `text/plain` content in UTF-8" in {
|
||||
marshal("Ha“llo") shouldEqual HttpEntity("Ha“llo")
|
||||
}
|
||||
"DoneMarshaller should enable marshalling of akka.Done" in {
|
||||
marshal(akka.Done) shouldEqual HttpEntity("")
|
||||
}
|
||||
"CharArrayMarshaller should marshal char arrays to `text/plain` content in UTF-8" in {
|
||||
marshal("Ha“llo".toCharArray) shouldEqual HttpEntity("Ha“llo")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package akka.http.scaladsl.marshalling
|
|||
import java.nio.CharBuffer
|
||||
|
||||
import akka.http.scaladsl.model.MediaTypes._
|
||||
import akka.http.scaladsl.model.ContentTypes.`text/plain(UTF-8)`
|
||||
import akka.http.scaladsl.model._
|
||||
import akka.util.ByteString
|
||||
|
||||
|
|
@ -35,6 +36,11 @@ trait PredefinedToEntityMarshallers extends MultipartMarshallers {
|
|||
HttpEntity(contentType, array)
|
||||
} else HttpEntity.Empty
|
||||
|
||||
implicit val DoneMarshaller: ToEntityMarshaller[akka.Done] =
|
||||
Marshaller.withFixedContentType(`text/plain(UTF-8)`) { done ⇒
|
||||
HttpEntity(`text/plain(UTF-8)`, "")
|
||||
}
|
||||
|
||||
implicit val StringMarshaller: ToEntityMarshaller[String] = stringMarshaller(`text/plain`)
|
||||
def stringMarshaller(mediaType: MediaType.WithOpenCharset): ToEntityMarshaller[String] =
|
||||
Marshaller.withOpenCharset(mediaType) { (s, cs) ⇒ HttpEntity(mediaType withCharset cs, s) }
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
package akka.http.scaladsl.marshalling
|
||||
|
||||
import akka.stream.impl.ConstantFun
|
||||
|
||||
import scala.collection.immutable
|
||||
import akka.http.scaladsl.util.FastFuture._
|
||||
import akka.http.scaladsl.model.MediaTypes._
|
||||
|
|
@ -18,7 +20,7 @@ trait PredefinedToResponseMarshallers extends LowPriorityToResponseMarshallerImp
|
|||
implicit m: ToEntityMarshaller[T]): ToResponseMarshaller[T] =
|
||||
fromStatusCodeAndHeadersAndValue compose (t ⇒ (status, headers, t))
|
||||
|
||||
implicit val fromResponse: TRM[HttpResponse] = Marshaller.opaque(conforms)
|
||||
implicit val fromResponse: TRM[HttpResponse] = Marshaller.opaque(ConstantFun.scalaIdentityFunction)
|
||||
|
||||
implicit val fromStatusCode: TRM[StatusCode] =
|
||||
Marshaller.withOpenCharset(`text/plain`) { (status, charset) ⇒
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue