Example #1
0
        protected virtual HttpRequestMessage CreateRequest(GetAttachmentCommand cmd)
        {
            var req = new HttpRequest(HttpMethod.Get, GenerateRequestUrl(cmd.DocId, cmd.DocRev, cmd.Name));

            req.SetIfMatch(cmd.DocRev);

            return req;
        }
        public virtual HttpRequest Create(GetAttachmentRequest request)
        {
            Ensure.That(request, "request").IsNotNull();

            var httpRequest = new HttpRequest(HttpMethod.Get, GenerateRelativeUrl(request))
                .SetRequestTypeHeader(request.GetType())
                .SetIfMatchHeader(request.DocRev);

            return httpRequest;
        }
Example #3
0
        public virtual async Task<HttpResponseMessage> SendAsync(HttpRequest httpRequest, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            OnBeforeSend(httpRequest);

            using (var message = CreateHttpRequestMessage(httpRequest))
            {
                return await HttpClient.SendAsync(message, cancellationToken).ForAwait();
            }
        }
        public virtual HttpRequest Create(CopyDocumentRequest request)
        {
            Ensure.That(request, "request").IsNotNull();

            var httpRequest = new HttpRequest(new HttpMethod("COPY"), GenerateRelativeUrl(request))
                .SetRequestTypeHeader(request.GetType())
                .SetIfMatchHeader(request.SrcRev);

            httpRequest.Headers.Add("Destination", request.NewId);

            return httpRequest;
        }
        public virtual HttpRequest Create(ReplaceDocumentRequest request)
        {
            Ensure.That(request, "request").IsNotNull();

            var httpRequest = new HttpRequest(new HttpMethod("COPY"), GenerateRelativeUrl(request))
                .SetRequestTypeHeader(request.GetType())
                .SetIfMatchHeader(request.SrcRev);

            httpRequest.Headers.Add("Destination", string.Concat(request.TrgId, "?rev=", request.TrgRev));

            return httpRequest;
        }
        public virtual HttpRequest Create(QueryShowRequest request)
        {
            Ensure.That(request, "request").IsNotNull();

            var httpRequest = new HttpRequest(HttpMethod.Get, GenerateRelativeUrl(request));

            httpRequest.SetRequestTypeHeader(request.GetType());

            if (request.HasAccepts)
                httpRequest.SetAcceptHeader(request.Accepts);
            else
                httpRequest.SetAcceptHeader(HttpContentTypes.Json, HttpContentTypes.Html);

            return httpRequest;
        }
Example #7
0
        protected virtual HttpRequestMessage CreateRequest(ReplaceDocumentCommand cmd)
        {
            var req = new HttpRequest(new HttpMethod("COPY"), GenerateRequestUrl(cmd));

            req.Headers.Add("Destination", string.Concat(cmd.TrgId, "?rev=", cmd.TrgRev));

            return req;
        }
Example #8
0
        protected virtual HttpRequestMessage CreateRequest(BulkCommand cmd)
        {
            var req = new HttpRequest(HttpMethod.Post, GenerateRequestUrl(cmd));

            req.SetContent(cmd.ToJson());

            return req;
        }
Example #9
0
        protected virtual HttpRequestMessage CreateRequest(CopyDocumentCommand cmd)
        {
            var req = new HttpRequest(new HttpMethod("COPY"), GenerateRequestUrl(cmd));

            req.Headers.Add("Destination", cmd.NewId);

            return req;
        }
 public virtual async Task<HttpResponseMessage> SendAsync(HttpRequest httpRequest, HttpCompletionOption completionOption, CancellationToken cancellationToken)
 {
     return await HttpClient.SendAsync(OnBeforeSend(httpRequest), completionOption, cancellationToken).ForAwait();
 }
 protected virtual HttpRequest OnBeforeSend(HttpRequest httpRequest)
 {
     return httpRequest.RemoveRequestType();
 }
Example #12
0
 public Task<HttpResponseMessage> SendAsync(HttpRequest httpRequest)
 {
     return null;
 }
 public virtual async Task<HttpResponseMessage> SendAsync(HttpRequest httpRequest)
 {
     return await HttpClient.SendAsync(OnBeforeSend(httpRequest)).ForAwait();
 }
Example #14
0
        protected virtual HttpRequestMessage CreateRequest(DocumentExistsCommand cmd)
        {
            var req = new HttpRequest(HttpMethod.Head, GenerateRequestUrl(cmd.Id, cmd.Rev));

            req.SetIfMatch(cmd.Rev);

            return req;
        }
Example #15
0
        protected virtual HttpRequestMessage CreateRequest(PutDocumentCommand cmd)
        {
            var req = new HttpRequest(HttpMethod.Put, GenerateRequestUrl(cmd.Id, cmd.Rev));

            req.SetIfMatch(cmd.Rev);
            req.SetContent(cmd.Content);

            return req;
        }
Example #16
0
 protected virtual string GenerateRequestUri(HttpRequest httpRequest)
 {
     return string.Format("{0}/{1}", Address.ToString().TrimEnd('/'), httpRequest.RelativeUrl.TrimStart('/'));
 }
Example #17
0
 protected virtual void OnBeforeSend(HttpRequest httpRequest) { }
Example #18
0
 protected virtual Task<HttpResponseMessage> SendAsync(HttpRequest httpRequest)
 {
     return Connection.SendAsync(httpRequest);
 }
Example #19
0
 public Task<HttpResponseMessage> SendAsync(HttpRequest httpRequest, HttpCompletionOption completionOption, CancellationToken cancellationToken)
 {
     return null;
 }
Example #20
0
 public Task<HttpResponseMessage> SendAsync(HttpRequest httpRequest, HttpCompletionOption completionOption)
 {
     return null;
 }
Example #21
0
        protected virtual HttpRequestMessage CreateRequest(HttpMethod method, JsonDocumentCommand cmd)
        {
            var req = new HttpRequest(method, GenerateRequestUrl(cmd));

            if (!string.IsNullOrWhiteSpace(cmd.Rev))
                req.SetIfMatch(cmd.Rev);

            req.SetContent(cmd.Content);

            return req;
        }
Example #22
0
        protected virtual HttpRequestMessage CreateRequest(PostDocumentCommand cmd)
        {
            var req = new HttpRequest(HttpMethod.Post, GenerateRequestUrl());

            req.SetContent(cmd.Content);

            return req;
        }
Example #23
0
        protected virtual HttpRequestMessage CreateHttpRequestMessage(HttpRequest httpRequest)
        {
            httpRequest.RemoveRequestTypeHeader();

            var message = new HttpRequestMessage(httpRequest.Method, GenerateRequestUri(httpRequest))
            {
                Content = httpRequest.Content,
            };

            foreach (var kv in httpRequest.Headers)
                message.Headers.TryAddWithoutValidation(kv.Key, kv.Value);

            return message;
        }
Example #24
0
 protected virtual Task<HttpResponseMessage> SendAsync(HttpRequest httpRequest, HttpCompletionOption completionOption, CancellationToken cancellationToken)
 {
     return Connection.SendAsync(httpRequest, completionOption, cancellationToken);
 }