Skip to content

Core transport

  • Package: com.com2usplatform.hiveaxyl.core
  • Namespaces: Hive.Axyl.Core

ITransport

  • Kind: interface
  • Namespace: Hive.Axyl.Core

Sends an HTTP request and returns the raw response. Implementations handle the actual network I/O (e.g., UnityWebRequest).

Methods

SendAsync

Sends the request and returns the HTTP response wrapped in a Result{T}. Returns Fail for transport-level failures (network, timeout).

Task<Result<HttpResponse>> SendAsync(HttpRequest request, CancellationToken ct = default)
Parameter Type Default Description
request HttpRequest —
ct CancellationToken default

IRefreshTransport

  • Kind: interface
  • Namespace: Hive.Axyl.Core
  • Inherits: ITransport

Marker for the auth-refresh transport: the same interceptor chain as the main pipeline minus AuthInterceptor, with the 401-refresh gate inactive. The token-refresh handler calls the refresh endpoint over this transport so the request neither re-enters the refresh gate (deadlock) nor carries the expired access token.

HttpRequest

  • Kind: class
  • Namespace: Hive.Axyl.Core

A mutable HTTP request passed through the interceptor pipeline. Method and Url are immutable after construction. Headers, Body, and Options may be modified by interceptors before the request is sent. Credential is resolved by the pipeline before the interceptors run and is read again after the response; interceptors must not modify it.

Thread safety: instances must not be shared across concurrent SendAsync calls.

Properties

Property Type Description
Method HiveHttpMethod The HTTP method (GET, POST, etc.).
Url string The full request URL including query string.
Headers Dictionary<string, string> Mutable request headers. Interceptors add/modify headers here.
Body byte[]? Raw request body bytes. null for requests without a body (e.g., GET).
Options RequestOptions? Optional per-request policy overrides. null uses global defaults.
Credential CallCredential The credential this request authenticates with. Generated code sets Anonymous on endpoints whose contract requires no authentication; a non-default Credential takes precedence.
Context ApiCallContext? Optional call context carrying idempotency key and custom metadata. Set before the request enters the interceptor pipeline.

Constructors

Creates a new HttpRequest with empty headers and no body.

HttpRequest(HiveHttpMethod method, string url)
Parameter Type Default Description
method HiveHttpMethod — The HTTP method.
url string — The full request URL. Must not be null or empty.

The method throws in the cases below.

  • ArgumentNullException: Thrown when url is null.
  • ArgumentException: Thrown when url is empty or does not use the http or https scheme.

HttpResponse

  • Kind: class
  • Namespace: Hive.Axyl.Core

An immutable HTTP response received from the server. All properties are read-only after construction.

Headers are stored in a case-insensitive ReadOnlyDictionary{TKey,TValue} (RFC 7230). The constructor copies input headers — callers cannot mutate them after creation.

Properties

Property Type Description
StatusCode int The HTTP status code (e.g., 200, 404, 500).
Headers IReadOnlyDictionary<string, string> Response headers. Case-insensitive key lookup (RFC 7230).
Body byte[] Raw response body bytes. Never null; empty responses use Empty{T}.
IsSuccess bool true when StatusCode is in the 2xx range (200–299).
IsProblemJson bool true when the Content-Type header contains application/problem+json (RFC 9457). Returns false if the header is absent.
Request HttpRequest? The originating request that produced this response, when supplied by the transport. null when the response is synthesized without a request (e.g., direct unit-test construction). The reference is shared, not copied: callers must not mutate the request (or its Options) between response creation and the completion of the response interceptor chain, since interceptors read per-request flags through this reference.

Constructors

Creates a new HttpResponse. Headers are copied into a case-insensitive dictionary.

HttpResponse(int statusCode, IReadOnlyDictionary<string, string> headers, byte[] body, HttpRequest? request = null)
Parameter Type Default Description
statusCode int — The HTTP status code.
headers IReadOnlyDictionary<string, string> — Response headers. Copied with case-insensitive comparer.
body byte[] — Raw response body. Use Empty{T} for empty.
request HttpRequest? null Optional originating HttpRequest. Transports should pass the request so that response-phase interceptors can read per-request options (e.g., SkipLogging) without cross-phase ambient state.

The method throws in the cases below.

  • ArgumentNullException: Thrown when headers or body is null.

HiveHttpMethod

  • Kind: enum
  • Namespace: Hive.Axyl.Core

