示例#1
0
        /// <summary>
        /// Loads options from filename
        /// </summary>
        public static HttpOptions Load(string filename)
        {
            string  json = System.IO.File.ReadAllText(filename);
            JObject obj  = JObject.Parse(json);

            HttpOptions options = CreateDefault();

            JToken timeMax = obj["HttpConnectionTimeMax"];

            if (timeMax != null)
            {
                options.HttpConnectionTimeMax = timeMax.Value <int>();
            }

            JToken requestLength = obj["MaximumRequestLength"];

            if (requestLength != null)
            {
                options.MaximumRequestLength = requestLength.Value <int>();
            }

            JToken hostnames = obj["Hostnames"];

            if (hostnames != null && hostnames.HasValues)
            {
                options.Hostnames = obj["Hostnames"].Values <string>().ToArray();
            }

            JToken supportedEncodings = obj["SupportedEncodings"];

            string[] sx = supportedEncodings != null?supportedEncodings.Values <string>().ToArray() : new string[0];

            List <ContentEncodings> encodings = new List <ContentEncodings>();

            foreach (string s in sx)
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }

                switch (s.Trim().ToLower())
                {
                case "none":
                    encodings.Add(ContentEncodings.None);
                    break;

                case "gzip":
                    encodings.Add(ContentEncodings.Gzip);
                    break;

                case "br":
                    encodings.Add(ContentEncodings.Brotli);
                    break;

                case "brotli":
                    encodings.Add(ContentEncodings.Brotli);
                    break;

                case "deflate":
                    encodings.Add(ContentEncodings.Deflate);
                    break;
                }
            }

            if (encodings.Count == 0)
            {
                encodings.Add(ContentEncodings.None);
            }

            options.SupportedEncodings = encodings.ToArray();

            return(options);
        }
示例#2
0
 /// <summary>
 /// Uses HTTP Protocol and accepts HTTP connections
 /// </summary>
 public static ITwinoServer UseHttp(this ITwinoServer server, HttpRequestHandler action)
 {
     return(UseHttp(server, action, HttpOptions.CreateDefault()));
 }
示例#3
0
        /// <summary>
        /// Uses HTTP Protocol and accepts HTTP connections
        /// </summary>
        public static ITwinoServer UseHttp(this ITwinoServer server, HttpRequestHandler action, HttpOptions options)
        {
            HttpMethodHandler handler  = new HttpMethodHandler(action);
            TwinoHttpProtocol protocol = new TwinoHttpProtocol(server, handler, options);

            server.UseProtocol(protocol);
            return(server);
        }
示例#4
0
 /// <summary>
 /// Creates new HTTP 1.1 protocol reader with specified options
 /// </summary>
 public HttpReader(HttpOptions options)
 {
     _options = options;
 }