0

Right now we are writing a gateway server, it receives a request from client, modify it and send the modified request to upstream, then copy response back to client.

Here we come out a problem that, what if upstream returns HTTP status code 500, should we return 500 to client? If so, how do we distinguish whether gateway failed or upstream failed?

Similar issues also apply to HTTP status code 404, 429 etc...

So, question is:

1. Should gateway return HTTP status code as whatever upstream returns?  
   In this case, how do we distinguish which server failed exactly  
   (consider that in a monitor system)

2. Is it a good practice that gateway map upstream status codes to some  
   fixed range of status codes? e.g. upstream 5xx -> client 502
dastan
  • 1,006
  • 1
  • 16
  • 36
  • Firstly, what would posess you to write a gateway? Or is this going to be a commercial product for sale? These things take years to write, and there are a lot of pitfalls, and there are free ones available. In answer to your question, it is normal to pass back through the received status. If the proxy fails, it can use 504, but even that can be returned from a server (e.g. if it's behind a reverse proxy). – Adrien Aug 24 '16 at 10:17
  • @Adrien Our gateway is not a pure HTTP proxy like nginx, it does some tiny logical things related to our business. I wouldn't argue about the question itself, but thanks for advising. :D Anyway, due to your answer, how do we distinguish which server failed exactly (consider that in a monitor system)? – dastan Aug 25 '16 at 03:20
  • You can add a custom header in the response. There are proxies out there already that can do all manner of modifications. Our product [WinGate](http://www.wingate.com) will allow you to make all sorts of modifications to requests and responses using a variety of tools, and. can integrate with external systems such as databases, files etc. There are a lot of things to get right in a proxy, especially if it will be used by a variety of clients, or has any requirement for performance. Disclaimer: I work for Qbik who make WinGate – Adrien Aug 25 '16 at 03:24

0 Answers0