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 static async Task <RavenJObject> GetMetadataForAsyncImpl(IHoldProfilingInformation self, HttpJsonRequestFactory requestFactory, FilesConvention conventions, NameValueCollection operationsHeaders, string filename, string baseUrl, OperationCredentials credentials) { using (var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(self, baseUrl + "/files?name=" + Uri.EscapeDataString(filename), "HEAD", credentials, conventions)).AddOperationHeaders(operationsHeaders)) { try { await request.ExecuteRequestAsync().ConfigureAwait(false); var response = request.Response; var metadata = response.HeadersToObject(); metadata[Constants.MetadataEtagField] = metadata[Constants.MetadataEtagField].Value <string>().Trim('\"'); return(metadata); } catch (Exception e) { try { throw e.SimplifyException(); } catch (FileNotFoundException) { return(null); } } } }
internal static async Task<RavenJObject> GetMetadataForAsyncImpl(IHoldProfilingInformation self, HttpJsonRequestFactory requestFactory, FilesConvention conventions, NameValueCollection operationsHeaders, string filename, string baseUrl, OperationCredentials credentials) { using (var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(self, baseUrl + "/files?name=" + Uri.EscapeDataString(filename), "HEAD", credentials, conventions)).AddOperationHeaders(operationsHeaders)) { try { await request.ExecuteRequestAsync().ConfigureAwait(false); var response = request.Response; var metadata = response.HeadersToObject(); metadata[Constants.MetadataEtagField] = metadata[Constants.MetadataEtagField].Value<string>().Trim('\"'); return metadata; } catch (Exception e) { try { throw e.SimplifyException(); } catch (FileNotFoundException) { return null; } } } }
public SingleAuthTokenRetriever(IHoldProfilingInformation profilingInfo, ConventionBase convention, NameValueCollection operationHeaders, OperationMetadata operationMetadata) { this.profilingInfo = profilingInfo; this.convention = convention; this.operationHeaders = operationHeaders; this.operationMetadata = operationMetadata; }
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 && 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 static async Task<Stream> DownloadAsyncImpl(IHoldProfilingInformation self, HttpJsonRequestFactory requestFactory, FilesConvention conventions, NameValueCollection operationsHeaders, string path, string filename, Reference<RavenJObject> metadataRef, long? @from, long? to, string baseUrl, OperationCredentials credentials) { var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(self, baseUrl + path + Uri.EscapeDataString(filename), "GET", credentials, conventions)).AddOperationHeaders(operationsHeaders); if (@from != null) { if (to != null) request.AddRange(@from.Value, to.Value); else request.AddRange(@from.Value); } try { var response = await request.ExecuteRawResponseAsync().ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.NotFound) throw new FileNotFoundException("The file requested does not exists on the file system.", baseUrl + path + filename); await response.AssertNotFailingResponse().ConfigureAwait(false); if (metadataRef != null) metadataRef.Value = response.HeadersToObject(); return new DisposableStream(await response.GetResponseStreamWithHttpDecompression().ConfigureAwait(false), request.Dispose); } catch (Exception e) { throw e.SimplifyException(); } }
public MultiGetOperation( IHoldProfilingInformation holdProfilingInformation, DocumentConvention convention, string url, GetRequest[] requests) { this.holdProfilingInformation = holdProfilingInformation; this.convention = convention; this.url = url; this.requests = requests; requestUri = url + "/multi_get"; if (convention.UseParallelMultiGet) { requestUri += "?parallel=yes"; } var absoluteUri = new Uri(url).AbsolutePath; foreach (var request in requests) { request.Url = absoluteUri + request.Url; if (request.Query.StartsWith("?") == false) { request.Query = "?" + request.Query; } } }
public SingleAuthTokenRetriever(IHoldProfilingInformation profilingInfo, HttpJsonRequestFactory factory, Convention convention, NameValueCollection operationHeaders, OperationMetadata operationMetadata) { this.profilingInfo = profilingInfo; this.factory = factory; this.convention = convention; this.operationHeaders = operationHeaders; this.operationMetadata = operationMetadata; }
internal HttpJsonRequest( CreateHttpJsonRequestParams requestParams, HttpJsonRequestFactory factory) { _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; recreateHandler = factory.httpMessageHandler ?? ( () => 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"); } if (factory.acceptGzipContent) { httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); } } headers.Add("Raven-Client-Version", ClientVersion); WriteMetadata(requestParams.Metadata); requestParams.UpdateHeaders(headers); }
/// <summary> /// Invoke the LogRequest event /// </summary> internal void InvokeLogRequest(IHoldProfilingInformation sender, Func <RequestResultArgs> generateRequestResult) { var handler = LogRequest; if (handler != null) { handler(sender, generateRequestResult()); } }
/// <summary> /// Invoke the LogRequest event /// </summary> internal void InvokeLogRequest(IHoldProfilingInformation sender, RequestResultArgs e) { var handler = LogRequest; if (handler != null) { handler(sender, e); } }
/// <summary> /// Invoke the LogRequest event /// </summary> internal void OnLogRequest(IHoldProfilingInformation sender, RequestResultArgs args) { var handler = LogRequest; if (handler != null) { handler(sender, args); } }
public CreateHttpJsonRequestParams(IHoldProfilingInformation self, string url, string method, RavenJObject metadata, ICredentials credentials, DocumentConvention convention) { Owner = self; Url = url; Method = method; Metadata = metadata; Credentials = credentials; Convention = convention; operationsHeadersColletion = new NameValueCollection(); }
public CreateHttpJsonRequestParams(IHoldProfilingInformation self, string url, string method, RavenJObject metadata, OperationCredentials credentials, Convention convention, TimeSpan?timeout = null) { Owner = self; Url = url; Method = method; Metadata = metadata; Credentials = credentials; Convention = convention; Timeout = timeout; operationsHeadersCollection = new NameValueCollection(); }
public CreateHttpJsonRequestParams(IHoldProfilingInformation self, string url, string method, RavenJObject metadata, OperationCredentials credentials, Convention convention, TimeSpan? timeout = null) { Owner = self; Url = url; Method = method; Metadata = metadata; Credentials = credentials; Convention = convention; Timeout = timeout; operationsHeadersCollection = new NameValueCollection(); }
public CreateHttpJsonRequestParams(IHoldProfilingInformation self, string url, HttpMethod method, OperationCredentials credentials, ConventionBase convention, IRequestTimeMetric requestTimeMetric = null, TimeSpan?timeout = null, long?etag = null) { Etag = etag; Owner = self; Url = url; Method = method; Credentials = credentials; Convention = convention; RequestTimeMetric = requestTimeMetric; Timeout = timeout; operationsHeadersCollection = new NameValueCollection(); ShouldCacheRequest = convention != null ? convention.ShouldCacheRequest : urlParam => false; }
internal HttpJsonRequest(string url, string method, RavenJObject metadata, ICredentials credentials, HttpJsonRequestFactory factory, IHoldProfilingInformation owner) { this.Url = url; this.factory = factory; this.owner = owner; this.Method = method; webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Credentials = credentials; WriteMetadata(metadata); webRequest.Method = method; webRequest.Headers["Accept-Encoding"] = "deflate,gzip"; webRequest.ContentType = "application/json; charset=utf-8"; }
public MultiGetOperation( IHoldProfilingInformation holdProfilingInformation, DocumentConvention convention, string url, GetRequest[] requests) { this.holdProfilingInformation = holdProfilingInformation; this.convention = convention; this.url = url; this.requests = requests; requestUri = url + "/multi_get"; if (convention.UseParallelMultiGet) { requestUri += "?parallel=yes"; } }
internal static async Task <Stream> DownloadAsyncImpl(IHoldProfilingInformation self, HttpJsonRequestFactory requestFactory, FilesConvention conventions, NameValueCollection operationsHeaders, string path, string filename, Reference <RavenJObject> metadataRef, long? @from, long?to, string baseUrl, OperationCredentials credentials) { var request = requestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(self, baseUrl + path + Uri.EscapeDataString(filename), HttpMethod.Get, credentials, conventions)).AddOperationHeaders(operationsHeaders); if (@from != null) { if (to != null) { request.AddRange(@from.Value, to.Value); } else { request.AddRange(@from.Value); } } try { var response = await request.ExecuteRawResponseAsync().ConfigureAwait(false); if (response.StatusCode == HttpStatusCode.NotFound) { throw new FileNotFoundException("The file requested does not exists on the file system.", baseUrl + path + filename); } await response.AssertNotFailingResponse().ConfigureAwait(false); if (metadataRef != null) { metadataRef.Value = response.HeadersToObject(); } return(new DisposableStream(await response.GetResponseStreamWithHttpDecompression().ConfigureAwait(false), () => { request.Dispose(); response.Content.Dispose(); response.Dispose(); })); } catch (Exception e) { throw e.SimplifyException(); } }
internal HttpJsonRequest( string url, string method, RavenJObject metadata, ICredentials credentials, HttpJsonRequestFactory factory, IHoldProfilingInformation owner, DocumentConvention conventions) { this.Url = url; this.factory = factory; this.owner = owner; this.conventions = conventions; this.Method = method; webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Credentials = credentials; WriteMetadata(metadata); webRequest.Method = method; webRequest.Headers["Accept-Encoding"] = "deflate,gzip"; webRequest.ContentType = "application/json; charset=utf-8"; }
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( string url, string method, RavenJObject metadata, ICredentials credentials, HttpJsonRequestFactory factory, IHoldProfilingInformation owner, DocumentConvention conventions) { this.Url = url; this.factory = factory; this.owner = owner; this.conventions = conventions; this.Method = method; webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Credentials = credentials; webRequest.Method = method; if (method == "POST" || method == "PUT" || method == "PATCH") webRequest.Headers["Content-Encoding"] = "gzip"; webRequest.ContentType = "application/json; charset=utf-8"; WriteMetadata(metadata); }
/// <summary> /// Creates the HTTP json request. /// </summary> public HttpJsonRequest CreateHttpJsonRequest(IHoldProfilingInformation self, string url, string method, RavenJObject metadata, ICredentials credentials, DocumentConvention convention) { if (disposed) { throw new ObjectDisposedException(typeof(HttpJsonRequestFactory).FullName); } var request = new HttpJsonRequest(url, method, metadata, credentials, this, self, convention) { ShouldCacheRequest = convention.ShouldCacheRequest(url) }; if (request.ShouldCacheRequest && method == "GET" && !DisableHttpCaching) { var cachedRequestDetails = ConfigureCaching(url, request.webRequest.Headers.Set); request.CachedRequestDetails = cachedRequestDetails.CachedRequest; request.SkipServerCheck = cachedRequestDetails.SkipServerCheck; } ConfigureRequest(self, new WebRequestEventArgs { Request = request.webRequest }); return(request); }
/// <summary> /// Invoke the LogRequest event /// </summary> internal void OnLogRequest(IHoldProfilingInformation sender, RequestResultArgs args) { var handler = LogRequest; if (handler != null) handler(sender, args); }
/// <summary> /// Invoke the LogRequest event /// </summary> internal void InvokeLogRequest(IHoldProfilingInformation sender, Func<RequestResultArgs> generateRequestResult) { var handler = LogRequest; if (handler != null) handler(sender, generateRequestResult()); }
internal HttpJsonRequest( CreateHttpJsonRequestParams requestParams, HttpJsonRequestFactory factory) { _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; recreateHandler = factory.httpMessageHandler ?? ( () => { var useDefaultCredentials = _credentials != null && _credentials.HasCredentials() == false; ICredentials credentialsToUse = null; if (_credentials != null) { var networkCredentials = _credentials.Credentials as NetworkCredential; if (networkCredentials != null && factory.authenticationScheme != null) { var credentialCache = new CredentialCache(); var uri = new Uri(requestParams.Url); credentialCache.Add(new Uri(string.Format("{0}://{1}:{2}/", uri.Scheme, uri.Host, uri.Port)), factory.authenticationScheme, networkCredentials); credentialsToUse = credentialCache; } else { credentialsToUse = _credentials.Credentials; } } #if !DNXCORE50 var handler = new WebRequestHandler { UseDefaultCredentials = useDefaultCredentials, Credentials = credentialsToUse }; #else var handler = new WinHttpHandler { ServerCredentials = useDefaultCredentials ? CredentialCache.DefaultCredentials : credentialsToUse }; #endif return(handler); } ); 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"); } if (factory.acceptGzipContent) { httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); } } headers.Add("Raven-Client-Version", ClientVersion); WriteMetadata(requestParams.Metadata); requestParams.UpdateHeaders(headers); }
/// <summary> /// Creates the HTTP json request. /// </summary> public HttpJsonRequest CreateHttpJsonRequest(IHoldProfilingInformation self, string url, string method, ICredentials credentials, DocumentConvention convention) { return(CreateHttpJsonRequest(self, url, method, new RavenJObject(), credentials, convention)); }
public CreateHttpJsonRequestParams(IHoldProfilingInformation self, string url, string method, ICredentials credentials, DocumentConvention convention) : this(self, url, method, new RavenJObject(), credentials, convention) { }
public CreateHttpJsonRequestParams(IHoldProfilingInformation self, string url, string method, OperationCredentials credentials, Convention convention, TimeSpan?timeout = null) : this(self, url, method, new RavenJObject(), credentials, convention, timeout) { }
internal HttpJsonRequest( CreateHttpJsonRequestParams requestParams, HttpJsonRequestFactory factory) { _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 = DefaultHttpClientTimeout; #if DEBUG if (Debugger.IsAttached) { Timeout = TimeSpan.FromMinutes(5); } #endif } this.factory = factory; owner = requestParams.Owner; conventions = requestParams.Convention; requestTimeMetric = requestParams.RequestTimeMetric; recreateHandler = factory.httpMessageHandler ?? ( () => { var useDefaultCredentials = _credentials != null && _credentials.HasCredentials() == false; ICredentials credentialsToUse = null; if (_credentials != null) { var networkCredentials = _credentials.Credentials as NetworkCredential; if (networkCredentials != null && factory.authenticationScheme != null) { var credentialCache = new CredentialCache(); var uri = new Uri(requestParams.Url); credentialCache.Add(new Uri(string.Format("{0}://{1}:{2}/", uri.Scheme, uri.Host, uri.Port)), factory.authenticationScheme, networkCredentials); credentialsToUse = credentialCache; } else { credentialsToUse = _credentials.Credentials; } } var handler = new HttpClientHandler { }; return(handler); } ); httpClient = factory.httpClientCache.GetClient(Timeout, _credentials, recreateHandler); var isNotGet = Method == HttpMethods.Post || Method == HttpMethods.Put || Method == HttpMethods.Patch || Method == HttpMethods.Eval; if (factory.DisableRequestCompression == false && requestParams.DisableRequestCompression == false) { if (isNotGet) { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Encoding", "gzip"); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8"); } if (factory.acceptGzipContent) { httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); } } if (requestParams.Etag.HasValue) { var etag = requestParams.Etag.Value.ToString(); if (isNotGet) { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("If-Match", etag); } else { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("If-None-Match", etag); } } headers.Add("Raven-Client-Version", ClientVersion); requestParams.UpdateHeaders(headers); }
public CreateHttpJsonRequestParams(IHoldProfilingInformation self, string url, string method, OperationCredentials credentials, Convention convention, TimeSpan? timeout = null) : this(self, url, method, new RavenJObject(), credentials, convention, timeout) {}
/// <summary> /// Invoke the LogRequest event /// </summary> internal void InvokeLogRequest(IHoldProfilingInformation sender, RequestResultArgs e) { var handler = LogRequest; if (handler != null) handler(sender, e); }