We are using ProxyKit as an API proxy for our Geo services. But although it worked perfectly on our development environment and when talking to our GeoServer, it failed with the following exception when we tried to access an ASP.NET Core API through the same proxy:
502 Bad Gateway
This turned out to be a bug in ProxyKit version 2.2.1. ProxyKit sets an empty content when executing a GET request. ASP.NET Core doesn’t like this as it expects that GET requests doesn’t have a body.
As a work around I explicitly set the content to null when executing a GET request:
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
var forwardContext = context.ForwardTo(_sampleApiAddress); | |
var accessToken=_bearerTokenProvider.GetBearerToken(); | |
forwardContext.UpstreamRequest.Headers.Authorization= new AuthenticationHeaderValue("Bearer", accessToken); | |
//Set the content to null when executing a GET | |
if(context.Request.Method=="GET") | |
forwardContext.UpstreamRequest.Content=null; | |
var response= await forwardContext.Send(); |
Remark: A new version 2.2.2 was released last week to fix the issue: https://github.com/damianh/ProxyKit/releases/tag/v2.2.2.