commit 4f5ea042f653e7529afad9fbd08c979d77727029
Author: Francois Gouget <fgouget@free.fr>
Date:   Sun Feb 15 12:29:44 2015 +0100

    wininet: Remove the dependency on Z_SOLO for gzip support.
    
    Z_SOLO was needed to prevent zlib.h from including unistd.h as this causes a conflict with ws2tcpip.h. However that's really a zlib implementation detail and not supported in all versions. So instead this patch isolates the winsock parts from the zlib one.

diff --git a/dlls/wininet/Makefile.in b/dlls/wininet/Makefile.in
index be69ea5..46a094f 100644
--- a/dlls/wininet/Makefile.in
+++ b/dlls/wininet/Makefile.in
@@ -9,6 +9,7 @@ C_SRCS = \
 	cookie.c \
 	dialogs.c \
 	ftp.c \
+	gzip_stream.c \
 	gopher.c \
 	http.c \
 	internet.c \
diff --git a/dlls/wininet/data_stream.h b/dlls/wininet/data_stream.h
new file mode 100644
index 0000000..f56e57e
--- /dev/null
+++ b/dlls/wininet/data_stream.h
@@ -0,0 +1,53 @@
+/*
+ * Wininet
+ *
+ * Copyright 1999 Corel Corporation
+ *
+ * Ulrich Czekalla
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _WINE_DATA_STREAM_H_
+#define _WINE_DATA_STREAM_H_
+
+#define READ_BUFFER_SIZE 8192
+
+typedef struct http_request_t http_request_t;
+typedef struct data_stream_t data_stream_t;
+
+typedef enum {
+    BLOCKING_ALLOW,
+    BLOCKING_DISALLOW,
+    BLOCKING_WAITALL
+} blocking_mode_t;
+
+typedef struct {
+    DWORD (*get_avail_data)(data_stream_t*,http_request_t*);
+    BOOL (*end_of_data)(data_stream_t*,http_request_t*);
+    DWORD (*read)(data_stream_t*,http_request_t*,BYTE*,DWORD,DWORD*,blocking_mode_t);
+    BOOL (*drain_content)(data_stream_t*,http_request_t*);
+    void (*destroy)(data_stream_t*);
+} data_stream_vtbl_t;
+
+struct data_stream_t {
+    const data_stream_vtbl_t *vtbl;
+};
+
+typedef struct gzip_stream_t gzip_stream_t;
+extern gzip_stream_t* new_gzip_stream(BOOL) DECLSPEC_HIDDEN;
+extern void init_gzip_stream(gzip_stream_t*,data_stream_t*,BYTE*,DWORD*,DWORD*) DECLSPEC_HIDDEN;
+
+#endif /* _WINE_DATA_STREAM_H_ */
diff --git a/dlls/wininet/gzip_stream.c b/dlls/wininet/gzip_stream.c
new file mode 100644
index 0000000..324907d
--- /dev/null
+++ b/dlls/wininet/gzip_stream.c
@@ -0,0 +1,220 @@
+/*
+ * Wininet - HTTP Implementation
+ *
+ * Copyright 1999 Corel Corporation
+ * Copyright 2002 CodeWeavers Inc.
+ * Copyright 2002 TransGaming Technologies Inc.
+ * Copyright 2004 Mike McCormack for CodeWeavers
+ * Copyright 2005 Aric Stewart for CodeWeavers
+ * Copyright 2006 Robert Shearman for CodeWeavers
+ * Copyright 2011 Jacek Caban for CodeWeavers
+ *
+ * Ulrich Czekalla
+ * David Hammerton
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+
+#ifdef HAVE_ZLIB
+#  include <zlib.h>
+#endif
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "windef.h"
+#include "winbase.h"
+#include "wininet.h"
+
+#include "heap.h"
+#include "data_stream.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(wininet);
+
+
+#ifdef HAVE_ZLIB
+
+struct gzip_stream_t {
+    data_stream_t stream;
+    data_stream_t *parent_stream;
+    z_stream zstream;
+    BYTE buf[READ_BUFFER_SIZE];
+    DWORD buf_size;
+    DWORD buf_pos;
+    BOOL end_of_data;
+};
+
+static DWORD gzip_get_avail_data(data_stream_t *stream, http_request_t *req)
+{
+    /* Allow reading only from read buffer */
+    return 0;
+}
+
+static BOOL gzip_end_of_data(data_stream_t *stream, http_request_t *req)
+{
+    gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
+    return gzip_stream->end_of_data
+        || (!gzip_stream->buf_size && gzip_stream->parent_stream->vtbl->end_of_data(gzip_stream->parent_stream, req));
+}
+
+static DWORD gzip_read(data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size,
+        DWORD *read, blocking_mode_t blocking_mode)
+{
+    gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
+    z_stream *zstream = &gzip_stream->zstream;
+    DWORD current_read, ret_read = 0;
+    int zres;
+    DWORD res = ERROR_SUCCESS;
+
+    TRACE("(%d %d)\n", size, blocking_mode);
+
+    while(size && !gzip_stream->end_of_data) {
+        if(!gzip_stream->buf_size) {
+            if(gzip_stream->buf_pos) {
+                if(gzip_stream->buf_size)
+                    memmove(gzip_stream->buf, gzip_stream->buf+gzip_stream->buf_pos, gzip_stream->buf_size);
+                gzip_stream->buf_pos = 0;
+            }
+            res = gzip_stream->parent_stream->vtbl->read(gzip_stream->parent_stream, req, gzip_stream->buf+gzip_stream->buf_size,
+                    sizeof(gzip_stream->buf)-gzip_stream->buf_size, &current_read, blocking_mode);
+            gzip_stream->buf_size += current_read;
+            if(res != ERROR_SUCCESS)
+                break;
+
+            if(!current_read) {
+                if(blocking_mode != BLOCKING_DISALLOW) {
+                    WARN("unexpected end of data\n");
+                    gzip_stream->end_of_data = TRUE;
+                }
+                break;
+            }
+        }
+
+        zstream->next_in = gzip_stream->buf+gzip_stream->buf_pos;
+        zstream->avail_in = gzip_stream->buf_size;
+        zstream->next_out = buf+ret_read;
+        zstream->avail_out = size;
+        zres = inflate(&gzip_stream->zstream, 0);
+        current_read = size - zstream->avail_out;
+        size -= current_read;
+        ret_read += current_read;
+        gzip_stream->buf_size -= zstream->next_in - (gzip_stream->buf+gzip_stream->buf_pos);
+        gzip_stream->buf_pos = zstream->next_in-gzip_stream->buf;
+        if(zres == Z_STREAM_END) {
+            TRACE("end of data\n");
+            gzip_stream->end_of_data = TRUE;
+            inflateEnd(zstream);
+        }else if(zres != Z_OK) {
+            WARN("inflate failed %d: %s\n", zres, debugstr_a(zstream->msg));
+            if(!ret_read)
+                res = ERROR_INTERNET_DECODING_FAILED;
+            break;
+        }
+
+        if(ret_read && blocking_mode == BLOCKING_ALLOW)
+            blocking_mode = BLOCKING_DISALLOW;
+    }
+
+    TRACE("read %u bytes\n", ret_read);
+    *read = ret_read;
+    return res;
+}
+
+static BOOL gzip_drain_content(data_stream_t *stream, http_request_t *req)
+{
+    gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
+    return gzip_stream->parent_stream->vtbl->drain_content(gzip_stream->parent_stream, req);
+}
+
+static void gzip_destroy(data_stream_t *stream)
+{
+    gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
+
+    gzip_stream->parent_stream->vtbl->destroy(gzip_stream->parent_stream);
+
+    if(!gzip_stream->end_of_data)
+        inflateEnd(&gzip_stream->zstream);
+    heap_free(gzip_stream);
+}
+
+static const data_stream_vtbl_t gzip_stream_vtbl = {
+    gzip_get_avail_data,
+    gzip_end_of_data,
+    gzip_read,
+    gzip_drain_content,
+    gzip_destroy
+};
+
+static voidpf wininet_zalloc(voidpf opaque, uInt items, uInt size)
+{
+    return heap_alloc(items*size);
+}
+
+static void wininet_zfree(voidpf opaque, voidpf address)
+{
+    heap_free(address);
+}
+
+gzip_stream_t* new_gzip_stream(BOOL is_gzip)
+{
+    gzip_stream_t *gzip_stream;
+    int zres;
+
+    gzip_stream = heap_alloc_zero(sizeof(gzip_stream_t));
+    if(!gzip_stream)
+        return NULL;
+
+    gzip_stream->stream.vtbl = &gzip_stream_vtbl;
+    gzip_stream->zstream.zalloc = wininet_zalloc;
+    gzip_stream->zstream.zfree = wininet_zfree;
+
+    zres = inflateInit2(&gzip_stream->zstream, is_gzip ? 0x1f : -15);
+    if(zres != Z_OK) {
+        ERR("inflateInit failed: %d\n", zres);
+        heap_free(gzip_stream);
+        return NULL;
+    }
+    return gzip_stream;
+}
+
+void init_gzip_stream(gzip_stream_t* gzip_stream, data_stream_t* parent_stream,
+                      BYTE* read_buf, DWORD *read_pos, DWORD *read_size)
+{
+    if(read_size) {
+        memcpy(gzip_stream->buf, read_buf+*read_pos, *read_size);
+        gzip_stream->buf_size = *read_size;
+        *read_pos = *read_size = 0;
+    }
+
+    gzip_stream->parent_stream = parent_stream;
+}
+
+#else
+
+gzip_stream_t* new_gzip_stream(BOOL is_gzip)
+{
+    ERR("gzip stream not supported, missing zlib.\n");
+    return NULL;
+}
+
+void init_gzip_stream(gzip_stream_t* gzip_stream, data_stream_t* parent_stream,
+                      BYTE* read_buf, DWORD *read_pos, DWORD *read_size)
+{
+}
+
+#endif
diff --git a/dlls/wininet/heap.h b/dlls/wininet/heap.h
new file mode 100644
index 0000000..036c823
--- /dev/null
+++ b/dlls/wininet/heap.h
@@ -0,0 +1,135 @@
+/*
+ * Wininet
+ *
+ * Copyright 1999 Corel Corporation
+ *
+ * Ulrich Czekalla
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef _WINE_HEAP_H_
+#define _WINE_HEAP_H_
+
+#include "wine/unicode.h"
+
+static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
+{
+    return HeapAlloc(GetProcessHeap(), 0, len);
+}
+
+static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
+{
+    return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
+}
+
+static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
+{
+    return HeapReAlloc(GetProcessHeap(), 0, mem, len);
+}
+
+static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
+{
+    return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
+}
+
+static inline BOOL heap_free(void *mem)
+{
+    return HeapFree(GetProcessHeap(), 0, mem);
+}
+
+static inline LPWSTR heap_strdupW(LPCWSTR str)
+{
+    LPWSTR ret = NULL;
+
+    if(str) {
+        DWORD size;
+
+        size = (strlenW(str)+1)*sizeof(WCHAR);
+        ret = heap_alloc(size);
+        if(ret)
+            memcpy(ret, str, size);
+    }
+
+    return ret;
+}
+
+static inline char *heap_strdupA(const char *str)
+{
+    char *ret = NULL;
+
+    if(str) {
+        DWORD size = strlen(str)+1;
+
+        ret = heap_alloc(size);
+        if(ret)
+            memcpy(ret, str, size);
+    }
+
+    return ret;
+}
+
+static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
+{
+    LPWSTR ret;
+    UINT len;
+
+    if(!str)
+        return NULL;
+
+    for(len=0; len<max_len; len++)
+        if(str[len] == '\0')
+            break;
+
+    ret = heap_alloc(sizeof(WCHAR)*(len+1));
+    if(ret) {
+        memcpy(ret, str, sizeof(WCHAR)*len);
+        ret[len] = '\0';
+    }
+
+    return ret;
+}
+
+static inline WCHAR *heap_strdupAtoW(const char *str)
+{
+    LPWSTR ret = NULL;
+
+    if(str) {
+        DWORD len;
+
+        len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+        ret = heap_alloc(len*sizeof(WCHAR));
+        if(ret)
+            MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
+    }
+
+    return ret;
+}
+
+static inline char *heap_strdupWtoA(LPCWSTR str)
+{
+    char *ret = NULL;
+
+    if(str) {
+        DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
+        ret = heap_alloc(size);
+        if(ret)
+            WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
+    }
+
+    return ret;
+}
+
+#endif /* _WINE_HEAP_H_ */
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 59c358c..2ffe2a1 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -27,13 +27,6 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include "config.h"
-
-#ifdef HAVE_ZLIB
-#  define Z_SOLO
-#  include <zlib.h>
-#endif
-
 #include "ws2tcpip.h"
 
 #include <stdarg.h>
