private void OnGetResponseHeaders(object sender, Chromium.Event.CfxGetResponseHeadersEventArgs e)
        {
            if (webResource == null)
            {
                e.Response.Status = 404;
            }
            else
            {
                var length = webResource.data.Length;
                e.ResponseLength    = webResource.data.Length;
                e.Response.MimeType = webResource.mimeType;
                e.Response.Status   = 200;

                var headers = e.Response.GetHeaderMap();

                if (isPartContent)
                {
                    headers.Add(new string[2] {
                        "Accept-Ranges", "bytes"
                    });
                    var startPos = 0;
                    var endPos   = length - 1;



                    if (buffStartPostition.HasValue && buffEndPostition.HasValue)
                    {
                        startPos = buffStartPostition.Value;
                        endPos   = buffEndPostition.Value;
                    }
                    else if (!buffEndPostition.HasValue && buffStartPostition.HasValue)
                    {
                        startPos = buffStartPostition.Value;
                    }



                    headers.Add(new string[2] {
                        "Content-Range", $"bytes {startPos}-{endPos}/{webResource.data.Length}"
                    });
                    headers.Add(new string[2] {
                        "Content-Length", $"{endPos - startPos + 1}"
                    });

                    e.ResponseLength = (endPos - startPos + 1);

                    e.Response.Status = 206;
                }


                e.Response.SetHeaderMap(headers);
            }
        }
Esempio n. 2
0
 private void OnGetResponseHeaders(object sender, Chromium.Event.CfxGetResponseHeadersEventArgs e)
 {
     if (webResource == null)
     {
         e.Response.Status = 404;
     }
     else
     {
         var length = webResource.data.Length;
         e.ResponseLength    = webResource.data.Length;
         e.Response.MimeType = webResource.mimeType;
         e.Response.Status   = 200;
         var headers = e.Response.GetHeaderMap();
         e.Response.SetHeaderMap(headers);
     }
 }
Esempio n. 3
0
        private void EmbeddedResourceHandler_GetResponseHeaders(object sender, Chromium.Event.CfxGetResponseHeadersEventArgs e)
        {
            if (webResource == null)
            {
                e.Response.Status = 404;
            }
            else
            {
                e.ResponseLength    = webResource.data.Length;
                e.Response.MimeType = webResource.mimeType;
                e.Response.Status   = 200;

                if (!browser.WebResource.ContainsKey(requestUrl))
                {
                    browser.SetWebResource(requestUrl, webResource);
                }
            }
        }
        private void LocalResourceHandler_GetResponseHeaders(object sender, Chromium.Event.CfxGetResponseHeadersEventArgs e)
        {
            if (webResource == null)
            {
                e.Response.Status = 404;
            }
            else
            {
                e.ResponseLength    = webResourceData.Length;
                e.Response.MimeType = webResourceMimeType;
                e.Response.Status   = 200;

                //if (!WebResources.ContainsKey(requestUrl))
                //{
                browser.SetWebResource(requestUrl, webResource);
                //}
            }
        }
Esempio n. 5
0
        private void OnGetResponseHeaders(object sender, Chromium.Event.CfxGetResponseHeadersEventArgs e)
        {
            var statusCode = formiumResponse?.Status ?? (int)System.Net.HttpStatusCode.BadRequest;

            e.Response.Status = statusCode;

            if (statusCode == 200)
            {
                var length = formiumResponse.Length;
                e.ResponseLength    = (int)length;
                e.Response.MimeType = formiumResponse.MimeType;
                e.Response.Status   = 200;

                var headers = e.Response.GetHeaderMap();

                if (isPartContent)
                {
                    headers.Add(new string[2] {
                        "Accept-Ranges", "bytes"
                    });
                    var startPos = 0;
                    var endPos   = length - 1;



                    if (buffStartPostition.HasValue && buffEndPostition.HasValue)
                    {
                        startPos = buffStartPostition.Value;
                        endPos   = buffEndPostition.Value;
                    }
                    else if (!buffEndPostition.HasValue && buffStartPostition.HasValue)
                    {
                        startPos = buffStartPostition.Value;
                    }



                    headers.Add(new string[2] {
                        "Content-Range", $"bytes {startPos}-{endPos}/{formiumResponse.Length}"
                    });
                    headers.Add(new string[2] {
                        "Content-Length", $"{endPos - startPos + 1}"
                    });

                    e.ResponseLength = (endPos - startPos + 1);

                    e.Response.Status = 206;

                    var extraInfo = new List <ColorToken>(Info.ToArray());

                    extraInfo.Add("[Content-Range:".Cyan());
                    extraInfo.Add($"{startPos}-{endPos}/{formiumResponse.Length-1}".Gray());
                    extraInfo.Add("]".Cyan());

                    Bootstrap.Log(extraInfo.ToArray());
                }

                foreach (var header in formiumResponse.Headers)
                {
                    foreach (var value in header.Value)
                    {
                        headers.Add(new string[2] {
                            header.Key, value
                        });
                    }
                }


                e.Response.SetHeaderMap(headers);
            }
            else
            {
                Bootstrap.Log(Info.ToArray());
            }
        }
Esempio n. 6
0
 private void Handler_GetResponseHeaders(object sender, Chromium.Event.CfxGetResponseHeadersEventArgs e)
 {
     e.Response.MimeType = mimeType;
     e.ResponseLength    = buf.Length;
 }