From 8ca8fde8a2f94e9446efc5aa68020c0badeecb4d Mon Sep 17 00:00:00 2001
From: Eli Zaretskii <eliz@gnu.org>
Date: Tue, 7 Oct 2014 20:18:07 +0300
Subject: [PATCH] Fix bug #18650 with warning about zlib when loading
 url-vars.el.

 src/decompress.c (init_zlib_functions): Move the message about zlib
 being unavailable from here...
 (Fzlib_decompress_region): ...to here.

 lisp/url/url-http.el (url-http-create-request): Recheck zlib availability
 on windows-nt each time it might be required.
---
 lisp/url/ChangeLog   |  5 +++++
 lisp/url/url-http.el |  9 ++++++++-
 src/ChangeLog        |  6 ++++++
 src/decompress.c     | 10 +++++-----
 4 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/lisp/url/ChangeLog b/lisp/url/ChangeLog
index 81096cfb800..21a779f85b3 100644
--- a/lisp/url/ChangeLog
+++ b/lisp/url/ChangeLog
@@ -1,3 +1,8 @@
+2014-10-07  Eli Zaretskii  <eliz@gnu.org>
+
+	* url-http.el (url-http-create-request): Recheck zlib availability
+	on windows-nt each time it might be required.  (Bug#18650)
+
 2014-09-28  Ulf Jasper  <ulf.jasper@web.de>
 
 	* url-gw.el (url-open-stream): New optional parameter
diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
index 9a874c25ce0..f9fbea1ba74 100644
--- a/lisp/url/url-http.el
+++ b/lisp/url/url-http.el
@@ -313,7 +313,14 @@ request.")
                  (concat
                   "From: " url-personal-mail-address "\r\n"))
              ;; Encodings we understand
-             (if url-mime-encoding-string
+             (if (or url-mime-encoding-string
+		     ;; MS-Windows loads zlib dynamically, so recheck
+		     ;; in case they made it available since
+		     ;; initialization in url-vars.el.
+		     (and (eq 'system-type 'windows-nt)
+			  (fboundp 'zlib-available-p)
+			  (zlib-available-p)
+			  (setq url-mime-encoding-string "gzip")))
                  (concat
                   "Accept-encoding: " url-mime-encoding-string "\r\n"))
              (if url-mime-charset-string
diff --git a/src/ChangeLog b/src/ChangeLog
index b57c76d5e3f..7a6b38f3b90 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-07  Eli Zaretskii  <eliz@gnu.org>
+
+	* decompress.c (init_zlib_functions): Move the message about zlib
+	being unavailable from here...
+	(Fzlib_decompress_region): ...to here.  (Bug#18650)
+
 2014-10-07  Dmitry Antipov  <dmantipov@yandex.ru>
 
 	* font.c (Ffont_get_glyphs): Use validate_subarray and fix
diff --git a/src/decompress.c b/src/decompress.c
index cd8a3d1e962..24ce852245c 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -60,10 +60,7 @@ init_zlib_functions (void)
   HMODULE library = w32_delayed_load (Qzlib_dll);
 
   if (!library)
-    {
-      message1 ("zlib library not found");
-      return false;
-    }
+    return false;
 
   LOAD_ZLIB_FN (library, inflateInit2_);
   LOAD_ZLIB_FN (library, inflate);
@@ -150,7 +147,10 @@ This function can be called only in unibyte buffers.  */)
   if (!zlib_initialized)
     zlib_initialized = init_zlib_functions ();
   if (!zlib_initialized)
-    return Qnil;
+    {
+      message1 ("zlib library not found");
+      return Qnil;
+    }
 #endif
 
   /* This is a unibyte buffer, so character positions and bytes are
-- 
2.39.5