HttpRequestSender

com.github.cloudfiles.core.http.HttpRequestSender

An actor implementation for sending HTTP requests to a specific host.

This module provides an actor-like wrapper around Akka HTTP's host level API. An HTTP request can be sent by passing a message to this actor. The actor processes the request and replies with a corresponding response.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Classlikes

object DiscardEntityMode extends Enumeration

An enumeration that controls when the entity of a response should be discarded by the request sender actor.

An enumeration that controls when the entity of a response should be discarded by the request sender actor.

Note that it is important that the entity of a response is '''always''' either read or discarded; otherwise, the HTTP pipeline is blocked. This is in the responsibility of the application. HttpRequestSender supports this a mechanism to discard entities automatically controlled by this enumeration. The following values can be set:

  • ''OnFailure'': The entity is discarded automatically if a response with a non-success status code is received. This is the default behavior.
  • ''Always'': The response entity is always discarded. This is useful for instance for update requests, that typically do not return a response entity.
  • ''Never'': The response entity is never discarded; this has to be done manually by the application. This is useful for instance if the server returns important information in failure case.

Attributes

Supertypes
class Enumeration
trait Serializable
class Object
trait Matchable
class Any
Self type
final case class FailedResponseException(response: HttpResponse) extends Exception

An exception class indicating a response with a non-success status code. The exception contains the original response, so it can be evaluated. Exceptions of this type are contained in a FailedResult object if the failure was caused by a non-success response.

An exception class indicating a response with a non-success status code. The exception contains the original response, so it can be evaluated. Exceptions of this type are contained in a FailedResult object if the failure was caused by a non-success response.

Value parameters

response

the failed response

Attributes

Supertypes
trait Product
trait Equals
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
final case class FailedResult(request: SendRequest, cause: Throwable) extends Result

A message class representing a failure response of an HTTP request. The class contains the original request and the exception that was the cause of the failure

A message class representing a failure response of an HTTP request. The class contains the original request and the exception that was the cause of the failure

Value parameters

cause

the exception causing the request to fail

request

the original request

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Result
class Object
trait Matchable
class Any
Show all
final case class ForwardedResult(result: Result) extends HttpCommand

A message class representing the result of a request that has been forwarded to another request actor.

A message class representing the result of a request that has been forwarded to another request actor.

This message type is not handled by this actor class itself, but it is used by extension actors that add functionality to request actors. Such extensions may have to inspect the result of a request to trigger specific actions (e.g. retry a failed request under certain circumstances). Therefore, there must be a way to deal with incoming results.

Value parameters

result

the result

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait HttpCommand
class Object
trait Matchable
class Any
Show all
sealed trait HttpCommand

The base trait for all commands understood by this actor class.

The base trait for all commands understood by this actor class.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class SendRequest
object Stop.type
sealed trait Result

A trait describing the result of an HTTP request sent by this actor.

A trait describing the result of an HTTP request sent by this actor.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
final case class SendRequest(request: HttpRequest, data: Any, replyTo: ActorRef[Result], discardEntityMode: DiscardEntityMode) extends HttpCommand

A message class that describes a request to be sent. The request is associated with a data object that is also part of the response.

A message class that describes a request to be sent. The request is associated with a data object that is also part of the response.

Value parameters

data

a data object

discardEntityMode

controls how to discard the response entity

replyTo

the object to send the reply to

request

the request to be sent

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait HttpCommand
class Object
trait Matchable
class Any
Show all
case object Stop extends HttpCommand

A message causing this actor to stop itself. This can be used to clean up actor instances that are no longer needed.

A message causing this actor to stop itself. This can be used to clean up actor instances that are no longer needed.

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait HttpCommand
class Object
trait Matchable
class Any
Show all
Self type
Stop.type
final case class SuccessResult(request: SendRequest, response: HttpResponse) extends Result

A message class representing a successful response of an HTTP request.

A message class representing a successful response of an HTTP request.

Value parameters

request

the original request

response

the response to this request

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait Result
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def apply(uri: Uri, queueSize: Int, proxy: ProxySelectorFunc): Behavior[HttpCommand]

Creates a new actor instance for sending HTTP requests to the host defined by the URI specified.

Creates a new actor instance for sending HTTP requests to the host defined by the URI specified.

Value parameters

proxy

a function to select the proxy for requests

queueSize

the size of the request queue

uri

the URI defining the target host

Attributes

Returns

the behavior of the actor

def discardEntityBytes[R <: Result](result: R)(implicit system: ActorSystem[_]): Future[R]

