コード例 #1
0
        public bool TryParse(out HttpRequest request)
        {
            try
            {
                request = null;

                if (!TryParsePackage())
                {
                    return false;
                }

                if (!TryParseRequestHeader())
                {
                    return false;
                }

                ParseHeaders();
                ParseBody();
                ParseQuery();

                // TODO: Investigate the headers instead of trying to parse.
                JsonObject jsonBody;
                JsonObject.TryParse(_body, out jsonBody);

                request = new HttpRequest(_method, _uri, _query, _headers, _body, jsonBody);
                return true;
            }
            catch (Exception)
            {
                request = null;
                return false;
            }
        }
コード例 #2
0
        private bool GetClientSupportsCompression(HttpRequest request)
        {
            string headerValue;
            if (request.Headers.TryGetValue("Accept-Encoding", out headerValue))
            {
                return headerValue.IndexOf("gzip", StringComparison.OrdinalIgnoreCase) > -1;
            }

            return false;
        }
コード例 #3
0
        private void ApiPost(HttpRequest request)
        {
            _temperature.UpdateValue((float) request.JsonBody.GetNamedNumber("temperature"));
            _humidity.UpdateValue((float) request.JsonBody.GetNamedNumber("humidity"));
            _sunrise = TimeSpan.Parse(request.JsonBody.GetNamedString("sunrise"));
            _sunset = TimeSpan.Parse(request.JsonBody.GetNamedString("sunset"));

            _lastFetched = DateTime.Now;
        }