public void SingleEncoding() { AcceptEncodingBuilder b = CreateBuilder(); b.Add(AcceptEncodingType.Gzip); Assert.Equal("gzip;q=1", b.Build()); }
private static async Task Main() { //Create a HttpClient using (HttpClient client = new HttpClient()) { //Create a builder to the accept-encoding header. We need this to construct which encodings we would like to accept in the response. AcceptEncodingBuilder acceptEncoding = new AcceptEncodingBuilder(); acceptEncoding.Add(AcceptEncodingType.Identity, 0.5f); acceptEncoding.Add(AcceptEncodingType.Compress, 0.1f); //Add the Accept-Encoding header to the HttpClient client.DefaultRequestHeaders.Add(acceptEncoding.HeaderName, acceptEncoding.Build()); //Now we create some options for the next header. These change the behavior of the builder. RangeOptions rangeOptions = new RangeOptions(); rangeOptions.DiscardInvalidRanges = true; rangeOptions.MergeOverlappingRanges = true; rangeOptions.ShortenRanges = true; rangeOptions.SortRanges = true; //Create a RangeBuilder with the options we just made RangeBuilder range = new RangeBuilder(Options.Create(rangeOptions)); range.Add(0, 10_000); range.Add(5, 100); //This range is overlapping, but that's okay since MergeOverlappingRanges is set to true. //We add the Range header to the HttpClient client.DefaultRequestHeaders.Add(range.HeaderName, range.Build()); //We send the request to a website that echo the headers back to us in the response. string echo = await client.GetStringAsync(new Uri("http://scooterlabs.com/echo")).ConfigureAwait(false); //The response is written to the console Console.WriteLine(echo); } }
public void OmitDefaultWeight() { AcceptEncodingBuilder b = CreateBuilder(); b.Add(AcceptEncodingType.Gzip); b.Add(AcceptEncodingType.Deflate); Assert.Equal("gzip;q=1, deflate;q=1", b.Build()); b.Options.Value.OmitDefaultWeight = true; Assert.Equal("gzip, deflate", b.Build()); }
public void EncodingsWithWeight() { AcceptEncodingBuilder b = CreateBuilder(); b.Add(AcceptEncodingType.Gzip, 0.1f); b.Add(AcceptEncodingType.Deflate, 0.2f); Assert.Equal("gzip;q=0.1, deflate;q=0.2", b.Build()); b.Reset(); Assert.Null(b.Build()); }