Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IdHTTP corrections when proxy is used
#2
(04-29-2019, 01:17 PM)NevTon Wrote: Hi, when using TIdHTTP with proxy there is exception generated when authorization was needed.
Exception EIdHTTPProtocolException is fired with some params, but I think that this procedure contains some bugs:
1. you can not have exception and not discard content from response at the same time
2. it fills this exception with empty information for response text and third parameter as well

I think you might have a misunderstanding of how hoNoProtocolErrorException and hoWantProtocolErrorContent are meant to work together (see New TIdHTTP flags and OnChunkReceived event).

If hoNoProtocolErrorException IS NOT set, and an HTTP error response is received, EIdHTTPProtocolException is meant to be raised (unless AIgnoreReplies includes the HTTP response code) and ALWAYS contain the response's body data in its ErrorMessage property.  This way, the caller ALWAYS has a chance of finding out what actually went wrong if needed, as the body data usually contains more detailed information than what the HTTP status line alone provides.

The purpose of hoWantProtocolErrorContent is to allow the caller to disable EIdHTTPProtocolException but still receive the body data of an error response.  When hoWantProtocolErrorContent IS set, but ONLY WHEN hoNoProtocolErrorException is ALSO set, then the body data is saved to the caller's target TStream (think when a server always sends a JSON document containing success/error info).  The body data is NOT saved to the caller's target TStream unless the caller EXPLICITLY asks for it, to avoid corrupting any data that may already be in the TStream (think when the caller is downloading a file to disk via a TFileStream).

hoWantProtocolErrorContent was originally intended to take effect ONLY when hoNoProtocolErrorException IS set. THIS IS BY DESIGN, it is not a bug.

Here the behavior before and after your proposed changes (click on the image to enlarge):

   

Is that what you really want?  What would be the actual use-case for this change?

Reply


Messages In This Thread
IdHTTP corrections when proxy is used - by NevTon - 04-29-2019, 01:17 PM
RE: IdHTTP corrections when proxy is used - by rlebeau - 04-30-2019, 07:17 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)