NetCoreServer
NetCoreServer copied to clipboard
SetHeader() does not work after HttpResponse has been created using factory methods.
SetHeader() does not work propery after HttpResponse has been created using factory methods, e.g. MakeGetResponse(). The reason is that the standard headers (length + content-type) and content body is already written to the internal Cache buffer inside HttpResponse. This means that subsequent calls to SetHeader() are useless as they are put in the cache after the content body.
From the API design and uage perspective, this is not optimal and leads to hard-to-track bugs. Perhaps the internal cache buffer could be created only during Send() or alternatively an Exception could be thrown, if the body has been already written to the cache before additional SetHeader() calls.
agree. I passed an hour wondering why my response was not correct. SetHeader() must be called at first. So i have to duplicate a MakeCustomResponse() to handle this behavious.
Make...Request() methods are very simple examples how to prepare GET/POST/PUT/DELETE requests. If you need something complicated with your custom headers, cookies you have to prepare HttpRequest using Clear(), SetBegin(), SetHeader(), SetCookie(), AddCookie(), SetBody() helper methods.