IndySockets / Indy

Indy - Internet Direct
https://www.indyproject.org
451 stars 153 forks source link

Update IdCustomHTTPServer responses #520

Open pressanykey101 opened 8 months ago

pressanykey101 commented 8 months ago

Found myself in need for response 308 Permanent Redirect. Don't see an easy way to extend/override TIdHTTPResponseInfo.SetResponseNo functionality. It would be nice to have an ability to upload a list of responses with corresponding text messages as a list or array at or after TIdHTTPServer creation.

rlebeau commented 8 months ago

In an OnCommand... event handler, you can manually set the response's ResponseNo and ResponseText properties (in that order) to whatever values you want. The ResponseNo property setter will assign a default string to the ResponseText, based on HTTP standards, but you can just overwrite that value with your own string, eg:

AResponseInfo.ResponseNo := 308;
AResponseInfo.ResponseText := 'Permanent Redirect';

That being said, allowing the user to customize the default ResponseText strings is an interesting idea, but it will have to wait for a future release since that is a whole new feature set to add (new properties, design-time editing, etc).

But, in the meantime, I have updated the ResponseNo setter to now include default ResponseText strings for a bunch of new status codes, including 308.