HTTP method for transport-level requests. Named HiveHttpMethod to avoid collision with System.Net.Http.HttpMethod.

Member Value Description
Get — HTTP GET.
Post — HTTP POST.
Put — HTTP PUT.
Patch — HTTP PATCH.
Delete — HTTP DELETE.
Head — HTTP HEAD.
Options — HTTP OPTIONS.

Result

  • Kind: struct
  • Namespace: Hive.Axyl.Core

An infrastructure-level result representing whether an HTTP response was received. Used internally by Transport, interceptors, token refresh logic, and generated code. Game developers interact with IAxylResult instead.

IsOk is true when an HTTP response was received, including 4xx and 5xx status codes. It is false only for transport-level failures such as network disconnection or timeout.

Type parameter Description
T The type of the value on success (typically HttpResponse).

Properties

Property Type Description
IsOk bool Whether an HTTP response was successfully received. 4xx/5xx responses are still considered Ok (the server responded).
Value T The response value. Only valid when IsOk is true. Returns default(T) when IsOk is false; callers must check IsOk first.
Error HiveError The transport-level error. When IsOk is true, contains a sentinel with OK. When IsOk is false, contains the actual transport-level failure.

Methods

Ok

Creates a successful result containing the given value.

static Result<T> Ok(T value)
Parameter Type Default Description
value T — The HTTP response or other success value.
  • Returns: Result<T>. A result where IsOk is true.

Fail

Creates a failed result containing the given transport-level error.

static Result<T> Fail(HiveError error)
Parameter Type Default Description
error HiveError — The error describing the transport failure.
  • Returns: Result<T>. A result where IsOk is false.

The method throws in the cases below.

  • ArgumentNullException: Thrown when error is null.

ITokenRefreshHandler

  • Kind: interface
  • Namespace: Hive.Axyl.Core

Defines the contract for performing a token refresh API call.

Auth Capability implements this interface to provide the server-specific refresh logic. Core handles session update and pending queue coordination around the handler result.

Implementations send the refresh request once and do not retry it. A refresh token is single-use: the server invalidates it as soon as a refresh uses it, so resending a request whose response was lost would present a token that is no longer valid. Core consumes only the returned TokenRefreshResponse and does not retry either.

Methods

RefreshAsync

Performs a token refresh with the refresh token in request.

Task<TokenRefreshResponse> RefreshAsync(TokenRefreshRequest request, CancellationToken ct)
Parameter Type Default Description
request TokenRefreshRequest — The refresh input Core builds from the current session.
ct CancellationToken — Cancellation token.
  • Returns: Task<TokenRefreshResponse>. A TokenRefreshResponse carrying the new tokens on success, or one of three unsuccessful shapes whose choice drives Core's session handling. Rejected reports the server's typed verdict that the refresh token itself is invalid (invalid_grant_refresh_token): the SDK destroys the stored session and fires OnSessionExpired. Failure reports a final failure without such a verdict (transport failure, timeout, 5xx, any other code, a 2xx without usable tokens): the SDK preserves the session and reports the given error to the request that started the refresh and to every request from the same login that waited on it, so build it as any other request's failure is built. If that login changes while the refresh is in flight, those requests get FailedPrecondition with Auth_SessionChanged instead. Three consecutive no-verdict failures end the in-memory session silently (no event — persisted credentials survive for a next-launch restore). Each handler invocation counts as one attempt toward that limit. Cancelled reports a caller-cancelled attempt, which neither touches the session nor counts toward that halt. A failure whose error is Cancelled is handled the same way. Beware of returning Failure for a server verdict of invalidity: a preserved-forever session can then never be signed out via refresh — use Rejected for the verdict.

TokenRefreshRequest

  • Kind: class
  • Namespace: Hive.Axyl.Core

The input Core passes to RefreshAsync.

Core builds it from the current session. Later versions may add properties here instead of changing the handler signature.

Properties

Property Type Description
RefreshToken string The refresh token of the current session.

Constructors

Creates a request that refreshes the session with refreshToken.

TokenRefreshRequest(string refreshToken)
Parameter Type Default Description
refreshToken string — The refresh token of the current session.

The method throws in the cases below.

  • ArgumentNullException: Thrown when refreshToken is null.

TokenRefreshResponse

  • Kind: struct
  • Namespace: Hive.Axyl.Core

