Incus J 10 Posted October 17, 2022 In OverbyteIcsHttpServ, the error procedures such as THttpConnection.Answer404 are called from various places in the code and have hard coded HTML. I'd like to serve my own error document instead. Is there a built in mechanism to supply a custom HTML error document for errors such as 404, 403 ? Share this post Link to post
Angus Robertson 591 Posted October 17, 2022 To send custom error responses you can create overloaded versions of Answer404, etc, in your version of THttpConnection or THttpAppSrvConnection. Angus 1 Share this post Link to post
Incus J 10 Posted October 17, 2022 Perfect - I had missed the virtual nature of Answer404 - Thank you! Share this post Link to post
nSolvePaul 0 Posted Monday at 11:48 AM I tried to do exactly this. i.e. I have created my own TManagersHttpConnection derived from THttpAppSrvConnection class TManagersHttpConnection: public THttpAppSrvConnection { typedef THttpAppSrvConnection inherited; private: protected: virtual void __fastcall Answer404(); public: __fastcall TManagersHttpConnection(Classes::TComponent* AOwner); }; I then told the OverbyteIcsHttpServ that ClientClass to use is the above one: __fastcall TnManagersHttpAppServer::TnManagersHttpAppServer(Classes::TComponent * AOwner) : THttpAppSrv(AOwner) { ClientClass = __classid(TManagersHttpConnection); My TManagersHttpConnection constructor gets called when a new client connects, exactly as I expect. Yet my Answer404() function does NOT get called for a missing file, instead the content served is that from the base THttpAppSrvConnection class. What might I be doing wrong please? FYI this is using ICS version: Revised: September 27, 2021 Release: V8.67 With Borland C++ 2007 Which for various reasons is not viable to update. Share this post Link to post
Angus Robertson 591 Posted Monday at 12:13 PM If you are stuck using an old version, which is understandable for old compilers, why not just customise the Answer404 function? Angus Share this post Link to post
nSolvePaul 0 Posted Monday at 01:27 PM Thanks for the alternative suggestion In fact it does work just fine, I think as I was only calling inherited::Answer404(); the compiler had optimized it out. Onwards and upwards now 🙂 Share this post Link to post
Angus Robertson 591 Posted Monday at 04:09 PM The ICS web server should probably offer an event to make creating customised error pages easier, I've put it on the wish list. Our error pages are very minimal. Angus Share this post Link to post