0

In a asp.net core reverse proxy setup, the goal is to intercept the OData response from the target server. You then replace all instances of the target server's URL with the proxy server's URL before forwarding it to the client. The received response has a content type of "application/json;odata.metadata=minimal". The objective is to achieve this transformation while keeping the response intact and without altering the response type.

I have implemented reverse proxy similar way given in the link.

4
  • you have this invoke method in your custom middleware, i.sstatic.net/xC8jO.png then what you need to do is getting the response content, then modify the data and update the content. What's your trouble here? Can this question help you? Commented Aug 7, 2023 at 3:28
  • I am able to modify the content , but could not set content type explicitely as "odata.metadata=minimal" while returning the response. Due to which client side not able to generate the next link. Commented Aug 9, 2023 at 16:00
  • sorry I'm not able to understand your issue well... Did you get any error/exception? Commented Aug 10, 2023 at 2:51
  • works fine with content-type application/json, after response modification, forgot to update content-type and content-length header. Commented Aug 22, 2023 at 12:35

1 Answer 1

0

After modifying the received response from the target server, applied below changes worked for me:

if ( IsContentOfType(responseMessage, "application/json") )
{
    var stringContent = Encoding.UTF8.GetString(content);
   // modify content
   context.Response.Headers.Remove("Content-Type");
   context.Response.Headers.Remove("Content-Length");
   context.Response.Headers.Add("Content-Type", "application/json;charset=UTF-8;");
   await context.Response.WriteAsync(stringContent, Encoding.UTF8);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.