Applied workaround for CurlSharp GC handling.
This commit is contained in:
parent
786e0b825a
commit
51155ba909
|
@ -45,7 +45,8 @@ namespace NzbDrone.Common.Http
|
||||||
Stream responseStream = new MemoryStream();
|
Stream responseStream = new MemoryStream();
|
||||||
Stream headerStream = new MemoryStream();
|
Stream headerStream = new MemoryStream();
|
||||||
|
|
||||||
var curlEasy = new CurlEasy();
|
using (var curlEasy = new CurlEasy())
|
||||||
|
{
|
||||||
curlEasy.AutoReferer = false;
|
curlEasy.AutoReferer = false;
|
||||||
curlEasy.WriteFunction = (b, s, n, o) =>
|
curlEasy.WriteFunction = (b, s, n, o) =>
|
||||||
{
|
{
|
||||||
|
@ -73,11 +74,14 @@ namespace NzbDrone.Common.Http
|
||||||
if (!httpRequest.Body.IsNullOrWhiteSpace())
|
if (!httpRequest.Body.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
// TODO: This might not go well with encoding.
|
// TODO: This might not go well with encoding.
|
||||||
curlEasy.PostFields = httpRequest.Body;
|
|
||||||
curlEasy.PostFieldSize = httpRequest.Body.Length;
|
curlEasy.PostFieldSize = httpRequest.Body.Length;
|
||||||
|
curlEasy.SetOpt(CurlOption.CopyPostFields, httpRequest.Body);
|
||||||
}
|
}
|
||||||
|
|
||||||
curlEasy.HttpHeader = SerializeHeaders(webRequest);
|
// Yes, we have to keep a ref to the object to prevent corrupting the unmanaged state
|
||||||
|
using (var httpRequestHeaders = SerializeHeaders(webRequest))
|
||||||
|
{
|
||||||
|
curlEasy.HttpHeader = httpRequestHeaders;
|
||||||
|
|
||||||
var result = curlEasy.Perform();
|
var result = curlEasy.Perform();
|
||||||
|
|
||||||
|
@ -85,6 +89,7 @@ namespace NzbDrone.Common.Http
|
||||||
{
|
{
|
||||||
throw new WebException(string.Format("Curl Error {0} for Url {1}", result, curlEasy.Url));
|
throw new WebException(string.Format("Curl Error {0} for Url {1}", result, curlEasy.Url));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var webHeaderCollection = ProcessHeaderStream(webRequest, headerStream);
|
var webHeaderCollection = ProcessHeaderStream(webRequest, headerStream);
|
||||||
var responseData = ProcessResponseStream(webRequest, responseStream, webHeaderCollection);
|
var responseData = ProcessResponseStream(webRequest, responseStream, webHeaderCollection);
|
||||||
|
@ -94,6 +99,7 @@ namespace NzbDrone.Common.Http
|
||||||
return new HttpResponse(httpRequest, httpHeader, responseData, (HttpStatusCode)curlEasy.ResponseCode);
|
return new HttpResponse(httpRequest, httpHeader, responseData, (HttpStatusCode)curlEasy.ResponseCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private CurlSlist SerializeHeaders(HttpWebRequest webRequest)
|
private CurlSlist SerializeHeaders(HttpWebRequest webRequest)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue