private void DispatchRequest(object sender, HttpRequestReceivedEventArgs eventArgs) { if (!eventArgs.Context.Request.Uri.StartsWith("/api/", StringComparison.OrdinalIgnoreCase)) { return; } eventArgs.IsHandled = true; DispatchRequest(eventArgs.Context); }
private void DispatchHttpRequest(object sender, HttpRequestReceivedEventArgs eventArgs) { if (!eventArgs.Context.Request.Uri.StartsWith("/api/")) { return; } eventArgs.IsHandled = true; DispatchHttpRequest(eventArgs.Context); }
private void HandleHttpRequest(HttpRequestReceivedEventArgs e) { try { HttpRequestReceived?.Invoke(this, e); } finally { if (_webSocketClientSession == null) { if (!e.IsHandled || e.Context.Request.Headers.ConnectionMustBeClosed()) { _cancellationTokenSource.Cancel(); } } } }
private void OnHttpRequestReceived(object sender, HttpRequestReceivedEventArgs e) { if (e.Context.Request.Uri.StartsWith(ApiBaseUri, StringComparison.OrdinalIgnoreCase)) { e.IsHandled = true; OnApiRequestReceived(e.Context); } else if (e.Context.Request.Uri.StartsWith(AppBaseUri, StringComparison.OrdinalIgnoreCase)) { e.IsHandled = true; OnAppRequestReceived(e.Context, StoragePath.AppRoot); } else if (e.Context.Request.Uri.StartsWith(ManagementAppBaseUri, StringComparison.OrdinalIgnoreCase)) { e.IsHandled = true; OnAppRequestReceived(e.Context, StoragePath.ManagementAppRoot); } }
private void OnRequestReceived(object sender, HttpRequestReceivedEventArgs e) { string path = e.Request.Url.AbsolutePath; bool routeFound = true; if (!_router.TryInvokeRoute(path, e.Request, e.Response, out RouteAttribute attribute)) { // Try the alternative route. string alternativePath = path.Replace(AlternativeRoute, ""); routeFound = _router.TryInvokeRoute(alternativePath, e.Request, e.Response, out attribute); } if (!routeFound) { if (Log404) { string body = ""; if (e.Request.ContentLength64 > 0) { byte[] buffer = new byte[e.Request.ContentLength64]; e.Request.InputStream.Read(buffer, 0, buffer.Length); body = Encoding.UTF8.GetString(buffer); } Log.Warning($"404 for {e.Request.HttpMethod} {e.Request.Url.AbsolutePath} {{Method}}{{Url}}{{Query}}{{Body}}", e.Request.HttpMethod, e.Request.Url.AbsolutePath, e.Request.Url.Query, body); } e.Response.StatusCode = 404; } else { if (LogHttpRequests && (attribute == null || !attribute.IsHidden)) { Log.Information($"{e.Request.HttpMethod} {e.Request.Url.AbsolutePath} {{Method}}{{Url}}{{Query}}", e.Request.HttpMethod, e.Request.Url.AbsolutePath, e.Request.Url.Query); } } e.Response.Close(); }