-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathAPIGatewayWebsocketApiProxyFunction.cs
More file actions
70 lines (60 loc) · 2.48 KB
/
APIGatewayWebsocketApiProxyFunction.cs
File metadata and controls
70 lines (60 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using Microsoft.AspNetCore.Http;
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.AspNetCoreServer.Internal;
namespace Amazon.Lambda.AspNetCoreServer
{
/// <summary>
/// Base class for ASP.NET Core Lambda functions that are getting request from API Gateway Websocket API V2 payload format.
///
/// The http method is fixed as POST. Requests are handled using the RouteKey, so the same lambda should be referenced by multiple API Gateway routes for the ASP.NET Core IServer to successfully route requests.
/// </summary>
public abstract class APIGatewayWebsocketApiProxyFunction : APIGatewayProxyFunction
{
/// <summary>
/// Default constructor
/// </summary>
protected APIGatewayWebsocketApiProxyFunction()
: base()
{
}
/// <inheritdoc/>
/// <param name="startupMode">Configure when the ASP.NET Core framework will be initialized</param>
protected APIGatewayWebsocketApiProxyFunction(StartupMode startupMode)
: base(startupMode)
{
}
/// <summary>
/// Constructor used by Amazon.Lambda.AspNetCoreServer.Hosting to support ASP.NET Core projects using the Minimal API style.
/// </summary>
/// <param name="hostedServices"></param>
protected APIGatewayWebsocketApiProxyFunction(IServiceProvider hostedServices)
: base(hostedServices)
{
_hostServices = hostedServices;
}
/// <inheritdoc/>
/// <param name="apiGatewayRequest"></param>
/// <returns>string</returns>
protected override string ParseHttpPath(APIGatewayProxyRequest apiGatewayRequest)
{
var path = "/" + Utilities.DecodeResourcePath(apiGatewayRequest.RequestContext.RouteKey);
return path;
}
/// <inheritdoc/>
/// <param name="apiGatewayRequest"></param>
/// <returns>string</returns>
protected override string ParseHttpMethod(APIGatewayProxyRequest apiGatewayRequest)
{
return "POST";
}
/// <inheritdoc/>
/// <returns>IHeaderDictionary</returns>
protected override IHeaderDictionary AddMissingRequestHeaders(APIGatewayProxyRequest apiGatewayRequest, IHeaderDictionary headers)
{
headers = base.AddMissingRequestHeaders(apiGatewayRequest, headers);
headers["Content-Type"] = "application/json";
return headers;
}
}
}