예제 #1
0
        public AspNetResponse(HttpContext context)
        {
            NativeContext = context;
            Headers       = new HttpHeaderDictionary();
            Entity        = new HttpEntity(Headers, NativeContext.Response.OutputStream);
//      context.Response.AddOnSendingHeaders(httpContext => _nativeHeadersSent = true);
        }
예제 #2
0
 public InMemoryRequest()
 {
     Headers = new HttpHeaderDictionary();
     Headers.Add("Host", "http://localhost/");
     Entity          = new HttpEntity(Headers, new MemoryStream());
     CodecParameters = new List <string>();
 }
예제 #3
0
 void SetHeaders(HttpHeaderDictionary headers, HttpResponseHeaders responseMessageHeaders)
 {
     foreach (var header in responseMessageHeaders)
     {
         SetHeader(headers, header.Key, header.Value);
     }
 }
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context        = context;
     _nativeResponse = response;
     Headers         = new HttpHeaderDictionary();
     Entity          = new HttpEntity(Headers, response.OutputStream);
 }
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context = context;
     _nativeResponse = response;
     Headers = new HttpHeaderDictionary();
     Entity = new HttpEntity(Headers, _tempStream);
     _nativeResponse.SendChunked = false;
 }
예제 #6
0
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context                    = context;
     _nativeResponse             = response;
     Headers                     = new HttpHeaderDictionary();
     Entity                      = new HttpEntity(Headers, _tempStream);
     _nativeResponse.SendChunked = false;
 }
예제 #7
0
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context        = context;
     _nativeResponse = response;
     Headers         = new HttpHeaderDictionary();
     // TODO: Wrap stream and send chunked when needed if write starts before sending response
     Entity = new HttpEntity(Headers, _tempStream);
     _nativeResponse.SendChunked = false;
 }
        public OwinResponse(IOwinContext context)
        {
            var response = context.Response;

            NativeContext = response;
            Headers = new HttpHeaderDictionary();
            var delayedStream = new DelayedStream(context.Response.Body);
            Entity = new HttpEntity(Headers, delayedStream);
        }
예제 #9
0
        public static void ShouldNotHaveHeader(this HttpHeaderDictionary headers, string fieldName)
        {
            headers[fieldName].ShouldBeNull();
            headers.TryGetValue(fieldName, out _).ShouldBeFalse();

            headers.TryGetValues(fieldName, out _).ShouldBeFalse();

            headers.Keys.ShouldNotContain(fieldName);
        }
예제 #10
0
        public void create_from_nvc()
        {
            var nvc = new NameValueCollection();

            nvc.Add("key", "value");
            nvc.Add("key", "value2");
            headers = new HttpHeaderDictionary(nvc);
            headers.ShouldHaveHeaderValues("key", "value", "value2");
        }
예제 #11
0
        public OwinResponse(IOwinContext context)
        {
            var response = context.Response;

            NativeContext = response;
            Headers       = new HttpHeaderDictionary();
            //var delayedStream = new DelayedStream(context.Response.Body);
            Entity = new HttpEntity(Headers, context.Response.Body);
        }
예제 #12
0
 public HttpEntity(HttpHeaderDictionary messageheaders, Stream entityBodyStream)
 {
     Headers = messageheaders;
     if (entityBodyStream != null)
     {
         Stream = new LengthTrackingStream(entityBodyStream);
     }
     Errors = new List<Error>();
 }
예제 #13
0
 public HttpListenerResponse(HttpListenerCommunicationContext context, System.Net.HttpListenerResponse response)
 {
     _context = context;
     _nativeResponse = response;
     Headers = new HttpHeaderDictionary();
     // TODO: Wrap stream and send chunked when needed if write starts before sending response
     Entity = new HttpEntity(Headers, _tempStream);
     _nativeResponse.SendChunked = false;
 }
예제 #14
0
        public void op_Contains_Token()
        {
            var obj = new HttpHeaderDictionary();

            Assert.False(obj.Contains("name"));

            obj.Add(new HttpHeader("name", "value"));

            Assert.True(obj.Contains("name"));
        }
예제 #15
0
        public OwinResponse(IOwinContext context)
        {
            var response = context.Response;

            context.Response.OnSendingHeaders(r => r.NativeHeadersSent = true, this);

            NativeContext = response;
            Headers       = new HttpHeaderDictionary();
            Entity        = new HttpEntity(Headers, context.Response.Body);
            _statusCode   = context.Response.StatusCode;
        }
예제 #16
0
        public void op_Add_HttpHeader()
        {
            var expected = new HttpHeader("name", "value");

            var obj = new HttpHeaderDictionary
                          {
                              expected
                          };

            Assert.Equal("value", obj["name"]);
        }