@@ -381,14 +374,6 @@ static WCHAR *get_host_header( http_request_t *req )
     return ret;
 }
 
-struct data_stream_vtbl_t {
-    DWORD (*get_avail_data)(data_stream_t*,http_request_t*);
-    BOOL (*end_of_data)(data_stream_t*,http_request_t*);
-    DWORD (*read)(data_stream_t*,http_request_t*,BYTE*,DWORD,DWORD*,blocking_mode_t);
-    BOOL (*drain_content)(data_stream_t*,http_request_t*);
-    void (*destroy)(data_stream_t*);
-};
-
 typedef struct {
     data_stream_t data_stream;
 
@@ -421,172 +406,6 @@ static void remove_header( http_request_t *request, const WCHAR *str, BOOL from_
     LeaveCriticalSection( &request->headers_section );
 }
 
-#ifdef HAVE_ZLIB
-
-typedef struct {
-    data_stream_t stream;
-    data_stream_t *parent_stream;
-    z_stream zstream;
-    BYTE buf[READ_BUFFER_SIZE];
-    DWORD buf_size;
-    DWORD buf_pos;
-    BOOL end_of_data;
-} gzip_stream_t;
-
-static DWORD gzip_get_avail_data(data_stream_t *stream, http_request_t *req)
-{
-    /* Allow reading only from read buffer */
-    return 0;
-}
-
-static BOOL gzip_end_of_data(data_stream_t *stream, http_request_t *req)
-{
-    gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
-    return gzip_stream->end_of_data
-        || (!gzip_stream->buf_size && gzip_stream->parent_stream->vtbl->end_of_data(gzip_stream->parent_stream, req));
-}
-
-static DWORD gzip_read(data_stream_t *stream, http_request_t *req, BYTE *buf, DWORD size,
-        DWORD *read, blocking_mode_t blocking_mode)
-{
-    gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
-    z_stream *zstream = &gzip_stream->zstream;
-    DWORD current_read, ret_read = 0;
-    int zres;
-    DWORD res = ERROR_SUCCESS;
-
-    TRACE("(%d %d)\n", size, blocking_mode);
-
-    while(size && !gzip_stream->end_of_data) {
-        if(!gzip_stream->buf_size) {
-            if(gzip_stream->buf_pos) {
-                if(gzip_stream->buf_size)
-                    memmove(gzip_stream->buf, gzip_stream->buf+gzip_stream->buf_pos, gzip_stream->buf_size);
-                gzip_stream->buf_pos = 0;
-            }
-            res = gzip_stream->parent_stream->vtbl->read(gzip_stream->parent_stream, req, gzip_stream->buf+gzip_stream->buf_size,
-                    sizeof(gzip_stream->buf)-gzip_stream->buf_size, &current_read, blocking_mode);
-            gzip_stream->buf_size += current_read;
-            if(res != ERROR_SUCCESS)
-                break;
-
-            if(!current_read) {
-                if(blocking_mode != BLOCKING_DISALLOW) {
-                    WARN("unexpected end of data\n");
-                    gzip_stream->end_of_data = TRUE;
-                }
-                break;
-            }
-        }
-
-        zstream->next_in = gzip_stream->buf+gzip_stream->buf_pos;
-        zstream->avail_in = gzip_stream->buf_size;
-        zstream->next_out = buf+ret_read;
-        zstream->avail_out = size;
-        zres = inflate(&gzip_stream->zstream, 0);
-        current_read = size - zstream->avail_out;
-        size -= current_read;
-        ret_read += current_read;
-        gzip_stream->buf_size -= zstream->next_in - (gzip_stream->buf+gzip_stream->buf_pos);
-        gzip_stream->buf_pos = zstream->next_in-gzip_stream->buf;
-        if(zres == Z_STREAM_END) {
-            TRACE("end of data\n");
-            gzip_stream->end_of_data = TRUE;
-            inflateEnd(zstream);
-        }else if(zres != Z_OK) {
-            WARN("inflate failed %d: %s\n", zres, debugstr_a(zstream->msg));
-            if(!ret_read)
-                res = ERROR_INTERNET_DECODING_FAILED;
-            break;
-        }
-
-        if(ret_read && blocking_mode == BLOCKING_ALLOW)
-            blocking_mode = BLOCKING_DISALLOW;
-    }
-
-    TRACE("read %u bytes\n", ret_read);
-    *read = ret_read;
-    return res;
-}
-
-static BOOL gzip_drain_content(data_stream_t *stream, http_request_t *req)
-{
-    gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
-    return gzip_stream->parent_stream->vtbl->drain_content(gzip_stream->parent_stream, req);
-}
-
-static void gzip_destroy(data_stream_t *stream)
-{
-    gzip_stream_t *gzip_stream = (gzip_stream_t*)stream;
-
-    destroy_data_stream(gzip_stream->parent_stream);
-
-    if(!gzip_stream->end_of_data)
-        inflateEnd(&gzip_stream->zstream);
-    heap_free(gzip_stream);
-}
-
-static const data_stream_vtbl_t gzip_stream_vtbl = {
-    gzip_get_avail_data,
-    gzip_end_of_data,
-    gzip_read,
-    gzip_drain_content,
-    gzip_destroy
-};
-
-static voidpf wininet_zalloc(voidpf opaque, uInt items, uInt size)
-{
-    return heap_alloc(items*size);
-}
-
-static void wininet_zfree(voidpf opaque, voidpf address)
-{
-    heap_free(address);
-}
-
-static DWORD init_gzip_stream(http_request_t *req, BOOL is_gzip)
-{
-    gzip_stream_t *gzip_stream;
-    int zres;
-
-    gzip_stream = heap_alloc_zero(sizeof(gzip_stream_t));
-    if(!gzip_stream)
-        return ERROR_OUTOFMEMORY;
-
-    gzip_stream->stream.vtbl = &gzip_stream_vtbl;
-    gzip_stream->zstream.zalloc = wininet_zalloc;
-    gzip_stream->zstream.zfree = wininet_zfree;
-
-    zres = inflateInit2(&gzip_stream->zstream, is_gzip ? 0x1f : -15);
-    if(zres != Z_OK) {
-        ERR("inflateInit failed: %d\n", zres);
-        heap_free(gzip_stream);
-        return ERROR_OUTOFMEMORY;
-    }
-
-    remove_header(req, szContent_Length, FALSE);
-
-    if(req->read_size) {
-        memcpy(gzip_stream->buf, req->read_buf+req->read_pos, req->read_size);
-        gzip_stream->buf_size = req->read_size;
-        req->read_pos = req->read_size = 0;
-    }
-
-    req->read_gzip = TRUE;
-    gzip_stream->parent_stream = req->data_stream;
-    req->data_stream = &gzip_stream->stream;
-    return ERROR_SUCCESS;
-}
-
-#else
-
-static DWORD init_gzip_stream(http_request_t *req, BOOL is_gzip)
-{
-    ERR("gzip stream not supported, missing zlib.\n");
-    return ERROR_SUCCESS;
-}
-
-#endif
 
 /***********************************************************************
  *           HTTP_FreeTokens (internal)
@@ -2913,6 +2732,23 @@ static const data_stream_vtbl_t chunked_stream_vtbl = {
     chunked_destroy
 };
 
+DWORD get_gzip_stream(http_request_t *req, BOOL is_gzip)
+{
+    gzip_stream_t *gzip_stream;
+
+    gzip_stream = new_gzip_stream(is_gzip);
+    if(!gzip_stream)
+        return ERROR_OUTOFMEMORY;
+
+    remove_header(req, szContent_Length, FALSE);
+
+    init_gzip_stream(gzip_stream, req->data_stream, req->read_buf,
+                     &req->read_pos, &req->read_size);
+    req->data_stream = (data_stream_t*)gzip_stream;
+    req->read_gzip = TRUE;
+    return ERROR_SUCCESS;
+}
+
 /* set the request content length based on the headers */
 static DWORD set_content_length(http_request_t *request)
 {
@@ -2972,12 +2808,12 @@ static DWORD set_content_length(http_request_t *request)
             if(!strcmpiW(request->custHeaders[encoding_idx].lpszValue, gzipW)) {
                 HTTP_DeleteCustomHeader(request, encoding_idx);
                 LeaveCriticalSection( &request->headers_section );
-                return init_gzip_stream(request, TRUE);
+                return get_gzip_stream(request, TRUE);
             }
             if(!strcmpiW(request->custHeaders[encoding_idx].lpszValue, deflateW)) {
                 HTTP_DeleteCustomHeader(request, encoding_idx);
                 LeaveCriticalSection( &request->headers_section );
-                return init_gzip_stream(request, FALSE);
+                return get_gzip_stream(request, FALSE);
             }
         }
 
diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h
index 19ab497..73a8d10 100644
--- a/dlls/wininet/internet.h
+++ b/dlls/wininet/internet.h
@@ -23,10 +23,11 @@
 #ifndef _WINE_INTERNET_H_
 #define _WINE_INTERNET_H_
 
-#include "wine/unicode.h"
 #include "wine/list.h"
 
 #include "winineti.h"
+#include "data_stream.h"
+#include "heap.h"
 
 extern HMODULE WININET_hModule DECLSPEC_HIDDEN;
 
@@ -86,112 +87,7 @@ typedef struct
 BOOL is_valid_netconn(netconn_t *) DECLSPEC_HIDDEN;
 void close_netconn(netconn_t *) DECLSPEC_HIDDEN;
 
-static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
-{
-    return HeapAlloc(GetProcessHeap(), 0, len);
-}
-
-static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
-{
-    return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
-}
-
-static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
-{
-    return HeapReAlloc(GetProcessHeap(), 0, mem, len);
-}
-
-static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
-{
-    return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
-}
-
-static inline BOOL heap_free(void *mem)
-{
-    return HeapFree(GetProcessHeap(), 0, mem);
-}
-
-static inline LPWSTR heap_strdupW(LPCWSTR str)
-{
-    LPWSTR ret = NULL;
-
-    if(str) {
-        DWORD size;
 
-        size = (strlenW(str)+1)*sizeof(WCHAR);
-        ret = heap_alloc(size);
-        if(ret)
-            memcpy(ret, str, size);
-    }
-
-    return ret;
-}
-
-static inline char *heap_strdupA(const char *str)
-{
-    char *ret = NULL;
-
-    if(str) {
-        DWORD size = strlen(str)+1;
-
-        ret = heap_alloc(size);
-        if(ret)
-            memcpy(ret, str, size);
-    }
-
-    return ret;
-}
-
-static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
-{
-    LPWSTR ret;
-    UINT len;
-
-    if(!str)
-        return NULL;
-
-    for(len=0; len<max_len; len++)
-        if(str[len] == '\0')
-            break;
-
-    ret = heap_alloc(sizeof(WCHAR)*(len+1));
-    if(ret) {
-        memcpy(ret, str, sizeof(WCHAR)*len);
-        ret[len] = '\0';
-    }
-
-    return ret;
-}
-
-static inline WCHAR *heap_strdupAtoW(const char *str)
-{
-    LPWSTR ret = NULL;
-
-    if(str) {
-        DWORD len;
-
-        len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
-        ret = heap_alloc(len*sizeof(WCHAR));
-        if(ret)
-            MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
-    }
-
-    return ret;
-}
-
-static inline char *heap_strdupWtoA(LPCWSTR str)
-{
-    char *ret = NULL;
-
-    if(str) {
-        DWORD size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
-        ret = heap_alloc(size);
-        if(ret)
-            WideCharToMultiByte(CP_ACP, 0, str, -1, ret, size, NULL, NULL);
-    }
-
-    return ret;
-}
 
 static inline void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
 {
@@ -307,21 +203,13 @@ typedef struct
 
 struct HttpAuthInfo;
 
-typedef struct data_stream_vtbl_t data_stream_vtbl_t;
-
-typedef struct {
-    const data_stream_vtbl_t *vtbl;
-}  data_stream_t;
-
 typedef struct {
     data_stream_t data_stream;
     DWORD content_length;
     DWORD content_read;
 } netconn_stream_t;
 
-#define READ_BUFFER_SIZE 8192
-
-typedef struct
+struct http_request_t
 {
     object_header_t hdr;
     http_session_t *session;
@@ -362,7 +250,7 @@ typedef struct
     BOOL decoding;
     data_stream_t *data_stream;
     netconn_stream_t netconn_stream;
-} http_request_t;
+};
 
 typedef struct task_header_t task_header_t;
 typedef void (*async_task_proc_t)(task_header_t*);
@@ -415,12 +303,6 @@ VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext,
                            DWORD dwStatusInfoLength) DECLSPEC_HIDDEN;
 BOOL INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto, WCHAR *foundProxy, DWORD *foundProxyLen) DECLSPEC_HIDDEN;
 
-typedef enum {
-    BLOCKING_ALLOW,
-    BLOCKING_DISALLOW,
-    BLOCKING_WAITALL
-} blocking_mode_t;
-
 DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN;
 void free_netconn(netconn_t*) DECLSPEC_HIDDEN;
 void NETCON_unload(void) DECLSPEC_HIDDEN;
