public void WriteActionsThrowWhenReadOnly()
    {
        var headers = new HeaderDictionary();

        headers.IsReadOnly = true;

        Assert.Throws <InvalidOperationException>(() => headers["header1"] = "value1");
        Assert.Throws <InvalidOperationException>(() => ((IDictionary <string, StringValues>)headers)["header1"] = "value1");
        Assert.Throws <InvalidOperationException>(() => headers.ContentLength = 12);
        Assert.Throws <InvalidOperationException>(() => headers.Add(new KeyValuePair <string, StringValues>("header1", "value1")));
        Assert.Throws <InvalidOperationException>(() => headers.Add("header1", "value1"));
        Assert.Throws <InvalidOperationException>(() => headers.Clear());
        Assert.Throws <InvalidOperationException>(() => headers.Remove(new KeyValuePair <string, StringValues>("header1", "value1")));
        Assert.Throws <InvalidOperationException>(() => headers.Remove("header1"));
    }
Beispiel #2
0
        protected override void Push(IOwinRequest request, PushFunc pushPromise, string pushReference)
        {
            // Copy the headers
            var headers = new HeaderDictionary(
                new Dictionary <string, string[]>(request.Headers, StringComparer.OrdinalIgnoreCase));

            // Populate special HTTP2 headers
            headers[CommonHeaders.Method] = request.Method.ToUpper(); // TODO: Not all methods are allowed for push.  Don't push, or change to GET?
            headers[CommonHeaders.Scheme] = request.Scheme;
            headers.Remove("Host");
            headers[CommonHeaders.Authority] = request.Headers["Host"];
            headers.Remove(CommonHeaders.ContentLength); // Push promises cannot emulate requests with bodies.
            // TODO: What about cache headers? If-Match, If-None-Match, If-Modified-Since, If-Unmodified-Since.
            // If-Match & If-None-Match are multi-value so the client could send e-tags for the primary resource and referenced resources.
            // If-Modified-Since and If-Unmodified-Since are single value, so it may not make sense to apply them for secondary resources.

            // Change the request path to the pushed resource
            headers[CommonHeaders.Path] = pushReference;

            pushPromise(headers);
        }
 public bool Remove(KeyValuePair <string, StringValues> item)
 {
     return(_headers.Remove(item));
 }
 public bool Remove(string key)
 {
     return(_headers.Remove(key));
 }