c# - Content Headers Remove fails for string Authorization -


the following test fails inexplicably:

    [test]     public void crazyasshttprequestmessagetest()     {         var subject = new httprequestmessage()                           {                               method = httpmethod.get,                               content = new stringcontent("some content")                           };         subject.content.headers.remove("authorization");     } 

the exceptions is:

system.invalidoperationexception : misused header name. make sure request headers used httprequestmessage, response headers httpresponsemessage, , content headers httpcontent objects.

why? other header seems work fine, replace authorization else , ok.

the httpcontentheaders class supports subset of http headers -- headers relating content. seems bit of odd decision split them way, that's way framework works.

the upshot there never authorization header in request.content.headers.

you same error if try remove "content-type" httprequestheaders or httpresponseheaders, or if try add unexpected header these collections without calling tryaddwithoutvalidation. more frustrating fact contains() throw if try check invalid header. can check existence without throwing without worrying exact type of header collection using httpheaders.trygetvalues, or use request.content.headers.any(x => x.key == "authorization").

the classes linked above have list of headers explicitly support (as typed properties) e.g. httpcontentheaders.contenttype.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -