Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create instance of HttpRequestHeaders class

I have to unit test class that use HttpRequestHeaders as parameter.

    public HeaderValueProvider(HttpRequestHeaders headers)     {         _headers = headers;     } 
like image 795
Bohdan Avatar asked Feb 18 '16 15:02

Bohdan


2 Answers

HttpRequestHeaders has only internal constructor. But you can do it by creating HttpRequestMesssage object:

using var headers = new HttpRequestMessage().Headers; 
like image 113
wolszakp Avatar answered Oct 06 '22 02:10

wolszakp


You can get a blank instance of HttpRequestHeaders via:

var headers = new HttpClient().DefaultRequestHeaders; 
like image 34
NikolaiDante Avatar answered Oct 06 '22 02:10

NikolaiDante