in http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpMessage.scala [321:432]
def discardEntityBytes()(implicit mat: Materializer): HttpMessage.DiscardedEntity =
httpMessage.discardEntityBytes(mat)
}
}
/**
* The immutable model HTTP request model.
*/
final class HttpRequest(
val method: HttpMethod,
val uri: Uri,
val headers: immutable.Seq[HttpHeader],
val attributes: Map[AttributeKey[_], _],
val entity: RequestEntity,
val protocol: HttpProtocol)
extends jm.HttpRequest with HttpMessage {
HttpRequest.verifyUri(uri)
require(entity.isKnownEmpty || method.isEntityAccepted,
s"Requests with method '${method.value}' must have an empty entity")
require(
protocol != HttpProtocols.`HTTP/1.0` || !entity.isChunked,
"HTTP/1.0 requests must not have a chunked entity")
type Self = HttpRequest
def self: Self = this
override def isRequest = true
override def isResponse = false
@deprecated("use the constructor that includes an attributes parameter instead", "Akka HTTP 10.2.0")
private[model] def this(method: HttpMethod, uri: Uri, headers: immutable.Seq[HttpHeader], entity: RequestEntity,
protocol: HttpProtocol) =
this(method, uri, headers, Map.empty, entity, protocol)
/**
* Resolve this request's URI according to the logic defined at
* http://tools.ietf.org/html/rfc7230#section-5.5
*
* Throws an [[IllegalUriException]] if the URI is relative and the `headers` don't
* include a valid [[pekko.http.scaladsl.model.headers.Host]] header or if URI authority and [[pekko.http.scaladsl.model.headers.Host]] header don't match.
*/
def effectiveUri(securedConnection: Boolean, defaultHostHeader: Host = Host.empty): Uri =
HttpRequest.effectiveUri(uri, headers, securedConnection, defaultHostHeader)
/**
* Returns a copy of this request with the URI resolved according to the logic defined at
* http://tools.ietf.org/html/rfc7230#section-5.5
*/
def withEffectiveUri(securedConnection: Boolean, defaultHostHeader: Host = Host.empty): HttpRequest =
copyImpl(uri = effectiveUri(securedConnection, defaultHostHeader))
/**
* All cookies provided by the client in one or more `Cookie` headers.
*/
def cookies: immutable.Seq[HttpCookiePair] = for (case `Cookie`(cookies) <- headers; cookie <- cookies) yield cookie
/**
* Determines whether this request can be safely retried, which is the case only of the request method is idempotent.
*/
def canBeRetried = method.isIdempotent
override def withHeaders(headers: immutable.Seq[HttpHeader]): HttpRequest =
if (headers eq this.headers) this else copyImpl(headers = headers)
override def withAttributes(attributes: Map[AttributeKey[_], _]): HttpRequest =
if (attributes eq this.attributes) this else copyImpl(attributes = attributes)
override def withHeadersAndEntity(headers: immutable.Seq[HttpHeader], entity: RequestEntity): HttpRequest =
copyImpl(headers = headers, entity = entity)
override def withEntity(entity: jm.RequestEntity): HttpRequest = copyImpl(entity = entity.asInstanceOf[RequestEntity])
override def withEntity(entity: MessageEntity): HttpRequest = copyImpl(entity = entity)
def mapEntity(f: RequestEntity => RequestEntity): HttpRequest = withEntity(f(entity))
override def withMethod(method: pekko.http.javadsl.model.HttpMethod): HttpRequest =
copyImpl(method = method.asInstanceOf[HttpMethod])
override def withProtocol(protocol: pekko.http.javadsl.model.HttpProtocol): HttpRequest =
copyImpl(protocol = protocol.asInstanceOf[HttpProtocol])
override def withUri(path: String): HttpRequest = withUri(Uri(path))
def withUri(uri: Uri): HttpRequest = copyImpl(uri = uri)
def transformEntityDataBytes[M](transformer: Graph[FlowShape[ByteString, ByteString], M]): HttpRequest =
copyImpl(entity = entity.transformDataBytes(Flow.fromGraph(transformer)))
import JavaMapping.Implicits._
/** Java API */
override def getUri: jm.Uri = uri.asJava
/** Java API */
override def withUri(uri: jm.Uri): HttpRequest = copyImpl(uri = uri.asScala)
/* Manual Case Class things, to easen bin-compat */
@deprecated("Use the `withXYZ` methods instead. Kept for binary compatibility", "Akka HTTP 10.2.0")
def copy(
method: HttpMethod = method,
uri: Uri = uri,
headers: immutable.Seq[HttpHeader] = headers,
entity: RequestEntity = entity,
protocol: HttpProtocol = protocol) = copyImpl(method, uri, headers, entity = entity, protocol = protocol)
private def copyImpl(
method: HttpMethod = method,
uri: Uri = uri,
headers: immutable.Seq[HttpHeader] = headers,
attributes: Map[AttributeKey[_], _] = attributes,
entity: RequestEntity = entity,
protocol: HttpProtocol = protocol) = new HttpRequest(method, uri, headers, attributes, entity, protocol)
override def hashCode(): Int = {