Exemple #1
0
 public ByteArrayHttpResponse(byte[] body, HttpResponseCode code, IStringLookup headers)
     : base(code, headers)
 {
     _body   = body;
     _offset = 0;
     _length = body.Length;
 }
Exemple #2
0
 public RedirectingHttpResponse(HttpResponseCode code, IStringLookup headers)
     : base(code, headers)
 {
     if ((int)code < 300 && (int)code > 399)
     {
         throw new ArgumentException("The response code must be a redirection code 3xx.", nameof(code));
     }
 }
Exemple #3
0
        public static string ToUriData(this IStringLookup headers)
        {
            var builder = new StringBuilder();

            foreach (var header in headers)
            {
                builder.AppendFormat("{0}={1}&", Uri.EscapeDataString(header.Key), Uri.EscapeDataString(header.Value));
            }
            return(builder.ToString(0, builder.Length - 1));
        }
Exemple #4
0
        public static bool TryGetByName <T>(this IStringLookup headers, string name, out T value)
        {
            if (headers.TryGetByName(name, out var stringValue))
            {
                value = (T)Convert.ChangeType(stringValue, typeof(T), CultureInfo.InvariantCulture);
                return(true);
            }

            value = default;
            return(false);
        }
 public HttpRequest(
     HttpMethod method,
     Uri uri,
     string protocol,
     IStringLookup headers,
     Stream contentStream)
 {
     Method       = method;
     Url          = uri;
     Protocol     = protocol;
     PathSegments = uri.GetPathSegments();
     Headers      = headers;
     Query        = string.IsNullOrEmpty(uri.Query)
         ? EmptyStringLookup.Instance
         : new QueryStringLookup(uri.Query);
     ;
     ContentStream = contentStream;
     Content       = null;
 }
Exemple #6
0
 public ByteArrayHttpResponse(byte[] body, int offset, int length, HttpResponseCode code, IStringLookup headers)
     : base(code, headers)
 {
     _body   = body;
     _offset = offset;
     _length = length;
 }
Exemple #7
0
 public EmptyHttpResponse(HttpResponseCode code, IStringLookup headers)
     : base(code, headers)
 {
 }
 public StringLookupDebuggerProxy(IStringLookup real)
 {
     _real = real;
 }
Exemple #9
0
 public static T GetByNameOrDefault <T>(this IStringLookup headers, string name, T defaultValue)
 {
     return(headers.TryGetByName(name, out T value) ? value : defaultValue);
 }
Exemple #10
0
 public static T GetByName <T>(this IStringLookup headers, string name)
 {
     return(headers.TryGetByName(name, out T value)
         ? value
         : throw new EntryNotFoundException($"Could not find '{name}' in lookup.", name));
 }
Exemple #11
0
 public static IStringLookup ToChainedStringLookup(this IEnumerable <KeyValuePair <string, string> > entries,
                                                   IStringLookup parent)
 => new ChainedDictionaryStringLookup(parent,
                                      entries.ToDictionary(e => e.Key, e => e.Value, StringComparer.InvariantCultureIgnoreCase));
 public StringHttpResponse(string body, HttpResponseCode code, IStringLookup headers)
     : base(code, headers)
 {
     _body = body;
 }
Exemple #13
0
 protected HttpResponseBase(HttpResponseCode code, IStringLookup headers)
 {
     ResponseCode = code;
     Headers      = headers;
 }
Exemple #14
0
 public ChainedDictionaryStringLookup(IStringLookup parent, IDictionary <string, string> values)
 {
     _parent = parent;
     _values = values;
 }