Only send `Expect` header for `comm.httpPost` when payload is large (squashed PR #4188)

* BizHawk#4187 Add a method to the comm LUA library to allow setting ExpectContinue

* Instead of exposing ExpectContinue set it automatically based on a threshold
This commit is contained in:
papercrane 2025-01-16 06:32:28 -08:00 committed by GitHub
parent 6c6986d79e
commit 544b8007dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 4 deletions

View File

@ -20,6 +20,8 @@ namespace BizHawk.Client.Common
public int Timeout { get; set; }
public int ExpectContinueThreshold { get; set; } = 1024 * 1024; // 1MB
public HttpCommunication(Func<byte[]> takeScreenshotCallback, string getURL, string postURL)
{
_takeScreenshotCallback = takeScreenshotCallback;
@ -30,10 +32,14 @@ namespace BizHawk.Client.Common
public string ExecGet(string url = null) => Get(url ?? GetUrl).Result;
public string ExecPost(string url = null, string payload = "") => Post(
url ?? PostUrl,
new FormUrlEncodedContent(new Dictionary<string, string> { ["payload"] = payload })
).Result;
public string ExecPost(string url = null, string payload = "")
{
_client.DefaultRequestHeaders.ExpectContinue = payload.Length > ExpectContinueThreshold;
return Post(
url ?? PostUrl,
new FormUrlEncodedContent(new Dictionary<string, string> { ["payload"] = payload })
).Result;
}
public async Task<string> Get(string url)
{