Skip to content

AuthorityRequestCondition

Troy Willmot edited this page Sep 25, 2016 · 2 revisions

AuthorityRequestCondition

Summary

The AuthorityRequestCondition is an implementation of the IRequestCondition interface. It allows processing only requests where the authority part of the request URI matches a specific value.

Samples

This sample uses the AuthorityRequestCondition with the Compressed Requests Handler so only requests to www.mydomain.com are compressed. Requests to any other authority are not compressed.

// Create the condition object
var authorityCondition = new AuthorityRequestCondition();
authorityCondition.AddAuthority("www.mydomain.com");

// Construct the compressed request handler with the condition object attached.
var handler = new CompressedRequestHandler(mh, authorityCondition);
var client = new System.Net.Http.HttpClient(handler);

// Now send a request that will be compressed because the request 
// authority matches the condition.
var uncompressedContent = "A compressible string. A compressible string. A compressible string. A compressible string.";
var result = await client.PostAsync("http://www.mydomain.com/SomeEndPoint", 
    new System.Net.Http.StringContent(uncompressedContent)
).ConfigureAwait(false);

// Now send a request that will NOT be compressed because the request 
// authority doesn't match the condition.
var result = await client.PostAsync("http://www.someotherdomain.com/SomeEndPoint", 
    new System.Net.Http.StringContent(uncompressedContent)
).ConfigureAwait(false);