NetCoreServer icon indicating copy to clipboard operation
NetCoreServer copied to clipboard

SetHeader() does not work after HttpResponse has been created using factory methods.

Open juhani-honkala opened this issue 3 years ago • 2 comments
trafficstars

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.

juhani-honkala avatar Sep 22 '22 17:09 juhani-honkala

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.

stratdev3 avatar Oct 31 '22 12:10 stratdev3

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.

chronoxor avatar Oct 31 '22 14:10 chronoxor