public UpdateHeaders ( |
||
webRequest | ||
return | void |
internal HttpJsonRequest( CreateHttpJsonRequestParams requestParams, HttpJsonRequestFactory factory) { Url = requestParams.Url; this.factory = factory; owner = requestParams.Owner; conventions = requestParams.Convention; Method = requestParams.Method; webRequest = (HttpWebRequest)WebRequest.Create(requestParams.Url); webRequest.UseDefaultCredentials = true; webRequest.Credentials = requestParams.Credentials; webRequest.Method = requestParams.Method; if (factory.DisableRequestCompression == false && requestParams.DisableRequestCompression == false) { if (requestParams.Method == "POST" || requestParams.Method == "PUT" || requestParams.Method == "PATCH" || requestParams.Method == "EVAL") { webRequest.Headers["Content-Encoding"] = "gzip"; } webRequest.Headers["Accept-Encoding"] = "gzip"; } webRequest.ContentType = "application/json; charset=utf-8"; webRequest.Headers.Add("Raven-Client-Version", ClientVersion); WriteMetadata(requestParams.Metadata); requestParams.UpdateHeaders(webRequest); }
internal HttpJsonRequest( CreateHttpJsonRequestParams requestParams, HttpJsonRequestFactory factory) { _credentials = requestParams.Credentials; Url = requestParams.Url; Method = requestParams.Method; this.factory = factory; owner = requestParams.Owner; conventions = requestParams.Convention; if (factory.httpMessageHandler != null) { handler = factory.httpMessageHandler; recreateHandler = () => factory.httpMessageHandler; } else { var webRequestHandler = new WebRequestHandler { UseDefaultCredentials = _credentials.HasCredentials() == false, Credentials = requestParams.Credentials.Credentials, }; recreateHandler = () => new WebRequestHandler { Credentials = webRequestHandler.Credentials }; disableAuthentication = () => { webRequestHandler.Credentials = null; webRequestHandler.UseDefaultCredentials = false; }; handler = webRequestHandler; } httpClient = new HttpClient(handler); if (factory.DisableRequestCompression == false && requestParams.DisableRequestCompression == false) { if (Method == "POST" || Method == "PUT" || Method == "PATCH" || Method == "EVAL") { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Encoding", "gzip"); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8"); } httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); } #if DEBUG if (Debugger.IsAttached) { Timeout = TimeSpan.FromMinutes(5); } #endif headers.Add("Raven-Client-Version", ClientVersion); WriteMetadata(requestParams.Metadata); requestParams.UpdateHeaders(headers); }
internal HttpJsonRequest( CreateHttpJsonRequestParams requestParams, HttpJsonRequestFactory factory) { Url = requestParams.Url; this.factory = factory; owner = requestParams.Owner; conventions = requestParams.Convention; Method = requestParams.Method; webRequest = (HttpWebRequest)WebRequest.Create(requestParams.Url); webRequest.UseDefaultCredentials = true; webRequest.Credentials = requestParams.Credentials; webRequest.Method = requestParams.Method; if (factory.DisableRequestCompression == false) { if(requestParams.Method == "POST" || requestParams.Method == "PUT" || requestParams.Method == "PATCH" || requestParams.Method == "EVAL") webRequest.Headers["Content-Encoding"] = "gzip"; webRequest.Headers["Accept-Encoding"] = "gzip"; } webRequest.ContentType = "application/json; charset=utf-8"; webRequest.Headers.Add("Raven-Client-Version", ClientVersion); WriteMetadata(requestParams.Metadata); requestParams.UpdateHeaders(webRequest); }
internal HttpJsonRequest( CreateHttpJsonRequestParams requestParams, HttpJsonRequestFactory factory) { Url = requestParams.Url; this.factory = factory; owner = requestParams.Owner; conventions = requestParams.Convention; Method = requestParams.Method; webRequest = (HttpWebRequest)WebRequest.Create(requestParams.Url); webRequest.Credentials = requestParams.Credentials; webRequest.Method = requestParams.Method; if (factory.DisableRequestCompression == false && (requestParams.Method == "POST" || requestParams.Method == "PUT" || requestParams.Method == "PATCH")) { webRequest.Headers["Content-Encoding"] = "gzip"; } webRequest.ContentType = "application/json; charset=utf-8"; WriteMetadata(requestParams.Metadata); requestParams.UpdateHeaders(webRequest); }
internal HttpJsonRequest( CreateHttpJsonRequestParams requestParams, HttpJsonRequestFactory factory) { try { _credentials = requestParams.DisableAuthentication == false ? requestParams.Credentials : null; disabledAuthRetries = requestParams.DisableAuthentication; Url = requestParams.Url; Method = requestParams.Method; if (requestParams.Timeout.HasValue) { Timeout = requestParams.Timeout.Value; } else { Timeout = TimeSpan.FromSeconds(100); // default HttpClient timeout #if DEBUG if (Debugger.IsAttached) { Timeout = TimeSpan.FromMinutes(5); } #endif } this.factory = factory; owner = requestParams.Owner; conventions = requestParams.Convention; if (factory.httpMessageHandler != null) { recreateHandler = () => factory.httpMessageHandler; } else { recreateHandler = () => new WebRequestHandler { UseDefaultCredentials = _credentials != null && _credentials.HasCredentials() == false, Credentials = _credentials != null ? _credentials.Credentials : null, }; } httpClient = factory.httpClientCache.GetClient(Timeout, _credentials, recreateHandler); if (factory.DisableRequestCompression == false && requestParams.DisableRequestCompression == false) { if (Method == "POST" || Method == "PUT" || Method == "PATCH" || Method == "EVAL") { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Encoding", "gzip"); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8"); } httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); } headers.Add("Raven-Client-Version", ClientVersion); WriteMetadata(requestParams.Metadata); requestParams.UpdateHeaders(headers); } catch (Exception) { throw; } }