Esempio n. 1
0
        /// <summary>
        /// Sets the WebRequest headers
        /// </summary>
        /// <param name="webReq">HttpWebRequest</param>
        /// <param name="client">AdlsClient</param>
        /// <param name="req">RequestOptions</param>
        /// <param name="token">Auth token</param>
        /// <param name="opMethod">Operation method (e.g. POST/GET)</param>
        /// <param name="customHeaders">Custom headers</param>
        private static void AssignCommonHttpHeaders(HttpWebRequest webReq, AdlsClient client, RequestOptions req, string token, string opMethod, IDictionary <string, string> customHeaders, int postRequestLength)
        {
            webReq.Headers["Authorization"] = token;
            string latencyHeader = LatencyTracker.GetLatency();

            if (!string.IsNullOrEmpty(latencyHeader))
            {
                webReq.Headers["x-ms-adl-client-latency"] = latencyHeader;
            }

            if (client.ContentEncoding != null && postRequestLength > MinDataSizeForCompression)
            {
                webReq.Headers["Content-Encoding"] = client.ContentEncoding;
            }

            if (client.DipIp != null && !req.IgnoreDip)
            {
#if NET452
                webReq.Host = client.AccountFQDN;
#else
                webReq.Headers["Host"] = client.AccountFQDN;
#endif
            }

            if (!req.KeepAlive)
            {
                /*
                 * Connection cant be set directly as a header in net452.
                 * KeepAlive needs to be set as a property in HttpWebRequest when we want to close connection.
                 */
#if NET452
                webReq.KeepAlive = false;
#else
                webReq.Headers["Connection"] = "Close";
#endif
            }

            if (customHeaders != null)
            {
                string contentType;
                if (customHeaders.TryGetValue("Content-Type", out contentType))
                {
                    webReq.ContentType = contentType;
                    customHeaders.Remove("Content-Type");
                }
                foreach (var key in customHeaders.Keys)
                {
                    webReq.Headers[key] = customHeaders[key];
                }
            }
#if NET452
            webReq.UserAgent = client.GetUserAgent();
            webReq.ServicePoint.UseNagleAlgorithm = false;
            webReq.ServicePoint.Expect100Continue = false;
#else
            webReq.Headers["User-Agent"] = client.GetUserAgent();
#endif
            webReq.Headers["x-ms-client-request-id"] = req.RequestId;
            webReq.Method = opMethod;
        }
        /// <summary>
        /// Sets the WebRequest headers
        /// </summary>
        /// <param name="webReq">HttpWebRequest</param>
        /// <param name="client">AdlsClient</param>
        /// <param name="req">RequestOptions</param>
        /// <param name="token">Auth token</param>
        /// <param name="opMethod">Operation method (e.g. POST/GET)</param>
        /// <param name="customHeaders">Custom headers</param>
        private static void AssignCommonHttpHeaders(HttpWebRequest webReq, AdlsClient client, RequestOptions req, string token, string opMethod, IDictionary <string, string> customHeaders)
        {
            webReq.Headers["Authorization"] = token;
            string latencyHeader = LatencyTracker.GetLatency();

            if (!string.IsNullOrEmpty(latencyHeader))
            {
                webReq.Headers["x-ms-adl-client-latency"] = latencyHeader;
            }

            if (client.DipIp != null && !req.IgnoreDip)
            {
#if NET452
                webReq.Host = client.AccountFQDN;
#else
                webReq.Headers["Host"] = client.AccountFQDN;
#endif
            }

            if (!req.KeepAlive)
            {
                /*
                 * Connection cant be set directly as a header in net452.
                 * KeepAlive needs to be set as a property in HttpWebRequest when we want to close connection.
                 */
#if NET452
                webReq.KeepAlive = false;
#else
                webReq.Headers["Connection"] = "Close";
#endif
            }
            if (customHeaders != null)
            {
                foreach (var key in customHeaders.Keys)
                {
                    webReq.Headers[key] = customHeaders[key];
                }
            }
#if NETSTANDARD2_0 || NET452
            webReq.UserAgent = client.GetUserAgent();
#else
            webReq.Headers["User-Agent"] = client.GetUserAgent();
#endif
#if NET452
            //Setting timeout is only available in NET452
            webReq.ReadWriteTimeout = (int)req.TimeOut.TotalMilliseconds;
            webReq.Timeout          = (int)req.TimeOut.TotalMilliseconds;
            webReq.ServicePoint.UseNagleAlgorithm = false;
            webReq.ServicePoint.Expect100Continue = false;
#endif
            webReq.Headers["x-ms-client-request-id"] = req.RequestId;
            webReq.Method = opMethod;
        }
Esempio n. 3
0
        /// <summary>
        /// Sets the WebRequest headers
        /// </summary>
        /// <param name="webReq">HttpWebRequest</param>
        /// <param name="client">AdlsClient</param>
        /// <param name="req">RequestOptions</param>
        /// <param name="token">Auth token</param>
        /// <param name="opMethod">Operation method (e.g. POST/GET)</param>
        private static void AssignCommonHttpHeaders(HttpWebRequest webReq, AdlsClient client, RequestOptions req, string token, string opMethod)
        {
            webReq.Headers["Authorization"] = token;
            string latencyHeader = LatencyTracker.GetLatency();

            if (!string.IsNullOrEmpty(latencyHeader))
            {
                webReq.Headers["x-ms-adl-client-latency"] = latencyHeader;
            }
#if NET452
            webReq.UserAgent = client.GetUserAgent();
            //Setting timeout is only available in NET452
            webReq.ReadWriteTimeout = (int)req.TimeOut.TotalMilliseconds;
            webReq.Timeout          = (int)req.TimeOut.TotalMilliseconds;
            webReq.ServicePoint.UseNagleAlgorithm = false;
            webReq.ServicePoint.Expect100Continue = false;
#else
            webReq.Headers["User-Agent"] = client.GetUserAgent();
#endif
            webReq.Headers["x-ms-client-request-id"] = req.RequestId;
            webReq.Method = opMethod;
        }