diff --git a/BeefLibs/curl/src/Curl.bf b/BeefLibs/curl/src/Curl.bf index fb42d006..9cbd9f70 100644 --- a/BeefLibs/curl/src/Curl.bf +++ b/BeefLibs/curl/src/Curl.bf @@ -860,6 +860,8 @@ namespace CURL HTTP2Stream, /* 92 - stream error in HTTP/2 framing layer */ } + public struct SList; + [CLink, CallingConvention(.Stdcall)] static extern void* curl_easy_init(); @@ -881,6 +883,12 @@ namespace CURL [CLink, CallingConvention(.Stdcall)] static extern void* curl_easy_reset(void* curl); + [CLink, CallingConvention(.Stdcall)] + static extern SList* curl_slist_append(SList* list, char8* val); + + [CLink, CallingConvention(.Stdcall)] + static extern void curl_slist_free_all(SList* list); + void* mCURL; public this() @@ -941,6 +949,12 @@ namespace CURL return WrapResult((ReturnCode)curl_easy_setopt(mCURL, (int)option, (int)funcPtr)); } + public Result SetOpt(Option option, SList* list) + { + Debug.Assert(((int)option / 10000 == 1)); + return WrapResult((ReturnCode)curl_easy_setopt(mCURL, (int)option, (int)(void*)list)); + } + public Result GetInfo(CurlInfo info, String val) { char8* ptr = null; @@ -960,5 +974,15 @@ namespace CURL { curl_easy_reset(mCURL); } + + public SList* Add(SList* list, StringView val) + { + return curl_slist_append(list, val.ToScopeCStr!()); + } + + public void Free(SList* list) + { + curl_slist_free_all(list); + } } } \ No newline at end of file diff --git a/BeefLibs/curl/src/Transfer.bf b/BeefLibs/curl/src/Transfer.bf index 9460161c..eb9d37c9 100644 --- a/BeefLibs/curl/src/Transfer.bf +++ b/BeefLibs/curl/src/Transfer.bf @@ -9,6 +9,7 @@ namespace CURL class Transfer { CURL.Easy mCurl; + CURL.Easy.SList* mHeaderList; bool mOwns; bool mCancelling = false; List mData = new List() ~ delete _; @@ -77,6 +78,9 @@ namespace CURL if (mOwns) delete mCurl; + + if (mHeaderList != null) + mCurl.Free(mHeaderList); } int GetCurBytesPerSecond() @@ -146,6 +150,11 @@ namespace CURL mCurl.SetOpt(.HTTPGet, true); } + public void AddHeader(StringView header) + { + mHeaderList = mCurl.Add(mHeaderList, header); + } + public void InitPost(String url, String param) { Init(url); @@ -154,6 +163,9 @@ namespace CURL public Result> Perform() { + if (mHeaderList != null) + mCurl.SetOpt(.HTTPHeader, mHeaderList); + mStatsTimer.Start(); var result = mCurl.Perform(); mStatsTimer.Stop();