本文整理汇总了C#中RequestHeaders类的典型用法代码示例。如果您正苦于以下问题:C# RequestHeaders类的具体用法?C# RequestHeaders怎么用?C# RequestHeaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestHeaders类属于命名空间,在下文中一共展示了RequestHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Request
public Request(string method, Url url, IHttpUtility httpUtility, RequestStream body = null, IDictionary<string, IEnumerable<string>> headers = null, string ip = null)
{
method.ArgumentNullOrEmptyCheck("method");
url.ArgumentNullCheck("url");
url.Path.ArgumentNullOrEmptyCheck("url.Path");
url.Scheme.ArgumentNullOrEmptyCheck("url.Scheme");
httpUtility.ArgumentNullCheck("httpUtility");
this.httpUtility = httpUtility;
Items = new Dictionary<string, object>();
UserHostAddress = ip;
Url = url;
Method = method;
Query = url.Query.AsQueryDictionary(httpUtility);
Body = body ?? RequestStream.FromStream(new MemoryStream());
Headers = new RequestHeaders(headers ?? new Dictionary<string, IEnumerable<string>>());
ParseFormData();
}
示例2: Should_return_empty_enumerable_when_accept_headers_are_not_available
public void Should_return_empty_enumerable_when_accept_headers_are_not_available()
{
// Given
var rawHeaders = new Dictionary<string, IEnumerable<string>>();
// When
var headers = new RequestHeaders(rawHeaders);
// Then
headers.Accept.ShouldHaveCount(0);
}
示例3: SetUp
public void SetUp()
{
httpRequest = new StubCurrentHttpRequest();
var container = StructureMapContainerFacility.GetBasicFubuContainer();
theHeaderValues = httpRequest.Headers;
container.Inject<ICurrentHttpRequest>(httpRequest);
theHeaders = container.GetInstance<RequestHeaders>();
}
示例4: SetUp
public void SetUp()
{
var container = StructureMapContainerFacility.GetBasicFubuContainer();
theHeaderValues = new KeyValues();
theRequest = new RequestData();
theRequest.AddValues(RequestDataSource.Header, theHeaderValues);
container.Inject<IRequestData>(theRequest);
theHeaders = container.GetInstance<RequestHeaders>();
}
示例5: Should_ignore_case_of_accept_charset_header_name_when_retrieving_values
public void Should_ignore_case_of_accept_charset_header_name_when_retrieving_values(string headerName)
{
// Given
var expectedValues = new[] { "utf-8", "iso-8859-5" };
var rawHeaders = new Dictionary<string, IEnumerable<string>> { { headerName, expectedValues } };
// When
var headers = new RequestHeaders(rawHeaders);
// Then
headers.AcceptCharset.ShouldBeSameAs(expectedValues);
}
示例6: Should_be_null_when_date_headers_are_invalid
public void Should_be_null_when_date_headers_are_invalid()
{
// Given
var expectedValues = new[] { "Bad Date Header" };
var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Date", expectedValues } };
// When
var headers = new RequestHeaders(rawHeaders);
// Then
headers.Date.ShouldBeNull();
}
示例7: Should_ignore_case_of_accept_encoding_header_name_when_retrieving_values
public void Should_ignore_case_of_accept_encoding_header_name_when_retrieving_values(string headerName)
{
// Given
var expectedValues = new[] { "compress", "sdch" };
var rawHeaders = new Dictionary<string, IEnumerable<string>> { { headerName, expectedValues } };
// When
var headers = new RequestHeaders(rawHeaders);
// Then
headers.AcceptEncoding.ShouldBeSameAs(expectedValues);
}
示例8: Should_ignore_case_of_accept_header_name_when_retrieving_values
public void Should_ignore_case_of_accept_header_name_when_retrieving_values(string headerName)
{
// Given
var expectedValues = new[] { "text/plain", "text/ninja" };
var rawHeaders = new Dictionary<string, IEnumerable<string>> { { headerName, expectedValues } };
// When
var headers = new RequestHeaders(rawHeaders);
// Then
headers.Accept.ShouldBeSameAs(expectedValues);
}
示例9: Should_header_values_when_available_using_indexer
public void Should_header_values_when_available_using_indexer()
{
// Given
var expectedValues = new[] { "fakeValue1", "fakeValue2" };
var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "some-header", expectedValues } };
var headers = new RequestHeaders(rawHeaders);
// When
var result = headers["some-header"];
// Then
result.ShouldBeSameAs(expectedValues);
}
示例10: Should_default_accept_language_header_values_to_quality_one_if_not_explicitly_defined
public void Should_default_accept_language_header_values_to_quality_one_if_not_explicitly_defined()
{
// Given
var values = new[] { "en-US" };
var rawHeaders = new Dictionary<string, IEnumerable<string>> { { "Accept-Language", values } };
// When
var headers = new RequestHeaders(rawHeaders).AcceptLanguage.ToList();
// Then
headers.Count.ShouldEqual(1);
headers[0].Item1.ShouldEqual("en-US");
headers[0].Item2.ShouldEqual(1m);
}
示例11: Should_allow_accept_authorization_to_be_overwritten
public void Should_allow_accept_authorization_to_be_overwritten()
{
// Given
var rawHeaders =
new Dictionary<string, IEnumerable<string>> { { "Authorization", new[] { "Basic 12345LDKJDFJDDSFDFvfdf==" } } };
var headers =
new RequestHeaders(rawHeaders) { Authorization = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" };
// When
var values = headers.Authorization;
// Then
values.ShouldEqual("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
}
示例12: PomonaRequest
public PomonaRequest(string url,
string relativePath,
HttpMethod method = HttpMethod.Get,
RequestHeaders headers = null,
Stream body = null,
DynamicDictionary query = null)
{
if (url == null)
throw new ArgumentNullException(nameof(url));
Method = method;
Url = url;
RelativePath = relativePath;
Body = body;
this.headers = headers;
Query = query ?? new DynamicDictionary();
}
示例13: Should_return_all_accept_headers_when_multiple_are_available
public void Should_return_all_accept_headers_when_multiple_are_available()
{
// Given
var rawHeaders =
new Dictionary<string, IEnumerable<string>>
{
{ "Accept", new[] { "text/plain", "text/ninja" } }
};
// When
var headers = new RequestHeaders(rawHeaders).Accept.ToList();
// Then
headers.ShouldHaveCount(2);
headers[0].Item1.ShouldEqual("text/plain");
headers[1].Item1.ShouldEqual("text/ninja");
}
示例14: Should_return_all_header_names_when_keys_are_retrieved
public void Should_return_all_header_names_when_keys_are_retrieved()
{
// Given
var rawHeaders =
new Dictionary<string, IEnumerable<string>>
{
{"accept", null},
{"charset", null}
};
var headers = new RequestHeaders(rawHeaders);
// When
var keys = headers.Keys.ToList();
// Then
keys.ShouldHaveCount(2);
keys.First().ShouldEqual("accept");
keys.Last().ShouldEqual("charset");
}
示例15: Should_allow_accept_encoding_headers_to_be_overwritten
public void Should_allow_accept_encoding_headers_to_be_overwritten()
{
// Given
var expectedValues = new[] {
"compress",
"gzip",
};
var rawHeaders =
new Dictionary<string, IEnumerable<string>> { { "Accept-Encoding", new[] { "sdch" } } };
var headers =
new RequestHeaders(rawHeaders) { AcceptEncoding = expectedValues };
// When
var values = headers.AcceptEncoding.ToList();
// Then
values[0].ShouldEqual("compress");
values[1].ShouldEqual("gzip");
}