-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathHostingOptions.cs
More file actions
231 lines (215 loc) · 12 KB
/
HostingOptions.cs
File metadata and controls
231 lines (215 loc) · 12 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using Amazon.Lambda.Core;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http.Features.Authentication;
namespace Amazon.Lambda.AspNetCoreServer.Hosting;
/// <summary>
/// Options for configuring AWS Lambda hosting for ASP.NET Core
/// </summary>
public class HostingOptions
{
/// <summary>
/// The ILambdaSerializer used by Lambda to convert the incoming event JSON into the .NET event type and serialize the .NET response type
/// back to JSON to return to Lambda.
/// </summary>
public ILambdaSerializer Serializer { get; set; }
/// <summary>
/// The default response content encoding to use when no explicit content type or content encoding mapping is registered.
/// Defaults to ResponseContentEncoding.Default (UTF-8 text).
/// </summary>
public ResponseContentEncoding DefaultResponseContentEncoding { get; set; } = ResponseContentEncoding.Default;
/// <summary>
/// Controls whether unhandled exception details are included in responses.
/// Defaults to false for security.
/// </summary>
public bool IncludeUnhandledExceptionDetailInResponse { get; set; } = false;
/// <summary>
/// Callback invoked after request marshalling to customize the HTTP request feature.
/// Receives the IHttpRequestFeature, Lambda request object, and ILambdaContext.
/// The Lambda request object will need to be cast to the appropriate type based on the event source.
/// <para>
/// <list type="table">
/// <listheader>
/// <term>API Type</term>
/// <description>Event Type</description>
/// </listheader>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.HttpApi">HttpApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest">APIGatewayHttpApiV2ProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.RestApi">RestApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest">APIGatewayProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.ApplicationLoadBalancer">ApplicationLoadBalancer</see></term>
/// <description><see cref="Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerRequest">ApplicationLoadBalancerRequest</see></description>
/// </item>
/// </list>
/// </para>
/// </summary>
public Action<IHttpRequestFeature, object, ILambdaContext>? PostMarshallRequestFeature { get; set; }
/// <summary>
/// Callback invoked after response marshalling to customize the HTTP response feature.
/// Receives the IHttpResponseFeature, Lambda response object, and ILambdaContext.
/// The Lambda response object will need to be cast to the appropriate type based on the event source.
/// <para>
/// <list type="table">
/// <listheader>
/// <term>API Type</term>
/// <description>Event Type</description>
/// </listheader>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.HttpApi">HttpApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse">APIGatewayHttpApiV2ProxyResponse</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.RestApi">RestApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse">APIGatewayProxyResponse</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.ApplicationLoadBalancer">ApplicationLoadBalancer</see></term>
/// <description><see cref="Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerResponse">ApplicationLoadBalancerResponse</see></description>
/// </item>
/// </list>
/// </para>
/// </summary>
public Action<IHttpResponseFeature, object, ILambdaContext>? PostMarshallResponseFeature { get; set; }
/// <summary>
/// Callback invoked after connection marshalling to customize the HTTP connection feature.
/// Receives the IHttpConnectionFeature, Lambda request object, and ILambdaContext.
/// The Lambda request object will need to be cast to the appropriate type based on the event source.
/// <para>
/// <list type="table">
/// <listheader>
/// <term>API Type</term>
/// <description>Event Type</description>
/// </listheader>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.HttpApi">HttpApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest">APIGatewayHttpApiV2ProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.RestApi">RestApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest">APIGatewayProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.ApplicationLoadBalancer">ApplicationLoadBalancer</see></term>
/// <description><see cref="Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerRequest">ApplicationLoadBalancerRequest</see></description>
/// </item>
/// </list>
/// </para>
/// </summary>
public Action<IHttpConnectionFeature, object, ILambdaContext>? PostMarshallConnectionFeature { get; set; }
/// <summary>
/// Callback invoked after authentication marshalling to customize the HTTP authentication feature.
/// Receives the IHttpAuthenticationFeature, Lambda request object, and ILambdaContext.
/// The Lambda request object will need to be cast to the appropriate type based on the event source.
/// <para>
/// <list type="table">
/// <listheader>
/// <term>API Type</term>
/// <description>Event Type</description>
/// </listheader>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.HttpApi">HttpApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest">APIGatewayHttpApiV2ProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.RestApi">RestApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest">APIGatewayProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.ApplicationLoadBalancer">ApplicationLoadBalancer</see></term>
/// <description><see cref="Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerRequest">ApplicationLoadBalancerRequest</see></description>
/// </item>
/// </list>
/// </para>
/// </summary>
public Action<IHttpAuthenticationFeature, object, ILambdaContext>? PostMarshallHttpAuthenticationFeature { get; set; }
/// <summary>
/// Callback invoked after TLS connection marshalling to customize the TLS connection feature.
/// Receives the ITlsConnectionFeature, Lambda request object, and ILambdaContext.
/// The Lambda request object will need to be cast to the appropriate type based on the event source.
/// <para>
/// <list type="table">
/// <listheader>
/// <term>API Type</term>
/// <description>Event Type</description>
/// </listheader>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.HttpApi">HttpApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest">APIGatewayHttpApiV2ProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.RestApi">RestApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest">APIGatewayProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.ApplicationLoadBalancer">ApplicationLoadBalancer</see></term>
/// <description><see cref="Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerRequest">ApplicationLoadBalancerRequest</see></description>
/// </item>
/// </list>
/// </para>
/// </summary>
public Action<ITlsConnectionFeature, object, ILambdaContext>? PostMarshallTlsConnectionFeature { get; set; }
/// <summary>
/// Callback invoked after items marshalling to customize the items feature.
/// Receives the IItemsFeature, Lambda request object, and ILambdaContext.
/// The Lambda request object will need to be cast to the appropriate type based on the event source.
/// <para>
/// <list type="table">
/// <listheader>
/// <term>API Type</term>
/// <description>Event Type</description>
/// </listheader>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.HttpApi">HttpApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest">APIGatewayHttpApiV2ProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.RestApi">RestApi</see></term>
/// <description><see cref="Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest">APIGatewayProxyRequest</see></description>
/// </item>
/// <item>
/// <term><see cref="Microsoft.Extensions.DependencyInjection.LambdaEventSource.ApplicationLoadBalancer">ApplicationLoadBalancer</see></term>
/// <description><see cref="Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerRequest">ApplicationLoadBalancerRequest</see></description>
/// </item>
/// </list>
/// </para>
/// </summary>
public Action<IItemsFeature, object, ILambdaContext>? PostMarshallItemsFeature { get; set; }
/// <summary>
/// Internal storage for content type to response content encoding mappings.
/// </summary>
internal Dictionary<string, ResponseContentEncoding> ContentTypeEncodings { get; } = new();
/// <summary>
/// Internal storage for content encoding to response content encoding mappings.
/// </summary>
internal Dictionary<string, ResponseContentEncoding> ContentEncodingEncodings { get; } = new();
/// <summary>
/// Registers a response content encoding for a specific content type.
/// </summary>
/// <param name="contentType">The content type (e.g., "application/json", "image/png")</param>
/// <param name="encoding">The response content encoding to use for this content type</param>
public void RegisterResponseContentEncodingForContentType(string contentType, ResponseContentEncoding encoding)
{
if (string.IsNullOrEmpty(contentType))
{
return;
}
ContentTypeEncodings[contentType] = encoding;
}
/// <summary>
/// Registers a response content encoding for a specific content encoding.
/// </summary>
/// <param name="contentEncoding">The content encoding (e.g., "gzip", "deflate", "br")</param>
/// <param name="encoding">The response content encoding to use for this content encoding</param>
public void RegisterResponseContentEncodingForContentEncoding(string contentEncoding, ResponseContentEncoding encoding)
{
if (string.IsNullOrEmpty(contentEncoding))
{
return;
}
ContentEncodingEncodings[contentEncoding] = encoding;
}
}