예제 #17
0
        public WebRequestResponse(HttpWebResponse response)
        {
            _response = response;
            if (!string.IsNullOrEmpty(response.ContentType))
                ContentType = new MediaType(response.ContentType);

            ContentLength = response.ContentLength;
            Headers = new HttpHeaderDictionary();
            foreach (string headerName in response.Headers.AllKeys)
                Headers[headerName] = response.Headers[headerName];
        }
예제 #18
0
        void PopulateHeaders(IOwinRequest ctx)
        {
            var headerCollection = new HttpHeaderDictionary();

            foreach (var header in ctx.Headers)
            {
                headerCollection.Add(header.Key, string.Join(",", header.Value));
            }

            Headers = headerCollection;
        }
예제 #19
0
        public HttpListenerRequest(HttpListenerCommunicationContext context, System.Net.HttpListenerRequest request)
        {
            _context = context;
            _nativeRequest = request;
            Uri = _nativeRequest.Url;
            CodecParameters = new List<string>();

            Headers = new HttpHeaderDictionary(_nativeRequest.Headers);

            Entity = new HttpEntity(Headers, new HistoryStream(_nativeRequest.InputStream));

            if (!string.IsNullOrEmpty(_nativeRequest.ContentType))
                Entity.ContentType = new MediaType(_nativeRequest.ContentType);
        }
예제 #20
0
        public AspNetRequest(HttpContext context)
        {
            NativeContext = context;
            Uri = NativeContext.Request.Url;
            Headers = new HttpHeaderDictionary(NativeContext.Request.Headers);

            // TODO: Finish off the new input stream that goes to the
            // WorkerRequest and bypasses asp.net completely.
            Entity = new HttpEntity(Headers, NativeContext.Request.InputStream);

            if (!string.IsNullOrEmpty(NativeContext.Request.ContentType))
                Entity.ContentType = new MediaType(NativeContext.Request.ContentType);
            CodecParameters = new List<string>();
        }
예제 #21
0
        public WebRequestResponse(HttpWebResponse response)
        {
            _response = response;
            if (!string.IsNullOrEmpty(response.ContentType))
            {
                ContentType = new MediaType(response.ContentType);
            }

            ContentLength = response.ContentLength;
            Headers       = new HttpHeaderDictionary();
            foreach (string headerName in response.Headers.AllKeys)
            {
                Headers[headerName] = response.Headers[headerName];
            }
        }
        public AspNetRequest(HttpContext context)
        {
            NativeContext = context;
            Uri           = NativeContext.Request.Url;
            Headers       = new HttpHeaderDictionary(NativeContext.Request.Headers);

            Entity = new HttpEntity(Headers, NativeContext.Request.InputStream);

            if (!string.IsNullOrEmpty(NativeContext.Request.ContentType))
            {
                Entity.ContentType = new MediaType(NativeContext.Request.ContentType);
            }

            CodecParameters = new List <string>();
        }
        public AspNetRequest(HttpContext context)
        {
            NativeContext = context;
            Uri           = NativeContext.Request.Url;
            Headers       = new HttpHeaderDictionary(NativeContext.Request.Headers);

            // TODO: Finish off the new input stream that goes to the
            // WorkerRequest and bypasses asp.net completely.
            Entity = new HttpEntity(Headers, NativeContext.Request.InputStream);

            if (!string.IsNullOrEmpty(NativeContext.Request.ContentType))
            {
                Entity.ContentType = new MediaType(NativeContext.Request.ContentType);
            }
            CodecParameters = new List <string>();
        }
        public HttpListenerRequest(HttpListenerCommunicationContext context, System.Net.HttpListenerRequest request)
        {
            _context        = context;
            _nativeRequest  = request;
            Uri             = _nativeRequest.Url;
            CodecParameters = new List <string>();

            Headers = new HttpHeaderDictionary(_nativeRequest.Headers);

            Entity = new HttpEntity(Headers, _nativeRequest.InputStream);

            if (!string.IsNullOrEmpty(_nativeRequest.ContentType))
            {
                Entity.ContentType = new MediaType(_nativeRequest.ContentType);
            }
        }
예제 #25
0
        private void PopulateHeaders(IOwinRequest ctx)
        {
            var headerCollection = new NameValueCollection();

            foreach (var header in ctx.Headers)
            {
                headerCollection.Add(header.Key, header.Value.First());
            }

            Headers = new HttpHeaderDictionary(headerCollection);

            if (Headers.ContentLength == null)
            {
                Headers.ContentLength = ctx.Body.Length;
            }
        }
예제 #26
0
        static void SetHeader(HttpHeaderDictionary headers, string fieldName, IEnumerable <string> fieldValues)
        {
            if (HttpHeaderClassification.IsHopByHopHeader(fieldName))
            {
                return;
            }

            if (HttpHeaderClassification.IsAppendedOnForwardHeader(fieldName))
            {
                headers.AddValues(fieldName, fieldValues);
            }
            else
            {
                headers.Remove(fieldName);
                headers.AddValues(fieldName, fieldValues);
            }
        }
