I have a .net service endpoint to return a list of entities with a GET request. However I do require an OData filter option to be defined, as I don't support a query for all the entities. If a request without a filter is sent, my service will return a 405 response. Http spec says that 405 responses must define an Allow header, but there's no other allowed method in this entity. Fortunately, I see that the Allow header can also be defined as empty.
So this is what I am trying to do, I want to define the Allow header field as an empty string.
I see that HttpRequestMessage.Headers cannot have the Allow field defined, as the Allow field is a Content Header field, so I've tried defining it as the following:
response.Content.Headers.Add("Allow", string.Empty);response.Content.Headers.TryAddWithoutValidation("Allow", string.Empty);response.Content.Headers.Append(new KeyValuePair<string, IEnumerable<string>>("Allow", new List<string>()));
However, in all of these cases, if I ask: Assert.IsTrue(msg.Content.Headers.Contains("Allow"));, it fails.
Is there a way to force the empty header to be sent out? Or am I looking at this completely in the wrong way?
I don't understood why you want this but i think that the right way as follows:
response.Content.Headers.Allow.Add(string.Empty);