diff --git a/CefSharp.Core/Internals/StreamAdapter.cpp b/CefSharp.Core/Internals/StreamAdapter.cpp index 9791afe1f..9319d741f 100644 --- a/CefSharp.Core/Internals/StreamAdapter.cpp +++ b/CefSharp.Core/Internals/StreamAdapter.cpp @@ -37,6 +37,11 @@ namespace CefSharp { System::IO::SeekOrigin seekOrigin; + if (!_stream->CanSeek) + { + return -1; + } + switch (whence) { case SEEK_CUR: @@ -76,6 +81,10 @@ namespace CefSharp bool StreamAdapter::MayBlock() { + if (isMemoryStream) + { + return false; + } return true; } } diff --git a/CefSharp.Core/Internals/StreamAdapter.h b/CefSharp.Core/Internals/StreamAdapter.h index 5b1162ac9..3afea54e0 100644 --- a/CefSharp.Core/Internals/StreamAdapter.h +++ b/CefSharp.Core/Internals/StreamAdapter.h @@ -17,6 +17,7 @@ namespace CefSharp { CriticalSection _syncRoot; gcroot _stream; + bool isMemoryStream = false; public: virtual ~StreamAdapter(); @@ -24,6 +25,7 @@ namespace CefSharp { //Reset stream position stream->Position = 0; + isMemoryStream = (dynamic_cast(stream)) != nullptr; } virtual size_t Read(void* ptr, size_t size, size_t n); diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 4dcd611d5..5479e1b1a 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -64,7 +64,9 @@ namespace CefSharp.Example if (handler != null) { const string responseBody = "

Success

This document is loaded from a System.IO.Stream

"; - handler.RegisterHandler(TestResourceUrl, ResourceHandler.FromString(responseBody)); + var response = ResourceHandler.FromString(responseBody); + response.Headers.Add("HeaderTest1", "HeaderTest1Value"); + handler.RegisterHandler(TestResourceUrl, response); const string unicodeResponseBody = "整体满意度"; handler.RegisterHandler(TestUnicodeResourceUrl, ResourceHandler.FromString(unicodeResponseBody)); diff --git a/CefSharp/ResourceHandler.cs b/CefSharp/ResourceHandler.cs index 276879862..25cab1c3f 100644 --- a/CefSharp/ResourceHandler.cs +++ b/CefSharp/ResourceHandler.cs @@ -49,6 +49,7 @@ namespace CefSharp StatusCode = 200; StatusText = "OK"; MimeType = "text/html"; + Headers = new NameValueCollection(); } /// @@ -60,6 +61,7 @@ namespace CefSharp StatusCode = 200; StatusText = "OK"; MimeType = mimeType; + Headers = new NameValueCollection(); } ///