diff options
Diffstat (limited to 'src/examples/http_compression.c')
-rw-r--r-- | src/examples/http_compression.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/src/examples/http_compression.c b/src/examples/http_compression.c index 1324fa4d..af153f6e 100644 --- a/src/examples/http_compression.c +++ b/src/examples/http_compression.c | |||
@@ -77,11 +77,11 @@ body_compress (void **buf, | |||
77 | *buf_size); | 77 | *buf_size); |
78 | if ((Z_OK != ret) || | 78 | if ((Z_OK != ret) || |
79 | (cbuf_size >= *buf_size)) | 79 | (cbuf_size >= *buf_size)) |
80 | { | 80 | { |
81 | /* compression failed */ | 81 | /* compression failed */ |
82 | free (cbuf); | 82 | free (cbuf); |
83 | return MHD_NO; | 83 | return MHD_NO; |
84 | } | 84 | } |
85 | free (*buf); | 85 | free (*buf); |
86 | *buf = (void *) cbuf; | 86 | *buf = (void *) cbuf; |
87 | *buf_size = (size_t) cbuf_size; | 87 | *buf_size = (size_t) cbuf_size; |
@@ -109,18 +109,18 @@ ahc_echo (void *cls, | |||
109 | 109 | ||
110 | if (0 != strcmp (method, "GET")) | 110 | if (0 != strcmp (method, "GET")) |
111 | return MHD_NO; /* unexpected method */ | 111 | return MHD_NO; /* unexpected method */ |
112 | if (!*ptr) | 112 | if (! *ptr) |
113 | { | 113 | { |
114 | *ptr = (void *) 1; | 114 | *ptr = (void *) 1; |
115 | return MHD_YES; | 115 | return MHD_YES; |
116 | } | 116 | } |
117 | *ptr = NULL; | 117 | *ptr = NULL; |
118 | 118 | ||
119 | body_str = strdup (PAGE); | 119 | body_str = strdup (PAGE); |
120 | if (NULL == body_str) | 120 | if (NULL == body_str) |
121 | { | 121 | { |
122 | return MHD_NO; | 122 | return MHD_NO; |
123 | } | 123 | } |
124 | body_len = strlen (body_str); | 124 | body_len = strlen (body_str); |
125 | /* try to compress the body */ | 125 | /* try to compress the body */ |
126 | comp = MHD_NO; | 126 | comp = MHD_NO; |
@@ -132,23 +132,23 @@ ahc_echo (void *cls, | |||
132 | body_str, | 132 | body_str, |
133 | MHD_RESPMEM_MUST_FREE); | 133 | MHD_RESPMEM_MUST_FREE); |
134 | if (NULL == response) | 134 | if (NULL == response) |
135 | { | 135 | { |
136 | free (body_str); | 136 | free (body_str); |
137 | return MHD_NO; | 137 | return MHD_NO; |
138 | } | 138 | } |
139 | 139 | ||
140 | if (MHD_YES == comp) | 140 | if (MHD_YES == comp) |
141 | { | ||
142 | /* Need to indicate to client that body is compressed */ | ||
143 | if (MHD_NO == | ||
144 | MHD_add_response_header (response, | ||
145 | MHD_HTTP_HEADER_CONTENT_ENCODING, | ||
146 | "deflate")) | ||
141 | { | 147 | { |
142 | /* Need to indicate to client that body is compressed */ | 148 | MHD_destroy_response (response); |
143 | if (MHD_NO == | 149 | return MHD_NO; |
144 | MHD_add_response_header (response, | ||
145 | MHD_HTTP_HEADER_CONTENT_ENCODING, | ||
146 | "deflate")) | ||
147 | { | ||
148 | MHD_destroy_response (response); | ||
149 | return MHD_NO; | ||
150 | } | ||
151 | } | 150 | } |
151 | } | ||
152 | ret = MHD_queue_response (connection, | 152 | ret = MHD_queue_response (connection, |
153 | 200, | 153 | 200, |
154 | response); | 154 | response); |
@@ -162,11 +162,12 @@ main (int argc, char *const *argv) | |||
162 | struct MHD_Daemon *d; | 162 | struct MHD_Daemon *d; |
163 | 163 | ||
164 | if (argc != 2) | 164 | if (argc != 2) |
165 | { | 165 | { |
166 | printf ("%s PORT\n", argv[0]); | 166 | printf ("%s PORT\n", argv[0]); |
167 | return 1; | 167 | return 1; |
168 | } | 168 | } |
169 | d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 169 | d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD |
170 | | MHD_USE_ERROR_LOG, | ||
170 | atoi (argv[1]), NULL, NULL, | 171 | atoi (argv[1]), NULL, NULL, |
171 | &ahc_echo, NULL, | 172 | &ahc_echo, NULL, |
172 | MHD_OPTION_END); | 173 | MHD_OPTION_END); |