i2pd icon indicating copy to clipboard operation
i2pd copied to clipboard

Incorrect response codes for HTTP proxy

Open Vort opened this issue 2 years ago • 5 comments

When internal i2pd HTTP proxy fails to make connection, it returns response with error code 500. This is wrong, more suitable code is 503. Most likely, other errors have wrong codes too.

This is how Host is down case is processed now: https://github.com/PurpleI2P/i2pd/blob/c215f2e8d19f07b95163fdfecd974fa5eec2dce1/libi2pd_client/HTTPProxy.cpp#L773 https://github.com/PurpleI2P/i2pd/blob/c215f2e8d19f07b95163fdfecd974fa5eec2dce1/libi2pd_client/HTTPProxy.cpp#L165-L171 https://github.com/PurpleI2P/i2pd/blob/c215f2e8d19f07b95163fdfecd974fa5eec2dce1/libi2pd_client/HTTPProxy.cpp#L198-L212

Vort avatar Dec 05 '23 14:12 Vort

We use 500 Domain Not Found if the hostname is not in the addressbook and 504 Gateway TImeout if the host is apparently down (no LS or no response). Here's our error pages for reference: https://github.com/i2p/i2p.i2p/tree/master/apps/i2ptunnel/resources/proxy

zzzi2p avatar Dec 18 '23 11:12 zzzi2p

It means that Java I2P requires fixing as well.

Simply speaking, 500 error should appear only when something unexpected happened. When condition leading to error is known to developer, some other code is needed.

The HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request. This error response is a generic "catch-all" response. Usually, this indicates the server cannot find a better 5xx error code to response.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500

Vort avatar Dec 18 '23 12:12 Vort

We have 20+ error pages and we only use 500 for the one case I mentioned - hostname not in address book. You have a suggestion for what would be better for that?

zzzi2p avatar Dec 19 '23 11:12 zzzi2p

we only use 500 for the one case I mentioned - hostname not in address book. You have a suggestion for what would be better for that?

This is what I found:

Most I have seen return 502 Bad Gateway or 504 Gateway Timeout.

https://stackoverflow.com/questions/24395931/what-to-return-to-browser-if-dns-lookup-failed#comment37735176_24395931

unfortunately from time to time we get 504 error DNS lookup failed

https://community.cloudflare.com/t/cant-resolve-nationalbank-kz-name-proxy-504-dns-lookup-failed/54835

Vort avatar Dec 19 '23 11:12 Vort

changed to 502

zzzi2p avatar Dec 22 '23 13:12 zzzi2p