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     = _status;
                response.MimeType   = _mime;
                response.StatusText = _statusText;
            }
            catch (Exception exception)
            {
                response.Status     = (int)HttpStatusCode.BadRequest;
                response.MimeType   = "text/plain";
                response.StatusText = "Resource loading error.";

                Logger.Instance.Log.LogError(exception, exception.Message);
            }
        }
示例#2
0
        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;
            }
        }
示例#3
0
        /// <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", "*");
                headers.Add("Accept-Ranges", "bytes");
                headers.Add("Content-Lenght", this.mFileBytes.Length.ToString());
                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);
            }
        }
示例#4
0
        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);
            }
        }
示例#5
0
        /// <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
            {
                HttpStatusCode status      = (mChromelyResponse != null) ? (HttpStatusCode)mChromelyResponse.Status : HttpStatusCode.BadRequest;
                string         errorStatus = (mChromelyResponse != null) ? mChromelyResponse.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)
            {
                Log.Error(exception);
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
    protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
    {
        redirectUrl    = string.Empty;
        responseLength = -1;

        response.MimeType   = MimeType;
        response.Status     = StatusCode;
        response.StatusText = StatusText;
        response.SetHeaderMap(Headers);

        if (!StringUtil.IsNullOrEmpty(Charset))
        {
            response.Charset = Charset ?? string.Empty;
        }

        if (ResponseLength.HasValue)
        {
            responseLength = ResponseLength.Value;
        }

        if (Stream is not null && Stream.CanSeek)
        {
            //ResponseLength property has higher precedence over Stream.Length
            if (ResponseLength is null || responseLength == 0)
            {
                //If no ResponseLength provided then attempt to infer the length
                responseLength = Stream.Length;
            }

            Stream.Position = 0;
        }
        ;
    }
示例#8
0
 protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
 {
     response.SetHeaderMap(_source.IsStatic ? Staticfileheader : Dynamicfileheader);
     response.Status     = 200;
     response.MimeType   = _source.Mime;            // "text/html";
     response.StatusText = "OK";
     responseLength      = _source.Resource.Length; // unknown content-length
     redirectUrl         = null;                    // no-redirect
 }
示例#9
0
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            var statusCode = _resourceResponse?.HttpStatus ?? System.Net.HttpStatusCode.BadRequest;

            if (_resourceResponse != null)
            {
                response.SetHeaderMap(_resourceResponse.Headers);
            }


            response.Status = (int)statusCode;

            redirectUrl = null;

            if (statusCode == System.Net.HttpStatusCode.OK)
            {
                responseLength    = _resourceResponse.Length;
                response.MimeType = _resourceResponse.MimeType;

                if (_isPartContent)
                {
                    response.SetHeaderByName("Accept-Ranges", "bytes", true);

                    var startPos = 0;
                    var endPos   = _resourceResponse.Length - 1;

                    if (_buffStartPostition.HasValue && _buffEndPostition.HasValue)
                    {
                        startPos = _buffStartPostition.Value;
                        endPos   = _buffStartPostition.Value;
                    }
                    else if (!_buffEndPostition.HasValue && _buffStartPostition.HasValue)
                    {
                        startPos = _buffStartPostition.Value;
                    }

                    response.SetHeaderByName("Content-Range", $"bytes {startPos}-{endPos}/{_resourceResponse.Length}", true);
                    response.SetHeaderByName("Content-Length", $"{endPos - startPos + 1}", true);


                    response.Status = 206;

                    Logger.Verbose($"[Content-Range]: {startPos}-{endPos}/{_resourceResponse.Length}");
                }


                response.SetHeaderByName("Content-Type", response.MimeType, true);

                response.SetHeaderByName(X_POWERED_BY, $"NanUI/{System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}", true);
            }
            else
            {
                responseLength = 0;
            }
        }
 protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
 {
     response.MimeType   = MimeType;
     response.Status     = StatusCode;
     response.StatusText = StatusText;
     if (Headers.Count > 0)
     {
         response.SetHeaderMap(Headers);
     }
     responseLength = (Data == null ? 0 : Data.LongLength);
     redirectUrl    = null;
 }
示例#11
0
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            response.MimeType = "text/html";
            response.Status = 200;
            response.StatusText = "OK, hello from handler!";

            var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);
            headers.Add("Cache-Control", "private");
            response.SetHeaderMap(headers);

            responseLength = responseData.LongLength;
            redirectUrl = null;
        }
示例#12
0
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            response.MimeType   = "application/javascript";
            response.Status     = 200;
            response.StatusText = "OK, hello from handler!";

            var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);

            headers.Add("Cache-Control", "private");
            response.SetHeaderMap(headers);

            responseLength = responseData.LongLength;
            redirectUrl    = null;
        }
示例#13
0
                protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
                {
                    response.MimeType   = "text/html";
                    response.Status     = 200;
                    response.StatusText = "OK";

                    var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);

                    headers.Add("Cache-Control", "private");
                    response.SetHeaderMap(headers);

                    responseLength = FStream.Length;
                    redirectUrl    = null;
                }
示例#14
0
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, ref string redirectUrl)
        {
            responseLength = this.responseLength;

            if (responseLength != -1)
            {
                var headers = new CefStringMultiMap();
                headers.Append("Content-Length", responseLength.ToString());
                response.SetHeaderMap(headers);
            }

            response.SetStatus(this.status);
            response.SetStatusText(this.statusText);
            response.SetMimeType(this.mimeType);
        }
示例#15
0
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            responseLength = this.responseLength;
            redirectUrl    = null;

            if (responseLength != -1)
            {
                var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);
                headers.Add("Content-Length", responseLength.ToString());
                response.SetHeaderMap(headers);
            }

            response.Status     = this.status;
            response.StatusText = this.statusText;
            response.MimeType   = this.mimeType;
        }
