From 544b8007dc46a84da6fc6f7e4a57d5f1dab55415 Mon Sep 17 00:00:00 2001 From: papercrane Date: Thu, 16 Jan 2025 06:32:28 -0800 Subject: [PATCH] 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 --- src/BizHawk.Client.Common/Api/HttpCommunication.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Client.Common/Api/HttpCommunication.cs b/src/BizHawk.Client.Common/Api/HttpCommunication.cs index a689d063ee..39451c7045 100644 --- a/src/BizHawk.Client.Common/Api/HttpCommunication.cs +++ b/src/BizHawk.Client.Common/Api/HttpCommunication.cs @@ -20,6 +20,8 @@ namespace BizHawk.Client.Common public int Timeout { get; set; } + public int ExpectContinueThreshold { get; set; } = 1024 * 1024; // 1MB + public HttpCommunication(Func 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 { ["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 { ["payload"] = payload }) + ).Result; + } public async Task Get(string url) {