diff --git a/src/PwrDrvr.LambdaDispatch.Router/LambdaConnection.cs b/src/PwrDrvr.LambdaDispatch.Router/LambdaConnection.cs index 98cb3f86..da1637a3 100644 --- a/src/PwrDrvr.LambdaDispatch.Router/LambdaConnection.cs +++ b/src/PwrDrvr.LambdaDispatch.Router/LambdaConnection.cs @@ -122,7 +122,7 @@ private async Task ProxyRequestToLambda(HttpRequest incomingRequest) _logger.LogDebug("LambdaId: {}, ChannelId: {} - Sending incoming request headers to Lambda", Instance.Id, ChannelId); // TODO: Get the 32 KB header size limit from configuration - var headerBuffer = ArrayPool.Shared.Rent(32 * 1024); + var headerBuffer = ArrayPool.Shared.Rent(128 * 1024); try { int offset = 0; @@ -138,6 +138,13 @@ private async Task ProxyRequestToLambda(HttpRequest incomingRequest) // Send the headers to the Lambda foreach (var header in incomingRequest.Headers) { + // Skip any cookie headers, they are handled below + // Cookies need to be consolidated into a single header + // if (string.Compare(header.Key, "Cookie", StringComparison.OrdinalIgnoreCase) == 0) + // { + // continue; + // } + // Write the header to the buffer var headerLine = $"{header.Key}: {header.Value}\r\n"; var headerLineBytes = Encoding.UTF8.GetBytes(headerLine); @@ -145,6 +152,22 @@ private async Task ProxyRequestToLambda(HttpRequest incomingRequest) offset += headerLineBytes.Length; } + // Combine all cookies into a single Cookie header + // if (incomingRequest.Cookies.Count != 0) + // { + // var cookies = string.Join("; ", incomingRequest.Cookies.Select(c => $"{c.Key}={c.Value}")); + // var cookieHeaderLine = $"Cookie: {cookies}\r\n"; + // var cookieHeaderLineBytes = Encoding.UTF8.GetBytes(cookieHeaderLine); + // cookieHeaderLineBytes.CopyTo(headerBuffer, offset); + // offset += cookieHeaderLineBytes.Length; + // } + + // Add X-Forwarded-Proto Header + var forwardedProtoHeaderLine = "X-Forwarded-Proto: https\r\n"; + var forwardedProtoHeaderLineBytes = Encoding.UTF8.GetBytes(forwardedProtoHeaderLine); + forwardedProtoHeaderLineBytes.CopyTo(headerBuffer, offset); + offset += forwardedProtoHeaderLineBytes.Length; + // Send the end of the headers headerBuffer[offset + 1] = (byte)'\n'; headerBuffer[offset] = (byte)'\r'; @@ -325,7 +348,7 @@ private async Task RelayResponseFromLambda(HttpRequest incomingRequest, HttpResp _logger.LogDebug("LambdaId: {} - Copying response body from Lambda", Instance.Id); // TODO: Get the 32 KB header size limit from configuration - var headerBuffer = ArrayPool.Shared.Rent(32 * 1024); + var headerBuffer = ArrayPool.Shared.Rent(128 * 1024); try { // Read up to max headers size of data @@ -467,6 +490,9 @@ private async Task RelayResponseFromLambda(HttpRequest incomingRequest, HttpResp // such as Set-Cookie incomingResponse.Headers.Append(key, value); + // Print the header + _logger.LogInformation("LambdaId: {}, ChannelId: {} - Response header: {headerLine}", Instance.Id, ChannelId, headerLine); + // Move the start to the character after '\n' startOfNextLine = endOfLine + 1; }