示例#16
0
        protected internal sealed override void GetResponseHeaders(CefResponse response, ref long responseLength, ref string redirectUrl)
        {
            response.Status   = (int)this.StatusCode;
            response.Charset  = "utf-8";
            response.MimeType = this.MimeType;
            responseLength    = _data.Length;

            if (_headers != null && _headers.Count > 0)
            {
                using (var map = new CefStringMultimap())
                {
                    map.Add(_headers);
                    response.SetHeaderMap(map);
                }
            }
        }
        /// <summary>
        /// Gets the response headers.
        /// </summary>
        /// <param name="response"></param>
        /// <param name="responseLength"></param>
        /// <param name="redirectUrl"></param>
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            redirectUrl = null;

            response.Status     = 200;
            response.StatusText = "OK";
            response.MimeType   = "application/json";
            response.SetHeaderMap(new NameValueCollection {
                { "Access-Control-Allow-Origin", "*" }
            });

            var nativeResponse = new NativeResponse();

            // exception
            if (Exception != null)
            {
                nativeResponse.Type      = NativeResponseType.Exception;
                nativeResponse.Value     = null;
                nativeResponse.Exception = ExceptionUtility.CreateJavascriptException(Exception);
            }

            // ok
            else
            {
                if (ResponseValue == Undefined.Value)
                {
                    nativeResponse.Type  = NativeResponseType.Undefined;
                    nativeResponse.Value = null;
                }
                else
                {
                    nativeResponse.Type  = NativeResponseType.Value;
                    nativeResponse.Value = ResponseValue;
                }

                nativeResponse.Exception = null;
            }

            Data           = JsonUtility.SerializeToByteJson(nativeResponse);
            responseLength = Data.Length;
        }
示例#18
0
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            if (process)
            {
                SetMimeType(_uri, ref response);
            }
            else
            {
                response.MimeType = "text/html";
            }
            response.Status = process ? 200 : 404;
            var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);

            headers.Add("Cache-Control", "private");
            headers.Add("Access-Control-Allow-Origin", "*");
            response.SetHeaderMap(headers);
            responseLength = process ? responseData.LongLength : 0;
            redirectUrl    = null;
        }
        /// <summary>
        /// Retrieve response header information. If the response length is not known
        /// set |response_length| to -1 and ReadResponse() will be called until it
        /// returns false. If the response length is known set |response_length|
        /// to a positive value and ReadResponse() will be called until it returns
        /// false or the specified number of bytes have been read. Use the |response|
        /// object to set the mime type, http status code and other optional header
        /// values. To redirect the request to a new URL set |redirectUrl| to the new
        /// URL.
        /// </summary>
        /// <param name="response"></param>
        /// <param name="responseLength"></param>
        /// <param name="redirectUrl"></param>
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            response.MimeType   = "text/html";
            response.Status     = 200;
            response.StatusText = "OK, hello from handler!";

            var headers = new NameValueCollection(StringComparer.OrdinalIgnoreCase);

            headers.Add("Cache-Control", "private");
            response.SetHeaderMap(headers);

            responseLength = responseData.LongLength;
            redirectUrl    = null;
        }
示例#20
0
        /// <summary>
        /// The GetResponseHeaders.
        /// </summary>
        /// <param name="response">The response<see cref="CefResponse"/>.</param>
        /// <param name="responseLength">The responseLength<see cref="long"/>.</param>
        /// <param name="redirectUrl">The redirectUrl<see cref="string"/>.</param>
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            response.MimeType   = respData.MimeType ?? "text/plain";
            response.Status     = (int)respData.HttpStatus;
            response.StatusText = respData.StatusText;

            var headers = new NameValueCollection(StringComparer.InvariantCultureIgnoreCase);

            headers.Add("Cache-Control", "private");

            foreach (var item in respData.Headers.AllKeys)
            {
                headers.Add(item, respData.Headers[item]);
            }

            response.SetHeaderMap(headers);

            responseLength = respData.Length;
            redirectUrl    = null;
        }
        /// <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");
            }
        }
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            if (ErrorCode.HasValue)
            {
                responseLength  = 0;
                redirectUrl     = null;
                response.Status = 501;
            }
            else
            {
                responseLength = -1;
                redirectUrl    = null;

                response.Status     = StatusCode;
                response.MimeType   = MimeType;
                response.StatusText = StatusText;
                response.SetHeaderMap(Headers);

                if (ResponseLength.HasValue)
                {
                    responseLength = ResponseLength.Value;
                }
                else
                {
                    var memoryStream = Stream as MemoryStream;
                    if (memoryStream != null)
                    {
                        responseLength = memoryStream.Length;
                    }
                }

                if (Stream != null && Stream.CanSeek)
                {
                    Stream.Position = 0;
                }
            }
        }
示例#23
0
        protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
        {
            // Add the "no-cache" directive to make sure that chrome doesn't cache this resource
            var headers = new NameValueCollection {
                { "Cache-Control", "no-cache" }, { "Access-Control-Allow-Origin", "*" }
            };

            response.SetHeaderMap(headers);
            response.MimeType = _mimeType;
            if (_resourceStream == null)
            {
                response.Status     = (int)HttpStatusCode.NotFound;
                response.StatusText = "Not found";
                responseLength      = -1;
                redirectUrl         = null;
            }
            else
            {
                response.Status     = (int)HttpStatusCode.OK;
                response.StatusText = "OK";
                responseLength      = _resourceStream.Length;
                redirectUrl         = null;
            }
        }