Result of a token refresh operation, returned by ITokenRefreshHandler.

Success requires both AccessToken and RefreshToken to be non-null; use Success to construct a successful response. Core only acts on the handler's final result.

An unsuccessful attempt takes one of three mutually exclusive shapes, and Core's session handling hinges on which one: Rejected carries the server's verdict that the refresh token itself is invalid, the only outcome that lets Core destroy the session; Failure is a final failure without a verdict on the refresh token (transport failure, server error, unusable response) after which Core preserves the session; and Cancelled reports a caller-cancelled attempt that never concluded, so the session likewise stays intact. Failures without a verdict have one exception: on the third in a row within the same session, Core clears the in-memory session without raising OnSessionExpired and reports Unavailable with Auth_RefreshHalted.

Properties

Property Type Description
AccessToken string? New access token. Non-null on success.
RefreshToken string? New refresh token. Non-null on success.
ExpiresAt DateTimeOffset? When the new access token expires. Set only on success, and null there too when the handler cannot tell. Core stores it in the session without reading it.
IsSuccess bool Whether the refresh succeeded (both tokens present).
IsCancelled bool Whether the caller cancelled the attempt before it concluded. Distinct from a no-verdict Failure in that it neither counts toward the consecutive-failure halt nor resets that run; the session is left untouched either way.
IsRejected bool Whether the server delivered a verdict that the refresh token itself is invalid. This is the only unsuccessful outcome that makes Core end the session and raise OnSessionExpired. A plain Failure leaves the session in place, except that on the third failure without a verdict in a row within the same session Core clears the in-memory session.
ErrorMessage string? Optional diagnostic message describing a failure, a rejection, or a cancellation; may be null. On cancellation this is the only thing distinguishing one reason from another, since the reported code is always Cancelled. For a failure built from a HiveError it is that error's message.
Error HiveError? The error a failure built from a HiveError carries, which Core reports unchanged to the request that started the refresh and to every request from the same login that waited on it. Null for every other response.

Methods

Success

Creates a successful response with new tokens.

static TokenRefreshResponse Success(string accessToken, string refreshToken, DateTimeOffset? expiresAt)
Parameter Type Default Description
accessToken string — The new access token.
refreshToken string — The new refresh token.
expiresAt DateTimeOffset? — When the new access token expires, or null if unknown.

Failure

Creates a final failure without a verdict on the refresh token: the attempt concluded, but nothing judged the stored credentials (transport failure, server error, unusable 2xx response, unexpected exception). Core preserves the session and reports error unchanged to the request that started the refresh and to every request from the same login that waited on it, so build it the way any other request's failure is built. There are two exceptions. If that login changes while the refresh is in flight, Core reports FailedPrecondition with Auth_SessionChanged. On the third consecutive no-verdict failure within one session generation, Core ends the in-memory session silently (no OnSessionExpired; persisted credentials survive for a next-launch restore) and reports Unavailable with Auth_RefreshHalted. Report a caller cancellation with Cancelled; an error whose code is Cancelled is treated as one.

static TokenRefreshResponse Failure(HiveError error)
Parameter Type Default Description
error HiveError — The failure of the refresh call.

The method throws in the cases below.

  • ArgumentNullException: Thrown when error is null.

Creates a no-verdict failure that carries only a diagnostic message. Core handles it like the overload that takes a HiveError, but reports Unavailable without an external code, since there is no error to pass on.

static TokenRefreshResponse Failure(string? errorMessage = null)
Parameter Type Default Description
errorMessage string? null

Rejected

Creates a response carrying the server's verdict that the refresh token itself is invalid (revoked, expired, or unknown — e.g. the token endpoint's invalid_grant_refresh_token outcome). This lets Core destroy the session that held the judged token — firing OnSessionExpired and reporting Unauthenticated — but the destruction is epoch-fenced: a stale verdict that lost the fence (the session changed while the attempt was in flight) destroys nothing and reports FailedPrecondition with Auth_SessionChanged.

static TokenRefreshResponse Rejected(string? errorMessage = null)
Parameter Type Default Description
errorMessage string? null

Cancelled

Creates a cancelled response. Core reports the cancellation to the caller without clearing the session, since the attempt reached no verdict on the credentials.

static TokenRefreshResponse Cancelled(string? errorMessage = null)
Parameter Type Default Description
errorMessage string? null