本文整理汇总了C#中HttpHeaders类的典型用法代码示例。如果您正苦于以下问题:C# HttpHeaders类的具体用法?C# HttpHeaders怎么用?C# HttpHeaders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpHeaders类属于命名空间,在下文中一共展示了HttpHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestHeadersInOrder
public static void TestHeadersInOrder()
{
string[] c1 = { "E2E4" };
string h_c1 = "Connection: E2E4\r\n";
string[] c2 = { "E7E5" };
string h_c2 = "Connection: E7E5\r\n";
string host = "chez.moi";
string h_host = "Host: " + host + "\r\n";
int ContentLength = 1951;
string h_cl = "Content-Length: 1951\r\n";
var hh = new HttpHeaders();
hh.Connection = c1;
Assert.AreEqual(h_c1, hh.HeadersInOrder);
hh.Host = host;
Assert.AreEqual(h_c1 + h_host, hh.HeadersInOrder);
hh.Connection = c2;
Assert.AreEqual(h_c2 + h_host, hh.HeadersInOrder);
hh.Connection = null;
Assert.AreEqual(h_host, hh.HeadersInOrder);
hh.ContentLength = (uint?) ContentLength;
Assert.AreEqual(h_host + h_cl, hh.HeadersInOrder);
hh.ContentLength = null;
Assert.AreEqual(h_host, hh.HeadersInOrder);
hh.Host = null;
Assert.IsTrue(String.IsNullOrEmpty(hh.HeadersInOrder));
}
示例2: ConvertToHeaders
protected Dictionary<string, string> ConvertToHeaders(string name, HttpHeaders headers)
{
var result = headers.ToDictionary(x => x.Key, x => x.Value.FirstOrDefault());
result.Add("Host", GetHost(name));
return result;
}
示例3: ServerSniffer
public async Task<IActionResult> ServerSniffer(string uri)
{
var request_headers = new Dictionary<string, string>();
var response_headers = new Dictionary<string, string>();
var http_headers = new HttpHeaders();
http_headers.RequestHeaders = request_headers;
http_headers.ResponseHeaders = response_headers;
using (var http_client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Head, uri);
using (var response = await http_client.SendAsync(request))
{
foreach (var header in response.Headers)
{
response_headers.Add(header.Key, string.Join(",", header.Value));
}
foreach (var header in request.Headers)
{
request_headers.Add(header.Key, string.Join(",", header.Value));
}
}
}
var json_result = new JsonResult(http_headers);
return json_result;
}
示例4: TestMultilineParse
public void TestMultilineParse()
{
//
// multiline values are acceptable if the next
// line starts with spaces
//
string header = @"HeaderName: Some multiline
value";
HttpHeaders headers = new HttpHeaders ();
headers.Parse (new StringReader (header));
Assert.AreEqual ("Some multiline value", headers ["HeaderName"], "a1");
header = @"HeaderName: Some multiline
value
that spans
a bunch of lines";
headers = new HttpHeaders ();
headers.Parse (new StringReader (header));
Assert.AreEqual ("Some multiline value that spans a bunch of lines", headers ["HeaderName"], "a2");
}
示例5: AuthorizeUser
private static async Task<bool> AuthorizeUser(HttpHeaders headers)
{
HttpContext.Current.User = await GetClaimsForRoleAsync(headers)
.ConfigureAwait(continueOnCapturedContext: false);
return HttpContext.Current.User.Identity.IsAuthenticated;
}
示例6: PopulateHeaders
public static void PopulateHeaders(this HttpPacket packet, HttpContentHeaders contentHeaders, HttpHeaders generalHeaders)
{
if (packet == null) throw new ArgumentNullException("packet");
string hdrKey;
foreach (var hdr in packet.Headers)
{
if (hdr.Key == null) continue;
hdrKey = hdr.Key.Trim().ToUpperInvariant();
if (hdrKey == "CONTENT-LENGTH") continue; //Content Length is automaitically calculated
if (Array.IndexOf<String>(contentOnlyHeaders, hdrKey) >= 0)
{
//TODO: Confirm if HttpResponseMessage/HttpRequestMessage will break headers into "," commas whereas in actuality header in Packet is an entire header
contentHeaders.Add(hdr.Key.Trim(), hdr.Value);
}
else
{
generalHeaders.Add(hdr.Key.Trim(), hdr.Value);
}
//TODO: Check if a string can be parsed properly into the typed header
//Test adding multiple headers of the same name will do. // Look up the Add overload that takes an ienumerable<string> to figure out its purpose.
}
}
示例7: GetClaimsForRoleAsync
private static async Task<ClaimsPrincipal> GetClaimsForRoleAsync(HttpHeaders role)
{
return await Task.Run(() => new ClaimsPrincipal(new List<ClaimsIdentity>
{
new ClaimsIdentity("SecureAuth", "SafeType", role.GetValues("RoleType").FirstOrDefault())
}));
}
示例8: DummyProxy
public DummyProxy(string fakeEncoding)
: base(new HttpSocket(new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp)))
{
ResponseHeaders = new HttpHeaders();
ResponseHeaders.ContentEncoding = fakeEncoding;
}
示例9: RequestHeaderMap
public RequestHeaderMap(HttpHeaders headers)
{
this.headersCollection = headers.ToDictionary(
x => x.Key.ToLower().Replace("-", string.Empty),
x => string.Join(",", x.Value)
);
}
示例10: DefaultHttpRequest
// Copy constructor
public DefaultHttpRequest(IHttpRequest existingRequest, Uri overrideUri = null)
{
this.body = existingRequest.Body;
this.bodyContentType = existingRequest.BodyContentType;
this.headers = new HttpHeaders(existingRequest.Headers);
this.method = existingRequest.Method.Clone();
this.canonicalUri = new CanonicalUri(existingRequest.CanonicalUri, overrideResourcePath: overrideUri);
}
示例11: GetHttpRequestHeader
private static string GetHttpRequestHeader(HttpHeaders headers, string headerName)
{
if (!headers.Contains(headerName))
return string.Empty;
return headers.GetValues(headerName)
.SingleOrDefault();
}
示例12: Getting_nonexistent_header_returns_default
public void Getting_nonexistent_header_returns_default()
{
var headers = new HttpHeaders();
var nonexistent = headers.GetFirst<string>("nope");
nonexistent.ShouldBeNull();
}
示例13: Adding_nonstandard_header_name_is_ok
public void Adding_nonstandard_header_name_is_ok()
{
var headers = new HttpHeaders();
headers.Add("FOOBAR", "123");
headers.GetFirst<string>("FOOBAR").ShouldBe("123");
}
示例14: WebClientHttpResponse
/// <summary>
/// Creates a new instance of <see cref="WebClientHttpResponse"/>
/// with the given <see cref="HttpWebResponse"/> instance.
/// </summary>
/// <param name="response">The <see cref="HttpWebResponse"/> instance to use.</param>
public WebClientHttpResponse(HttpWebResponse response)
{
ArgumentUtils.AssertNotNull(response, "response");
this.httpWebResponse = response;
this.headers = new HttpHeaders();
this.Initialize();
}
示例15: DefaultResourceDataRequest
public DefaultResourceDataRequest(ResourceAction action, Type resourceType, CanonicalUri uri, HttpHeaders requestHeaders, Map properties, bool skipCache)
{
this.action = action;
this.uri = uri;
this.requestHeaders = requestHeaders;
this.resourceType = resourceType;
this.properties = properties;
this.skipCache = skipCache;
}