5using System.Threading.Tasks;
7using Microsoft.AspNetCore.Authorization;
8using Microsoft.AspNetCore.Mvc;
9using Microsoft.Extensions.Hosting;
10using Microsoft.Extensions.Logging;
26 [Route(
"/" + RouteExtension)]
28 [ApiExplorerSettings(IgnoreApi =
true)]
59 readonly ILogger<BridgeController>
logger;
80 ArgumentNullException.ThrowIfNull(applicationLifetime);
82 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
95 public async ValueTask<IActionResult>
Process([FromQuery]
string data, CancellationToken cancellationToken)
100 var remoteIP = Request.HttpContext.Connection.RemoteIpAddress;
101 if (remoteIP ==
null || !IPAddress.IsLoopback(remoteIP))
103 logger.LogTrace(
"Rejecting remote bridge request from {remoteIP}", remoteIP);
115 logger.LogWarning(ex,
"Error deserializing bridge request: {badJson}", data);
117 logger.LogWarning(ex,
"Error deserializing bridge request!");
125 logger.LogWarning(
"Error deserializing bridge request: {badJson}", data);
127 logger.LogWarning(
"Error deserializing bridge request!");
133 logger.LogTrace(
"Bridge Request: {json}", data);
135 logger.LogTrace(
"Bridge Request");
138 if (response ==
null)
144 logger.LogTrace(
"Bridge Response: {json}", responseJson);
145 return Content(responseJson, MediaTypeNames.Application.Json);
Routes to a server actions.
const string ApiRoot
The root of API methods.
Parameters for a bridge request.
Constants used for communication with the DMAPI.
static readonly JsonSerializerSettings SerializerSettings
JsonSerializerSettings for use when communicating with the DMAPI.
Base class for all API style controllers.
Controller for receiving DMAPI requests from DreamDaemon.
BridgeController(IBridgeDispatcher bridgeDispatcher, IHostApplicationLifetime applicationLifetime, ILogger< BridgeController > logger)
Initializes a new instance of the BridgeController class.
static long requestsProcessed
Static counter for the number of requests processed.
static bool LogContent
If the content of bridge requests and responses should be logged.
readonly ILogger< BridgeController > logger
The ILogger for the BridgeController.
readonly IBridgeDispatcher bridgeDispatcher
The IBridgeDispatcher for the BridgeController.
const string RouteExtension
The route to the BridgeController.
async ValueTask< IActionResult > Process([FromQuery] string data, CancellationToken cancellationToken)
Processes a bridge request.
static uint logContentDisableCounter
Counter which, if not zero, indicates content logging should be disabled.
Helpers for manipulating the Serilog.Context.LogContext.
const string BridgeRequestIterationContextProperty
The Serilog.Context.LogContext property name for the ID of the bridge request currently being process...
Handler for BridgeParameters.
ValueTask< BridgeResponse?> ProcessBridgeRequest(BridgeParameters parameters, CancellationToken cancellationToken)
Handle a set of bridge parameters .