commit d7a7a47de56eebd2d1bd31fa74240dfda9929649
parent 38fad29b451f60898f2bbbaccc39dc97b86f5fe2
Author: Andrey Uzunov <andrey.uzunov@gmail.com>
Date: Sun, 8 Dec 2013 22:05:57 +0000
mhd2spdy: minor bugs fixed
Diffstat:
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/src/examples/mhd2spdy_http.c b/src/examples/mhd2spdy_http.c
@@ -172,6 +172,7 @@ http_cb_request (void *cls,
struct SPDY_Headers spdy_headers;
bool with_body = false;
struct HTTP_URI *http_uri;
+ const char *header_value;
if (NULL == ptr || NULL == *ptr)
return MHD_NO;
@@ -250,9 +251,11 @@ http_cb_request (void *cls,
proxy->url = http_uri->uri;
+ header_value = MHD_lookup_connection_value(connection,
+ MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH);
+
with_body = 0 == strcmp (method, MHD_HTTP_METHOD_POST)
- && 0 != strcmp ("0",
- MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH));
+ && (NULL == header_value || 0 != strcmp ("0", header_value));
PRINT_INFO2("body will be sent %i", with_body);
diff --git a/src/examples/mhd2spdy_spdy.c b/src/examples/mhd2spdy_spdy.c
@@ -727,7 +727,7 @@ spdy_connect(const struct URI *uri,
spdylay_session_callbacks callbacks;
int fd;
SSL *ssl=NULL;
- struct SPDY_Connection * connection;
+ struct SPDY_Connection * connection = NULL;
int rv;
spdy_setup_spdylay_callbacks(&callbacks);
@@ -757,11 +757,7 @@ spdy_connect(const struct URI *uri,
{
PRINT_INFO("Closing SSL");
//no spdy on the other side
- SSL_shutdown(ssl);
- close(fd);
- SSL_free(ssl);
-
- return NULL;
+ goto free_and_fail;
}
}
else
@@ -770,12 +766,13 @@ spdy_connect(const struct URI *uri,
}
if(NULL == (connection = au_malloc(sizeof(struct SPDY_Connection))))
- return NULL;
+ goto free_and_fail;
connection->is_tls = is_tls;
connection->ssl = ssl;
connection->want_io = IO_NONE;
- connection->host = strdup(uri->host);
+ if(NULL == (connection->host = strdup(uri->host)))
+ goto free_and_fail;
/* Here make file descriptor non-block */
spdy_socket_make_non_block(fd);
@@ -791,6 +788,24 @@ spdy_connect(const struct URI *uri,
connection->fd = fd;
return connection;
+
+ //for GOTO
+ free_and_fail:
+ if(NULL != connection)
+ {
+ free(connection->host);
+ free(connection);
+ }
+
+ if(is_tls)
+ SSL_shutdown(ssl);
+
+ close(fd);
+
+ if(is_tls)
+ SSL_free(ssl);
+
+ return NULL;
}