Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpResponseMessage ReasonPhrase max length?

I have this code:

public void Put(int id, DistributionRuleModelListItem model)
{
    CommonResultModel pre = new BLL.DistributionRules().Save(id, model, true);
    if(!pre.success){
        DAL.DBManager.DestroyContext();
        var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
        {
            Content = new StringContent(string.Format("Internal server error for distruleId: {0}", id)),
            ReasonPhrase = pre.message.Replace(Environment.NewLine, " ")//.Substring(0,400)
        };
        throw new HttpResponseException(resp);
    }
}

There is logic that can set the value of pre.message to be an exception.ToString() and if it is too long i receive the following application exception:

Specified argument was out of the range of valid values. Parameter name: value

But if I uncomment .Substring(0,400) everything works fine and on client side I receive the correct response and it is possible to show it to the user.

What is the max length of ReasonPhrase? I can't find any documentation that specifies this value.

like image 629
aleha Avatar asked Sep 17 '14 12:09

aleha


1 Answers

I couldn't find the max value documented anywhere, however through trial and error, I found it to have a maximum length of 512 bytes.

like image 150
ThePhantomOfTheChrome Avatar answered Oct 07 '22 22:10

ThePhantomOfTheChrome