Skip to content

Commit

Permalink
Allow passing extra headers into the HTTP calls (useful for CP-33676)…
Browse files Browse the repository at this point in the history
…. Renamed a couple of local parameters.

Signed-off-by: Konstantina Chremmou <[email protected]>
  • Loading branch information
kc284 committed Jan 10, 2024
1 parent 0b4be9a commit 0c00825
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions ocaml/sdk-gen/csharp/autogen/src/HTTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,9 @@ private static void AuthenticateProxy(ref Stream stream, Uri uri, IWebProxy prox
}


private static Stream DoHttp(Uri uri, IWebProxy proxy, bool nodelay, int timeout_ms, params string[] headers)
private static Stream DoHttp(Uri uri, IWebProxy proxy, bool noDelay, int timeoutMs, params string[] headers)
{
Stream stream = ConnectStream(uri, proxy, nodelay, timeout_ms);
Stream stream = ConnectStream(uri, proxy, noDelay, timeoutMs);

int redirects = 0;

Expand All @@ -687,43 +687,72 @@ private static Stream DoHttp(Uri uri, IWebProxy proxy, bool nodelay, int timeout

stream.Flush();
}
while (ReadHttpHeaders(ref stream, proxy, nodelay, timeout_ms));
while (ReadHttpHeaders(ref stream, proxy, noDelay, timeoutMs));

return stream;
}

/// <summary>
/// Adds HTTP CONNECT headers returning the stream ready for use
/// </summary>
public static Stream HttpConnectStream(Uri uri, IWebProxy proxy, String session, int timeoutMs)
public static Stream HttpConnectStream(Uri uri, IWebProxy proxy, string session, int timeoutMs, Dictionary<string, string> additionalHeaders = null)
{
return DoHttp(uri, proxy, true, timeoutMs,
string.Format("CONNECT {0} HTTP/1.0", uri.PathAndQuery),
string.Format("Host: {0}", uri.Host),
string.Format("Cookie: session_id={0}", session));
var allHeaders = new List<string>
{
$"CONNECT {uri.PathAndQuery} HTTP/1.0",
$"Host: {uri.Host}",
$"Cookie: session_id={session}"
};

if (additionalHeaders != null)
{
foreach (var kvp in additionalHeaders)
allHeaders.Add($"{kvp.Key}: {kvp.Value}");
}

return DoHttp(uri, proxy, true, timeoutMs, allHeaders.ToArray());
}

/// <summary>
/// Adds HTTP PUT headers returning the stream ready for use
/// </summary>
public static Stream HttpPutStream(Uri uri, IWebProxy proxy, long contentLength, int timeoutMs)
public static Stream HttpPutStream(Uri uri, IWebProxy proxy, long contentLength, int timeoutMs, Dictionary<string, string> additionalHeaders = null)
{
return DoHttp(uri, proxy, false, timeoutMs,
string.Format("PUT {0} HTTP/1.0", uri.PathAndQuery),
string.Format("Host: {0}", uri.Host),
string.Format("Content-Length: {0}", contentLength));
var allHeaders = new List<string>
{
$"PUT {uri.PathAndQuery} HTTP/1.0",
$"Host: {uri.Host}",
$"Content-Length: {contentLength}"
};

if (additionalHeaders != null)
{
foreach (var kvp in additionalHeaders)
allHeaders.Add($"{kvp.Key}: {kvp.Value}");
}

return DoHttp(uri, proxy, false, timeoutMs, allHeaders.ToArray());
}

/// <summary>
/// Adds HTTP GET headers returning the stream ready for use
/// </summary>
public static Stream HttpGetStream(Uri uri, IWebProxy proxy, int timeoutMs)
public static Stream HttpGetStream(Uri uri, IWebProxy proxy, int timeoutMs, Dictionary<string, string> additionalHeaders = null)
{
return DoHttp(uri, proxy, false, timeoutMs,
string.Format("GET {0} HTTP/1.0", uri.PathAndQuery),
string.Format("Host: {0}", uri.Host));
}
var allHeaders = new List<string>
{
$"GET {uri.PathAndQuery} HTTP/1.0",
$"Host: {uri.Host}"
};

if (additionalHeaders != null)
{
foreach (var kvp in additionalHeaders)
allHeaders.Add($"{kvp.Key}: {kvp.Value}");
}

return DoHttp(uri, proxy, false, timeoutMs, allHeaders.ToArray());
}

/// <summary>
/// A general HTTP PUT method, with delegates for progress and cancelling. May throw various exceptions.
Expand Down

0 comments on commit 0c00825

Please sign in to comment.