CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
HttpCompressionProxy.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="HttpCompressionProxy.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Implements a data portal proxy to relay data portal</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Net;
10using System.Net.Http;
11
13{
19 {
26 public HttpCompressionProxy(ApplicationContext applicationContext, HttpClient httpClient, HttpProxyOptions options)
27 : base(applicationContext, httpClient, options)
28 { }
29
34 protected override HttpClientHandler GetHttpClientHandler()
35 {
36 var result = new HttpClientHandler();
38 result.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
39 return result;
40 }
41
47 protected override void SetHttpRequestHeaders(HttpRequestMessage request)
48 {
49 request.Headers.Add("Accept", "*/*");
50 request.Headers.Add("Accept-Encoding", "gzip,deflate,*");
51 }
52
57 protected override WebClient GetWebClient()
58 {
59 var client = new CompressionWebClient(Timeout);
60 client.Headers.Set("Accept", "*/*");
61 client.Headers.Set("Accept-Encoding", "gzip,deflate,*");
62 return client;
63 }
64
65#pragma warning disable SYSLIB0014
66 private class CompressionWebClient : WebClient
67 {
68 private int Timeout { get; set; }
69
70 public CompressionWebClient(int timeout) => Timeout = timeout;
71
72 protected override WebRequest GetWebRequest(Uri address)
73 {
74 var req = base.GetWebRequest(address) as HttpWebRequest;
75 req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
76 if (Timeout > 0)
77 req.Timeout = Timeout;
78 return req;
79 }
80 }
81#pragma warning restore SYSLIB0014
82 }
83}
Provides consistent context information between the client and server DataPortal objects.
Implements a data portal proxy to relay data portal calls to a remote application server by using htt...
override HttpClientHandler GetHttpClientHandler()
Gets an HttpClientHandler for use in initializing the HttpClient instance.
HttpCompressionProxy(ApplicationContext applicationContext, HttpClient httpClient, HttpProxyOptions options)
Creates an instance of the type.
override void SetHttpRequestHeaders(HttpRequestMessage request)
Override to set headers or other properties of the HttpRequestMessage before it is sent to the server...
override WebClient GetWebClient()
Gets an WebClient object for use in communication with the server.
Implements a data portal proxy to relay data portal calls to a remote application server by using htt...
Definition: HttpProxy.cs:23
static bool UseTextSerialization
Gets or sets a value indicating whether to use text/string serialization instead of the default binar...
Definition: HttpProxy.cs:93
virtual int Timeout
Gets or sets the Client timeout in milliseconds (0 uses default timeout).