mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-22 17:48:01 +02:00
Support custom headers
This commit is contained in:
parent
d1902c4926
commit
560a7eb7a7
2 changed files with 36 additions and 0 deletions
|
@ -860,6 +860,8 @@ namespace CURL
|
||||||
HTTP2Stream, /* 92 - stream error in HTTP/2 framing layer */
|
HTTP2Stream, /* 92 - stream error in HTTP/2 framing layer */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct SList;
|
||||||
|
|
||||||
[CLink, CallingConvention(.Stdcall)]
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
static extern void* curl_easy_init();
|
static extern void* curl_easy_init();
|
||||||
|
|
||||||
|
@ -881,6 +883,12 @@ namespace CURL
|
||||||
[CLink, CallingConvention(.Stdcall)]
|
[CLink, CallingConvention(.Stdcall)]
|
||||||
static extern void* curl_easy_reset(void* curl);
|
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;
|
void* mCURL;
|
||||||
|
|
||||||
public this()
|
public this()
|
||||||
|
@ -941,6 +949,12 @@ namespace CURL
|
||||||
return WrapResult((ReturnCode)curl_easy_setopt(mCURL, (int)option, (int)funcPtr));
|
return WrapResult((ReturnCode)curl_easy_setopt(mCURL, (int)option, (int)funcPtr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result<void, ReturnCode> 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<void> GetInfo(CurlInfo info, String val)
|
public Result<void> GetInfo(CurlInfo info, String val)
|
||||||
{
|
{
|
||||||
char8* ptr = null;
|
char8* ptr = null;
|
||||||
|
@ -960,5 +974,15 @@ namespace CURL
|
||||||
{
|
{
|
||||||
curl_easy_reset(mCURL);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ namespace CURL
|
||||||
class Transfer
|
class Transfer
|
||||||
{
|
{
|
||||||
CURL.Easy mCurl;
|
CURL.Easy mCurl;
|
||||||
|
CURL.Easy.SList* mHeaderList;
|
||||||
bool mOwns;
|
bool mOwns;
|
||||||
bool mCancelling = false;
|
bool mCancelling = false;
|
||||||
List<uint8> mData = new List<uint8>() ~ delete _;
|
List<uint8> mData = new List<uint8>() ~ delete _;
|
||||||
|
@ -77,6 +78,9 @@ namespace CURL
|
||||||
|
|
||||||
if (mOwns)
|
if (mOwns)
|
||||||
delete mCurl;
|
delete mCurl;
|
||||||
|
|
||||||
|
if (mHeaderList != null)
|
||||||
|
mCurl.Free(mHeaderList);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetCurBytesPerSecond()
|
int GetCurBytesPerSecond()
|
||||||
|
@ -146,6 +150,11 @@ namespace CURL
|
||||||
mCurl.SetOpt(.HTTPGet, true);
|
mCurl.SetOpt(.HTTPGet, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddHeader(StringView header)
|
||||||
|
{
|
||||||
|
mHeaderList = mCurl.Add(mHeaderList, header);
|
||||||
|
}
|
||||||
|
|
||||||
public void InitPost(String url, String param)
|
public void InitPost(String url, String param)
|
||||||
{
|
{
|
||||||
Init(url);
|
Init(url);
|
||||||
|
@ -154,6 +163,9 @@ namespace CURL
|
||||||
|
|
||||||
public Result<Span<uint8>> Perform()
|
public Result<Span<uint8>> Perform()
|
||||||
{
|
{
|
||||||
|
if (mHeaderList != null)
|
||||||
|
mCurl.SetOpt(.HTTPHeader, mHeaderList);
|
||||||
|
|
||||||
mStatsTimer.Start();
|
mStatsTimer.Start();
|
||||||
var result = mCurl.Perform();
|
var result = mCurl.Perform();
|
||||||
mStatsTimer.Stop();
|
mStatsTimer.Stop();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue