IIS and RestSharp & # 8594; Is the response body cut off for a 40x error?

Situation

It seems pretty simple: I have a service running on IIS 7. Client POSTS data (application / json), and I check the data before accepting it.

If I do not accept this, I really wanted to return 406 and the same ~ data as the body (possibly changed / fixed) [1]. Unfortunately, this leads to truncated response bodies as well as invalid json.

To get started, enable forwarding for my errors because IIS is trying to be smart otherwise:

<httpErrors errorMode="Detailed" existingResponse="PassThrough">
</httpErrors>

The relevant part of my code makes the moral equivalent of this:

HttpResponseBase response = context.HttpContext.Response;

response.StatusCode = StatusCode;
response.StatusDescription = StatusDescription;

if (!string.IsNullOrEmpty(ContentType))
    response.ContentType = ContentType;
else
    response.ContentType = "application/json";

if (ContentEncoding != null)
    response.ContentEncoding = ContentEncoding;

using (var sw = new StreamWriter(response.OutputStream))
{
    sw.Write(JsonConvert.SerializeObject(Data));
}

On the client side, I'm doing naive right now (to find json truncation issue)

var response = myRestClient.Execute(myRestRequest);

Problem

If the response returns a status code of 200, I get this

response.ContentLength == 69345
response.RawBytes.Length == 69345

, ( 406 ), , :

response.ContentLength == 69345
response.RawBytes.Length == 65536 // <--- Not! Good!

65536 , . , ? RestSharp, IIS .

1: , , , ?

+3
1

: RestSharp RestResponse 64 kb

, RestSharp HttpWebRequest .NET Framework. DefaultMaximumErrorResponseLength. , - 64 .

0

All Articles