Warning HTTP Header - legal agent string format

Viewed 93

I've just set a Warning HTTP header for the first time. In the System.Net .NET namespace, there's a type WarningHeaderValue with this constructor:

WarningHeaderValue(int code, string agent, string text)

But it throws on my agent string saying

The format of value 'Company Name .NET Origin' is invalid.

What format is legal for the agent? I couldn't glean anything useful from the HTTP spec.

 warn-agent = ( uri-host [ ":" port ] ) / pseudonym
                 ; the name or pseudonym of the server adding
                 ; the Warning header field, for use in debugging
                 ; a single "-" is recommended when agent unknown
 warn-text  = quoted-string
 warn-date  = DQUOTE HTTP-date DQUOTE

What's missing in all these arcane specifications are examples.

1 Answers

In this case, quoted-string means include quotes within the string. So instead of: "Deprecated API" , it would be "\"Deprecated API\""

Full example:

HttpResponseMessage response = await base.ExecuteAsync(cancellationToken);

string message = $"\"Deprecated API : use {NewUri} instead.\"";
response.Headers.Warning.Add(new WarningHeaderValue(299, "-", message));
return response;
Related