예제 #27
0
        public OwinResponse(IOwinContext context)
        {
            _nativeAssignements = new Dictionary <string, Action <IOwinResponse, string> >(StringComparer.OrdinalIgnoreCase)
            {
                ["content-type"]   = (r, val) => r.ContentType = val,
                ["content-length"] = (r, val) => r.ContentLength = Headers.ContentLength
            };

            var response = context.Response;

            context.Response.OnSendingHeaders(r => r.NativeHeadersSent = true, this);

            NativeContext = response;
            Headers       = new HttpHeaderDictionary();
            Entity        = new HttpEntity(Headers, context.Response.Body);
            _statusCode   = context.Response.StatusCode;
        }
예제 #28
0
        private void WriteBlock(string transferId, long blockNumber, Stream input)
        {
            //get meta information from headers
            VfsHttpHeaders       headerNames = VfsHttpHeaders.Default;
            HttpHeaderDictionary headers     = Request.Headers;

            var blockLength = Convert.ToInt32(headers[headerNames.BlockLength]);
            var isLastBlock = headers.ContainsKey(headerNames.IsLastBlock) ? Convert.ToBoolean(headers[headerNames.IsLastBlock]) : false;
            var offset      = Convert.ToInt64(headers[headerNames.BlockOffset]);

            StreamedDataBlock block = new StreamedDataBlock
            {
                TransferTokenId = transferId,
                BlockNumber     = blockNumber,
                IsLastBlock     = isLastBlock,
                BlockLength     = blockLength,
                Offset          = offset,
                Data            = new NonSeekableStream(input)
            };

            FileSystem.UploadTransfers.WriteBlockStreamed(block);
        }
예제 #29
0
        public static void ShouldHaveHeaderValues(this HttpHeaderDictionary headers, string fieldName,
                                                  params string[] fieldValue)
        {
            var combinedFieldValues = string.Join(",", fieldValue);

            // indexer
            headers[fieldName].ShouldBe(combinedFieldValues);

            // singular
            headers.TryGetValue(fieldName, out var singular).ShouldBeTrue();
            singular.ShouldBe(combinedFieldValues);

            // multi
            headers.TryGetValues(fieldName, out var all).ShouldBeTrue();
            all.ShouldBe(fieldValue);

            // keys contain
            headers.Keys.ShouldContain(fieldName);
            headers.ContainsKey(fieldName).ShouldBeTrue();

            // values contain (why again, why?)
            headers.Values.ShouldContain(combinedFieldValues);


            foreach (var val in fieldValue)
            {
                headers.Contains(new KeyValuePair <string, string>(fieldName, val)).ShouldBeTrue();
            }

            // convert to dictionary
            new Dictionary <string, string>(headers)[fieldName].ShouldBe(combinedFieldValues);

            // copy to array (why why why?)
            var array = new KeyValuePair <string, string> [10];

            headers.CopyTo(array, 0);
            array.Any(item => item.Key == fieldName && item.Value == combinedFieldValues).ShouldBeTrue();
        }
예제 #30
0
 public MultipartHttpEntity()
 {
     Headers = new HttpHeaderDictionary();
 }
예제 #31
0
 public InMemoryRequest()
 {
     Headers = new HttpHeaderDictionary();
     Entity = new HttpEntity(Headers, new MemoryStream());
     CodecParameters = new List<string>();
 }
예제 #32
0
 public InMemoryResponse()
 {
     Headers = new HttpHeaderDictionary();
     Entity = new HttpEntity(Headers, _outputStream);
 }
예제 #33
0
        public void op_GetEnumerator()
        {
            var expected = new KeyValuePair<Token, string>("name", "value");

            var obj = new HttpHeaderDictionary
                          {
                              {
                                  "name", "value"
                              }
                          };

            foreach (var actual in obj)
            {
                Assert.Equal(expected, actual);
            }
        }
 public AspNetResponse(HttpContext context)
 {
     NativeContext = context;
     Headers = new HttpHeaderDictionary();
     Entity = new HttpEntity(Headers, NativeContext.Response.OutputStream);
 }
예제 #35
0
 public InMemoryRequest()
 {
     Headers         = new HttpHeaderDictionary();
     Entity          = new HttpEntity(Headers, new MemoryStream());
     CodecParameters = new List <string>();
 }
 public AspNetResponse(HttpContext context)
 {
     NativeContext = context;
     Headers       = new HttpHeaderDictionary();
     Entity        = new HttpEntity(Headers, NativeContext.Response.OutputStream);
 }
예제 #37
0
 public InMemoryResponse()
 {
     Headers = new HttpHeaderDictionary();
     Entity  = new HttpEntity(Headers, _outputStream);
 }