aleha_84
aleha_84

Reputation: 8539

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.

Upvotes: 6

Views: 2174

Answers (1)

ThePhantomOfTheChrome
ThePhantomOfTheChrome

Reputation: 106

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.

Upvotes: 9

Related Questions