/// <summary> /// The get response headers. /// </summary> /// <param name="response"> /// The response. /// </param> /// <param name="responseLength"> /// The response length. /// </param> /// <param name="redirectUrl"> /// The redirect url. /// </param> protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl) { // unknown content-length // no-redirect responseLength = -1; redirectUrl = null; try { var headers = response.GetHeaderMap(); headers.Add("Access-Control-Allow-Origin", "*"); response.SetHeaderMap(headers); response.Status = (int)HttpStatusCode.OK; response.MimeType = this.mMime; response.StatusText = "OK"; } catch (Exception exception) { response.Status = (int)HttpStatusCode.BadRequest; response.MimeType = "text/plain"; response.StatusText = "Resource loading error."; Log.Error(exception); } }
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl) { // unknown content-length // no-redirect responseLength = -1; redirectUrl = null; try { HttpStatusCode status = (_chromelyResponse != null) ? (HttpStatusCode)_chromelyResponse.Status : HttpStatusCode.BadRequest; string errorStatus = (_chromelyResponse != null) ? _chromelyResponse.Data.ToString() : "Not Found"; var headers = response.GetHeaderMap(); headers.Add("Cache-Control", "private"); headers.Add("Access-Control-Allow-Origin", "*"); headers.Add("Access-Control-Allow-Methods", "GET,POST"); headers.Add("Access-Control-Allow-Headers", "Content-Type"); headers.Add("Content-Type", "application/json; charset=utf-8"); response.SetHeaderMap(headers); response.Status = (int)status; response.MimeType = "application/json"; response.StatusText = (status == HttpStatusCode.OK) ? "OK" : errorStatus; } catch (Exception exception) { Logger.Instance.Log.LogError(exception, exception.Message); } }
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl) { // unknown content-length // no-redirect responseLength = -1; redirectUrl = null; try { var headers = response.GetHeaderMap(); headers.Add("Access-Control-Allow-Origin", "*"); response.SetHeaderMap(headers); response.Status = (int)_chromelyResource.StatusCode; response.MimeType = _chromelyResource.MimeType; response.StatusText = _chromelyResource.StatusText; } catch (Exception exception) { _chromelyResource = _chromelyErrorHandler.HandleError(_fileInfo, exception); response.Status = (int)_chromelyResource.StatusCode; response.MimeType = _chromelyResource.MimeType; response.StatusText = _chromelyResource.StatusText; } }
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl) { responseLength = _responseBytes?.LongLength ?? 0; redirectUrl = null; try { var statusCode = _apiResponse.StatusCode; var headers = response.GetHeaderMap(); headers.Add("Cache-Control", "private"); headers.Add("Access-Control-Allow-Origin", "*"); headers.Add("Access-Control-Allow-Methods", "GET,POST"); headers.Add("Access-Control-Allow-Headers", "Content-Type"); headers.Add("Content-Type", "application/json; charset=utf-8"); response.SetHeaderMap(headers); response.Status = statusCode; response.MimeType = "application/json"; response.StatusText = (statusCode < 400 && statusCode >= 200) ? "OK" : "Error"; } catch (Exception exception) { _logger.Error(exception); } }
protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl) { // unknown content-length // no-redirect responseLength = -1; redirectUrl = null; try { var headers = response.GetHeaderMap(); headers.Add("Access-Control-Allow-Origin", "*"); response.SetHeaderMap(headers); response.Status = (int)_statusCode; response.MimeType = _mime; response.StatusText = _statusText; } catch (Exception exception) { _chromelyErrorHandler.HandleResourceError(ResourceStatus.FileProcessingError, null, exception, out _statusCode, out _statusText); response.Status = (int)_statusCode; response.StatusText = _statusText; response.MimeType = "text/plain"; Logger.Instance.Log.LogError(exception, exception.Message); } }
protected override void OnResourceResponse(CefBrowser browser, string url, CefResponse response, out CefContentFilter filter) { var prevColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("OnResourceResponse: {0} ({1})", url, response.GetHeader("Content-Length")); Console.ForegroundColor = prevColor; response.GetHeaderMap().Append("Access-Control-Allow-Origin", "*"); filter = null; // filter = new CefWebProgressContentFilter(); }
/// <inheritdoc/> protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl) { // unknown content-length // no-redirect responseLength = -1; redirectUrl = null; try { if (_httpResponseMessage == null) { response.Error = CefErrorCode.Failed; return; } var headers = response.GetHeaderMap(); headers.Clear(); this.ProcessHeaders(_httpResponseMessage, headers); response.SetHeaderMap(headers); response.MimeType = _httpResponseMessage.Content?.Headers?.ContentType?.MediaType; response.Status = (int)_httpResponseMessage.StatusCode; response.StatusText = _httpResponseMessage.ReasonPhrase; responseLength = this._responseLenght = _httpResponseMessage.Content?.Headers?.ContentLength ?? -1; if (_httpResponseMessage.StatusCode == HttpStatusCode.MovedPermanently || _httpResponseMessage.StatusCode == HttpStatusCode.Moved || _httpResponseMessage.StatusCode == HttpStatusCode.Redirect || _httpResponseMessage.StatusCode == HttpStatusCode.RedirectMethod || _httpResponseMessage.StatusCode == HttpStatusCode.TemporaryRedirect) { redirectUrl = _httpResponseMessage.Headers.Location.ToString(); } } catch (Exception ex) { response.Error = CefErrorCode.Failed; Logger.Instance.Log.LogError(ex, "Exception thrown while processing request"); } }