-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update http proxy to handle client disconnect scenario (#10688)
- Loading branch information
1 parent
c99ef0a
commit e9887fc
Showing
8 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/WebJobs.Script.Grpc/Exceptions/HttpForwardingException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.Grpc.Exceptions | ||
{ | ||
internal class HttpForwardingException : Exception | ||
{ | ||
public HttpForwardingException() | ||
{ | ||
} | ||
|
||
public HttpForwardingException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public HttpForwardingException(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/WebJobs.Script.WebHost/Middleware/HandleCancellationMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.Extensions; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Azure.WebJobs.Script.WebHost.Middleware | ||
{ | ||
internal class HandleCancellationMiddleware | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly RequestDelegate _next; | ||
|
||
public HandleCancellationMiddleware(RequestDelegate next, ILogger<HandleCancellationMiddleware> logger) | ||
{ | ||
_logger = logger; | ||
_next = next; | ||
} | ||
|
||
public async Task Invoke(HttpContext context) | ||
{ | ||
var requestId = context.Request.HttpContext.Items[ScriptConstants.AzureFunctionsRequestIdKey].ToString(); | ||
try | ||
{ | ||
await _next.Invoke(context); | ||
|
||
if (context.RequestAborted.IsCancellationRequested && !context.Response.HasStarted) | ||
{ | ||
_logger.RequestAborted(requestId); | ||
context.Response.StatusCode = StatusCodes.Status499ClientClosedRequest; | ||
} | ||
} | ||
catch (Exception ex) when ((ex is OperationCanceledException || ex is IOException) && context.RequestAborted.IsCancellationRequested) | ||
{ | ||
_logger.RequestAborted(requestId); | ||
|
||
if (!context.Response.HasStarted) | ||
{ | ||
context.Response.StatusCode = StatusCodes.Status499ClientClosedRequest; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters