コード例 #1
0
        public void IsSupportedContentTypes_DetectsTextHtmlInContentType()
        {
            string[] htmlContentTypes = new string[]
            {
                "text/html",
                "TEXT/hTmL",
                "text/html; charset=utf-8",
                "text/html; any parameter",
            };

            string[] nonHtmlContentTypes = new string[]
            {
                "text/htmlx",
                "text/html charset=utf-8",
                null,
                "",
                "text/htm",
            };

            foreach (string htmlContentType in htmlContentTypes)
            {
                Assert.True(ContentTypeUtil.IsSupportedContentTypes(htmlContentType), htmlContentType);
            }

            foreach (string nonHtmlContentType in nonHtmlContentTypes)
            {
                Assert.False(ContentTypeUtil.IsSupportedContentTypes(nonHtmlContentType), nonHtmlContentType);
            }
        }
コード例 #2
0
        public void IsSupportedContentTypes_DetectsXhtmlInContentType()
        {
            string[] xhtmlContentTypes = new string[]
            {
                "application/xhtml+xml",
                "APPLICATION/xhTml+Xml",
                "application/xhtml+xml; charset=utf-8",
                "application/xhtml+xml; any parameter",
            };

            string[] nonXhtmlContentTypes = new string[]
            {
                "application/xml",
                "application/xhtml+xml charset=utf-8",
                null,
                "",
                "application/xhtm",
            };

            foreach (string xhtmlContentType in xhtmlContentTypes)
            {
                Assert.True(ContentTypeUtil.IsSupportedContentTypes(xhtmlContentType), xhtmlContentType);
            }

            foreach (string nonXhtmlContentType in nonXhtmlContentTypes)
            {
                Assert.False(ContentTypeUtil.IsSupportedContentTypes(nonXhtmlContentType), nonXhtmlContentType);
            }
        }
コード例 #3
0
        private async Task ExecuteWithFilter(IHttpSocketAdapter injectScriptSocket, string requestId, HttpContext httpContext)
        {
            ScriptInjectionFilterContext filterContext = new ScriptInjectionFilterContext(httpContext);
            int currentPort = -1;

            PreprocessRequestHeader(httpContext, ref currentPort);

            RequestHeaders requestHeader = new RequestHeaders(httpContext.Request.Headers);

            if (currentPort == -1)
            {
                BrowserLinkMiddleWareUtil.RemoveETagAndTimeStamp(requestHeader);
            }

            using (ScriptInjectionFilterStream filter = new ScriptInjectionFilterStream(injectScriptSocket, filterContext))
            {
                httpContext.Response.Body = filter;
                httpContext.Response.OnStarting(delegate()
                {
                    if (ContentTypeUtil.IsSupportedContentTypes(httpContext.Response.ContentType))
                    {
                        httpContext.Response.ContentLength = null;
                    }

                    ResponseHeaders responseHeader = new ResponseHeaders(httpContext.Response.Headers);

                    BrowserLinkMiddleWareUtil.AddToETag(responseHeader, currentPort);

                    return(StaticTaskResult.True);
                });

                IHttpSendFileFeature originalSendFile = httpContext.Features.Get <IHttpSendFileFeature>();
                httpContext.Features.Set <IHttpSendFileFeature>(new SendFilesWrapper(originalSendFile, httpContext.Response));

                using (AddPageExecutionListenerFeatureTo(httpContext, requestId))
                {
                    await _next(httpContext);

                    await filter.WaitForFilterComplete();

                    if (filter.ScriptInjectionTimedOut)
                    {
                        _filterRequestTimeouts++;
                    }
                    else
                    {
                        _filterRequestTimeouts = 0;
                    }
                }
            }
        }
コード例 #4
0
        private void DetermineIfFilterShouldBePassthrough(byte[] buffer, int offset, int count)
        {
            string contentTypeFromHeader = _context.ResponseContentType;
            string path = _context.RequestPath;

            if (!ContentTypeUtil.IsSupportedContentTypes(contentTypeFromHeader))
            {
                CloseInjectScriptSocketAndBecomePassthrough();
            }

            else if (!ContentTypeUtil.IsHtml(path, buffer, offset, count))
            {
                CloseInjectScriptSocketAndBecomePassthrough();
            }
        }