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; } }
private bool GetClientSupportsCompression(HttpRequest request) { string headerValue; if (request.Headers.TryGetValue("Accept-Encoding", out headerValue)) { return headerValue.IndexOf("gzip", StringComparison.OrdinalIgnoreCase) > -1; } return false; }
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; }