[libgepub] Serve empty documents when path not found



commit d15928f8634ba2abe9b20bee5797f8efc39d38ed
Author: Chris Lee <clee mg8 org>
Date:   Sat Feb 24 13:14:11 2018 -0700

    Serve empty documents when path not found
    
    Instead of not serving anything at all, serving an empty document
    when a resource is not found will usually let the epub render properly.

 libgepub/gepub-widget.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/libgepub/gepub-widget.c b/libgepub/gepub-widget.c
index 5ec0685..41b9986 100644
--- a/libgepub/gepub-widget.c
+++ b/libgepub/gepub-widget.c
@@ -261,9 +261,16 @@ resource_callback (WebKitURISchemeRequest *request, gpointer user_data)
     contents = gepub_doc_get_resource (widget->doc, path);
     mime = gepub_doc_get_resource_mime (widget->doc, path);
 
+    // if the resource requested doesn't exist, we should serve an
+    // empty document instead of nothing at all (otherwise some
+    // poorly-structured ebooks will fail to render).
+    if (!contents) {
+        contents = g_byte_array_free_to_bytes(g_byte_array_sized_new(0));
+        mime = g_strdup("application/octet-stream");
+    }
+
     if (!mime) {
-        g_free (uri);
-        return;
+        mime = g_strdup("application/octet-stream");
     }
 
     stream = g_memory_input_stream_new_from_bytes (contents);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]