public void IsHtml_DetectsNonHtmlInBuffer() { // Arrange byte[] buffer = Encoding.ASCII.GetBytes("var j = 10;"); // Act bool result = ContentTypeUtil.IsHtml("default.html", buffer, 0, buffer.Length); // Assert Assert.False(result); }
public void IsHtml_DetectsHtmlInBuffer() { // Arrange byte[] buffer = Encoding.ASCII.GetBytes("<html><head></head><body></body></html>"); // Act bool result = ContentTypeUtil.IsHtml("default.html", buffer, 0, buffer.Length); // Assert Assert.True(result); }
public void IsHtml_DetectsHtmlInBufferWithOffset() { // Arrange byte[] buffer = Encoding.ASCII.GetBytes("<html><head></head><body></body></html>"); byte[] bufferWithLeadingBytes = new byte[100 + buffer.Length]; Array.Copy(buffer, 0, bufferWithLeadingBytes, 100, buffer.Length); // Act bool result = ContentTypeUtil.IsHtml("default.html", bufferWithLeadingBytes, 100, buffer.Length); // Assert Assert.True(result); }
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(); } }