Discards the bytes of the entity from the given result from an ''HttpRequestSender'' actor. This function is useful if the caller is not interested in the response body. (Nevertheless, the body stream needs to be processed to avoid blocking of the HTTP stream.) If the result is not a SuccessResult, no action is performed.

Discards the bytes of the entity from the given result from an ''HttpRequestSender'' actor. This function is useful if the caller is not interested in the response body. (Nevertheless, the body stream needs to be processed to avoid blocking of the HTTP stream.) If the result is not a SuccessResult, no action is performed.

Type parameters

R

the type of the result

Value parameters

result

the result

system

the actor system

Attributes

Returns

a ''Future'' with the result with the entity bytes discarded

def discardEntityBytes[R <: Result](futResult: Future[R])(implicit system: ActorSystem[_]): Future[R]

Discards the bytes of the entity from the given ''Future'' result from an ''HttpRequestSender'' actor. Works like the method with the same name, but operates on the result future rather than the actual result.

Discards the bytes of the entity from the given ''Future'' result from an ''HttpRequestSender'' actor. Works like the method with the same name, but operates on the result future rather than the actual result.

Value parameters

futResult

the ''Future'' with the result object

system

the actor system

Attributes

Returns

a ''Future'' of the result with the entity discarded

def forwardRequest(context: ActorContext[HttpCommand], receiver: ActorRef[HttpCommand], request: HttpRequest, requestData: Any, discardMode: DiscardEntityMode, timeout: Timeout): Unit

Forwards a request to another request actor using the ''ask'' pattern. The response is then passed to the owner of the given context as a ForwardedResult message. This functionality is intended to be used by extension actors that intercept the normal request processing mechanism.

Forwards a request to another request actor using the ''ask'' pattern. The response is then passed to the owner of the given context as a ForwardedResult message. This functionality is intended to be used by extension actors that intercept the normal request processing mechanism.

Value parameters

context

the actor context

discardMode

controls when to discard the entity's bytes

receiver

the actor to send the message to

request

the HTTP request to forward

requestData

the request data

timeout

a timeout for the request

Attributes

Generates a ''Result'' object from the result of a request that has been forwarded to another actor. This function is intended to be used by extension actors. It expects that the request data contains the original request. Therefore, this request is extracted, and a correct result is constructed which references it. If the data object of the forwarded request is not of type ''SendRequest'', this function fails with a match error.

Generates a ''Result'' object from the result of a request that has been forwarded to another actor. This function is intended to be used by extension actors. It expects that the request data contains the original request. Therefore, this request is extracted, and a correct result is constructed which references it. If the data object of the forwarded request is not of type ''SendRequest'', this function fails with a match error.

Value parameters

result

the result from the forwarded request

Attributes

Returns

the result to return to the original caller

def sendRequest(sender: ActorRef[HttpCommand], request: HttpRequest, discardMode: DiscardEntityMode, requestData: Any)(implicit system: ActorSystem[_], timeout: Timeout): Future[Result]

Convenience function to send an HTTP request to an ''HttpRequestSender'' actor. This function simplifies the sending of requests from outside an actor context. It implements the corresponding ask pattern.

Convenience function to send an HTTP request to an ''HttpRequestSender'' actor. This function simplifies the sending of requests from outside an actor context. It implements the corresponding ask pattern.

Value parameters

discardMode

controls when to discard the entity's bytes

request

the HTTP request to be sent

requestData

the data object associated with the request

sender

the actor to process the request

system

the actor system

timeout

the timeout for the ask operation

Attributes

Returns

a ''Future'' with the result of request processing

def sendRequestSuccess(sender: ActorRef[HttpCommand], request: HttpRequest, discardMode: DiscardEntityMode, requestData: Any)(implicit system: ActorSystem[_], timeout: Timeout): Future[SuccessResult]

Convenience function to send an HTTP request to an ''HttpRequestSender'' actor and checking the result. This function invokes ''sendRequest()'' and then checks for the result. If it is a success result, it is returned. Otherwise, a failed future is returned with the exception from the failed result.

Convenience function to send an HTTP request to an ''HttpRequestSender'' actor and checking the result. This function invokes ''sendRequest()'' and then checks for the result. If it is a success result, it is returned. Otherwise, a failed future is returned with the exception from the failed result.

Value parameters

discardMode

controls when to discard the entity's bytes

request

the HTTP request to be sent

requestData

the data object associated with the request

sender

the actor to process the request

system

the actor system

timeout

the timeout for the ask operation

Attributes

Returns

a ''Future'' with the successful result of request processing

Concrete fields

final val DefaultQueueSize: 16

The default size of the request queue.

The default size of the request queue.

Attributes