Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added setting headers capability. Example:

  var cr = new Curl("http://somesite.com/somefile.php");
  var headers : Array<String> = new Array();
  headers.push("Content-type: text/xml;charset=\"utf-8\"");
  cr.setHttpHeaders(headers);
  • Loading branch information...
commit 62d15044d2ce1f6c7c59b347f1f3a45cf9677ad1 1 parent 42985b9
@programmador programmador authored
Showing with 31 additions and 0 deletions.
  1. +5 −0 curl/Curl.hx
  2. +26 −0 ndll/Source/curl_wrap.c
View
5 curl/Curl.hx
@@ -74,6 +74,9 @@ class Curl {
public function setPostData( data:String ) : Void {
setPostdata( curl_handle, Lib.haxeToNeko( data ));
}
+ public function setHttpHeaders( data:Array<String> ) : Void {
+ setHttpheaders( curl_handle, Lib.haxeToNeko( data ));
+ }
function set_ua( agent:String ) {
setUserAgent( curl_handle, Lib.haxeToNeko( agent ));
return agent;
@@ -125,6 +128,8 @@ class Curl {
private static var setUrl = neko.Lib.load("curl_wrap","setUrl",2);
// setPostdata( curl_handle, string:neko_string ) → Bool
private static var setPostdata = neko.Lib.load("curl_wrap","setPostdata",2);
+ // setHeaders( curl_handle, data:neko_array/pointer ) → Bool
+ private static var setHttpheaders = neko.Lib.load("curl_wrap","setHeaders",2);
// makeRequest( curl_handle ) → Bool
private static var makeRequest =neko.Lib.load("curl_wrap","makeRequest",1);
// makeRequest( curl_handle ) → Bool
View
26 ndll/Source/curl_wrap.c
@@ -83,6 +83,32 @@ value setPostdata ( value curl_handle, value data ) {
return val_true;
} DEFINE_PRIM(setPostdata,2);
+value setHeaders ( value curl_handle, value data ) {
+ struct curl_slist * header_list = NULL;
+ value * p_arr;
+ int i;
+ if(val_is_array(data))
+ {
+ p_arr = val_array_ptr(data);
+ for (i = 0; i < val_array_size(data); i++)
+ {
+ if(val_is_string(p_arr[i]))
+ {
+ printf("headers array item #%i = %s\n", i, val_string(p_arr[i]));
+ header_list = curl_slist_append(header_list, val_string(p_arr[i]));
+ //header_list = curl_slist_append(header_list, "Content-type: text/json;charset=\"utf-8\"");
+ }
+ else
+ {
+ printf("non-string item value found in headers array at item #%i\n", i);
+ }
+ }
+ }
+ curl_easy_setopt( val_data( curl_handle ),
+ CURLOPT_HTTPHEADER, header_list );
+ return val_true;
+} DEFINE_PRIM(setHeaders,2);
+
// This is needed so that we know what do when libCurl calls us
typedef struct _WriteCallbackData {
// The neko function that is going to aswer the call
Please sign in to comment.
Something went wrong with that request. Please try again.