diff options
author | Gustavo Sverzut Barbieri <barbieri@profusion.mobi> | 2016-08-29 14:50:33 -0300 |
---|---|---|
committer | Gustavo Sverzut Barbieri <barbieri@profusion.mobi> | 2016-08-30 00:35:45 -0300 |
commit | f1c691d0f54c13ad76163ce419cbc54f2b3b2afc (patch) | |
tree | 15e95577cb271bb9f709fd40b7b5106737e301eb | |
parent | fba2743361d5a149f9d9ccc7642dc209da523c01 (diff) |
efl_net_dialer_http: allow incompatible configurations such as GET + upload.
CURL is smart and when you ask for CURLOPT_HTTPGET, it will
automatically configure UPLOAD=false. Likewise, if you ask for
UPLOAD=1 it will configure CURLOPT_PUT...
However, to do things like WebSocket we need to do a GET request where
we need to send data, then UPLOAD=true must be used.
Then use both information in order to setup the request method and
upload, using CURLOPT_CUSTOMREQUEST to force a given HTTP method.
-rw-r--r-- | src/lib/ecore_con/efl_net_dialer_http.c | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/src/lib/ecore_con/efl_net_dialer_http.c b/src/lib/ecore_con/efl_net_dialer_http.c index f80bd4e31e..68477ac6c3 100644 --- a/src/lib/ecore_con/efl_net_dialer_http.c +++ b/src/lib/ecore_con/efl_net_dialer_http.c | |||
@@ -1378,25 +1378,65 @@ _efl_net_dialer_http_efl_io_sizer_size_get(Eo *o, Efl_Net_Dialer_Http_Data *pd) | |||
1378 | return len; | 1378 | return len; |
1379 | } | 1379 | } |
1380 | 1380 | ||
1381 | EOLIAN static void | 1381 | static void |
1382 | _efl_net_dialer_http_method_set(Eo *o, Efl_Net_Dialer_Http_Data *pd, const char *method) | 1382 | _efl_net_dialer_http_request_apply(Eo *o, Efl_Net_Dialer_Http_Data *pd, const char *method, Efl_Net_Dialer_Http_Primary_Mode primary_mode) |
1383 | { | 1383 | { |
1384 | CURLcode r; | 1384 | CURLcode r; |
1385 | 1385 | ||
1386 | EINA_SAFETY_ON_NULL_RETURN(method); | 1386 | if (primary_mode == EFL_NET_DIALER_HTTP_PRIMARY_MODE_UPLOAD) |
1387 | 1387 | { | |
1388 | if (strcasecmp(method, "GET") == 0) | 1388 | if (strcasecmp(method, "PUT") == 0) |
1389 | r = curl_easy_setopt(pd->easy, CURLOPT_HTTPGET, 1L); | 1389 | r = curl_easy_setopt(pd->easy, CURLOPT_PUT, 1L); |
1390 | else if (strcasecmp(method, "POST") == 0) | 1390 | else |
1391 | r = curl_easy_setopt(pd->easy, CURLOPT_POST, 1L); | 1391 | { |
1392 | else if (strcasecmp(method, "PUT") == 0) | 1392 | /* upload with non PUT method: |
1393 | r = curl_easy_setopt(pd->easy, CURLOPT_PUT, 1L); | 1393 | * 1 - set CURLOPT_UPLOAD = 1, this forces httpreq = PUT |
1394 | * 2 - set CURLOPT_CUSTOMREQUEST = method, this overrides | ||
1395 | * the string to send. | ||
1396 | */ | ||
1397 | r = curl_easy_setopt(pd->easy, CURLOPT_UPLOAD, 1L); | ||
1398 | if (r != CURLE_OK) | ||
1399 | ERR("dialer=%p could not configure upload mode: %s", | ||
1400 | o, curl_easy_strerror(r)); | ||
1401 | |||
1402 | r = curl_easy_setopt(pd->easy, CURLOPT_CUSTOMREQUEST, method); | ||
1403 | } | ||
1404 | } | ||
1394 | else | 1405 | else |
1395 | r = curl_easy_setopt(pd->easy, CURLOPT_CUSTOMREQUEST, method); | 1406 | { |
1407 | if (strcasecmp(method, "GET") == 0) | ||
1408 | r = curl_easy_setopt(pd->easy, CURLOPT_HTTPGET, 1L); | ||
1409 | else if (strcasecmp(method, "POST") == 0) | ||
1410 | r = curl_easy_setopt(pd->easy, CURLOPT_POST, 1L); | ||
1411 | else if (strcasecmp(method, "PUT") == 0) | ||
1412 | { | ||
1413 | if (primary_mode == EFL_NET_DIALER_HTTP_PRIMARY_MODE_AUTO) | ||
1414 | r = curl_easy_setopt(pd->easy, CURLOPT_PUT, 1L); | ||
1415 | else | ||
1416 | { | ||
1417 | r = curl_easy_setopt(pd->easy, CURLOPT_UPLOAD, 0L); | ||
1418 | if (r != CURLE_OK) | ||
1419 | ERR("dialer=%p could not configure no-upload mode: %s", | ||
1420 | o, curl_easy_strerror(r)); | ||
1421 | |||
1422 | r = curl_easy_setopt(pd->easy, CURLOPT_CUSTOMREQUEST, method); | ||
1423 | } | ||
1424 | } | ||
1425 | else | ||
1426 | r = curl_easy_setopt(pd->easy, CURLOPT_CUSTOMREQUEST, method); | ||
1427 | } | ||
1428 | |||
1396 | if (r != CURLE_OK) | 1429 | if (r != CURLE_OK) |
1397 | ERR("dialer=%p could not configure HTTP method: %s: %s", | 1430 | ERR("dialer=%p could not configure HTTP method: %s: %s", |
1398 | o, method, curl_easy_strerror(r)); | 1431 | o, method, curl_easy_strerror(r)); |
1432 | } | ||
1433 | |||
1434 | EOLIAN static void | ||
1435 | _efl_net_dialer_http_method_set(Eo *o, Efl_Net_Dialer_Http_Data *pd, const char *method) | ||
1436 | { | ||
1437 | EINA_SAFETY_ON_NULL_RETURN(method); | ||
1399 | 1438 | ||
1439 | _efl_net_dialer_http_request_apply(o, pd, method, pd->primary_mode); | ||
1400 | eina_stringshare_replace(&pd->method, method); | 1440 | eina_stringshare_replace(&pd->method, method); |
1401 | } | 1441 | } |
1402 | 1442 | ||
@@ -1407,8 +1447,9 @@ _efl_net_dialer_http_method_get(Eo *o EINA_UNUSED, Efl_Net_Dialer_Http_Data *pd) | |||
1407 | } | 1447 | } |
1408 | 1448 | ||
1409 | EOLIAN static void | 1449 | EOLIAN static void |
1410 | _efl_net_dialer_http_primary_mode_set(Eo *o EINA_UNUSED, Efl_Net_Dialer_Http_Data *pd, Efl_Net_Dialer_Http_Primary_Mode primary_mode) | 1450 | _efl_net_dialer_http_primary_mode_set(Eo *o, Efl_Net_Dialer_Http_Data *pd, Efl_Net_Dialer_Http_Primary_Mode primary_mode) |
1411 | { | 1451 | { |
1452 | _efl_net_dialer_http_request_apply(o, pd, pd->method, primary_mode); | ||
1412 | pd->primary_mode = primary_mode; | 1453 | pd->primary_mode = primary_mode; |
1413 | } | 1454 | } |
1414 | 1455 | ||