aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http_client.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2014-07-01 03:13:16 +0000
committerDavid Barksdale <amatus.amongus@gmail.com>2014-07-01 03:13:16 +0000
commit5ab82d972d1b300af56a680950726b810133cd89 (patch)
tree72c2afde82d1003dc22cc24a19951a5d5a87380e /src/transport/plugin_transport_http_client.c
parent0e07f3b3f6df0f56bc5b23820977864828616845 (diff)
downloadgnunet-5ab82d972d1b300af56a680950726b810133cd89.tar.gz
gnunet-5ab82d972d1b300af56a680950726b810133cd89.zip
Add HTTP transport tests with XHR client emulation
These tests don't pass currently but I ran them against a hacked version of the HTTP server which never calls server_delete_session and they passed.
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r--src/transport/plugin_transport_http_client.c59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 81ab4d5da..cf75ec5d7 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -353,6 +353,10 @@ struct HTTP_Client_Plugin
353 */ 353 */
354 uint16_t use_ipv4; 354 uint16_t use_ipv4;
355 355
356 /**
357 * Should we emulate an XHR client for testing?
358 */
359 int emulate_xhr;
356}; 360};
357 361
358 362
@@ -649,6 +653,16 @@ client_log (CURL *curl,
649 653
650 654
651/** 655/**
656 * Connect GET connection for a session
657 *
658 * @param s the session to connect
659 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
660 */
661static int
662client_connect_get (struct Session *s);
663
664
665/**
652 * Connect a HTTP put connection 666 * Connect a HTTP put connection
653 * 667 *
654 * @param s the session to connect 668 * @param s the session to connect
@@ -983,6 +997,15 @@ client_send_cb (void *stream,
983 997
984 if (NULL == msg) 998 if (NULL == msg)
985 { 999 {
1000 if (GNUNET_YES == plugin->emulate_xhr)
1001 {
1002 LOG (GNUNET_ERROR_TYPE_DEBUG,
1003 "Session %p/connection %p: PUT request finished\n",
1004 s, s->put.easyhandle);
1005 s->put_tmp_disconnecting = GNUNET_YES;
1006 return 0;
1007 }
1008
986 LOG (GNUNET_ERROR_TYPE_DEBUG, 1009 LOG (GNUNET_ERROR_TYPE_DEBUG,
987 "Session %p/connection %p: nothing to send, suspending\n", 1010 "Session %p/connection %p: nothing to send, suspending\n",
988 s, s->put.easyhandle); 1011 s, s->put.easyhandle);
@@ -1343,7 +1366,15 @@ curl_easy_getinfo (easy_h,
1343 /* FIXME: who calls curl_multi_remove on 'easy_h' now!? */ 1366 /* FIXME: who calls curl_multi_remove on 'easy_h' now!? */
1344 GNUNET_assert (plugin->cur_connections > 0); 1367 GNUNET_assert (plugin->cur_connections > 0);
1345 plugin->cur_connections--; 1368 plugin->cur_connections--;
1346 http_client_plugin_session_disconnect (plugin, s); 1369 /* If we are emulating an XHR client we need to make another GET
1370 * request.
1371 */
1372 if (GNUNET_YES == plugin->emulate_xhr)
1373 {
1374 if (GNUNET_SYSERR == client_connect_get (s))
1375 http_client_plugin_session_disconnect (plugin, s);
1376 } else
1377 http_client_plugin_session_disconnect (plugin, s);
1347 } 1378 }
1348 } 1379 }
1349 } 1380 }
@@ -1413,7 +1444,15 @@ client_connect_get (struct Session *s)
1413 s->plugin->proxy_use_httpproxytunnel); 1444 s->plugin->proxy_use_httpproxytunnel);
1414 } 1445 }
1415 1446
1416 curl_easy_setopt (s->get.easyhandle, CURLOPT_URL, s->url); 1447 if (GNUNET_YES == s->plugin->emulate_xhr)
1448 {
1449 char *url;
1450
1451 GNUNET_asprintf(&url, "%s,1", s->url);
1452 curl_easy_setopt (s->get.easyhandle, CURLOPT_URL, url);
1453 GNUNET_free(url);
1454 } else
1455 curl_easy_setopt (s->get.easyhandle, CURLOPT_URL, s->url);
1417 //curl_easy_setopt (s->get.easyhandle, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); 1456 //curl_easy_setopt (s->get.easyhandle, CURLOPT_HEADERFUNCTION, &curl_get_header_cb);
1418 //curl_easy_setopt (s->get.easyhandle, CURLOPT_WRITEHEADER, ps); 1457 //curl_easy_setopt (s->get.easyhandle, CURLOPT_WRITEHEADER, ps);
1419 curl_easy_setopt (s->get.easyhandle, CURLOPT_READFUNCTION, client_send_cb); 1458 curl_easy_setopt (s->get.easyhandle, CURLOPT_READFUNCTION, client_send_cb);
@@ -1583,8 +1622,14 @@ client_connect (struct Session *s)
1583 "Initiating outbound session peer `%s' using address `%s'\n", 1622 "Initiating outbound session peer `%s' using address `%s'\n",
1584 GNUNET_i2s (&s->address->peer), s->url); 1623 GNUNET_i2s (&s->address->peer), s->url);
1585 1624
1586 if ((GNUNET_SYSERR == client_connect_get (s)) || 1625 if (GNUNET_SYSERR == client_connect_get (s))
1587 (GNUNET_SYSERR == client_connect_put (s))) 1626 return GNUNET_SYSERR;
1627 /* If we are emulating an XHR client then delay sending a PUT request until
1628 * there is something to send.
1629 */
1630 if (GNUNET_YES == plugin->emulate_xhr)
1631 s->put_tmp_disconnected = GNUNET_YES;
1632 else if (GNUNET_SYSERR == client_connect_put (s))
1588 return GNUNET_SYSERR; 1633 return GNUNET_SYSERR;
1589 1634
1590 LOG (GNUNET_ERROR_TYPE_DEBUG, 1635 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1970,6 +2015,12 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin)
1970 2015
1971 GNUNET_free_non_null (proxy_type); 2016 GNUNET_free_non_null (proxy_type);
1972 } 2017 }
2018
2019 /* Should we emulate an XHR client for testing? */
2020 plugin->emulate_xhr
2021 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
2022 plugin->name,
2023 "EMULATE_XHR");
1973 return GNUNET_OK; 2024 return GNUNET_OK;
1974} 2025}
1975 2026