diff --git a/.github/workflows/probe.yml b/.github/workflows/probe.yml index 332e8be..22613ca 100644 --- a/.github/workflows/probe.yml +++ b/.github/workflows/probe.yml @@ -156,6 +156,9 @@ jobs: 'connectionState': conn, 'reason': reason, 'scored': scored, 'durationMs': r.get('durationMs', 0), + 'rawRequest': r.get('rawRequest'), + 'rawResponse': r.get('rawResponse'), + 'behavioralNote': r.get('behavioralNote'), }) scored_results = [r for r in results if r['scored']] diff --git a/.gitignore b/.gitignore index 845d16d..c461843 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,9 @@ nunit-*.xml docs/public/ docs/.hugo_build.lock docs/resources/ + +# Probe data (generated by CI, pushed to latest-results branch) +docs/static/probe/data.js + +# Node +node_modules/ diff --git a/docs/hugo.yaml b/docs/hugo.yaml index f96ab52..db64c5a 100644 --- a/docs/hugo.yaml +++ b/docs/hugo.yaml @@ -41,8 +41,13 @@ menu: weight: 8 params: type: theme-toggle - - name: GitHub + - name: Discord weight: 9 + url: https://discord.gg/H84B5ZqDXR + params: + icon: discord + - name: GitHub + weight: 10 url: https://github.com/MDA2AV/Http11Probe params: icon: github diff --git a/docs/static/probe/render.js b/docs/static/probe/render.js index 09d38b3..6065474 100644 --- a/docs/static/probe/render.js +++ b/docs/static/probe/render.js @@ -5,7 +5,12 @@ window.ProbeRender = (function () { var FAIL_BG = '#cf222e'; var SKIP_BG = '#656d76'; var EXPECT_BG = '#444c56'; - var pillCss = 'text-align:center;padding:2px 4px;font-size:11px;font-weight:600;color:#fff;border-radius:3px;min-width:28px;display:inline-block;line-height:18px;'; + var pillCss = 'text-align:center;padding:2px 4px;font-size:11px;font-weight:600;color:#fff;border-radius:3px;min-width:28px;display:inline-block;line-height:18px;cursor:default;'; + + function escapeAttr(s) { + if (!s) return ''; + return s.replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>'); + } // Servers temporarily hidden from results (undergoing major changes) var BLACKLISTED_SERVERS = ['GenHTTP']; @@ -44,10 +49,100 @@ window.ProbeRender = (function () { + 'html.dark .probe-table tbody tr{border-bottom-color:#30363d}' + 'html.dark .probe-server-row:hover{background:#161b22}' + 'html.dark .probe-server-row.probe-row-active{background:#2a3a50 !important}' - + 'html.dark .probe-table thead a{color:#58a6ff !important}'; + + 'html.dark .probe-table thead a{color:#58a6ff !important}' + // Tooltip (hover) + + '.probe-tooltip{position:fixed;z-index:9999;background:#1c1c1c;color:#e0e0e0;font-family:monospace;font-size:11px;' + + 'white-space:pre;padding:8px 10px;border-radius:6px;max-width:500px;max-height:300px;overflow:auto;' + + 'pointer-events:none;box-shadow:0 4px 16px rgba(0,0,0,0.3);line-height:1.4}' + + '.probe-tooltip .probe-note{color:#f0c674;font-family:sans-serif;font-weight:600;font-size:11px;margin-bottom:6px;white-space:normal}' + + '.probe-tooltip .probe-label{color:#81a2be;font-family:sans-serif;font-weight:700;font-size:10px;text-transform:uppercase;letter-spacing:0.5px;margin-bottom:2px}' + + '.probe-tooltip .probe-label:not(:first-child){margin-top:8px;padding-top:8px;border-top:1px solid #333}' + // Modal (click) + + '.probe-modal-overlay{position:fixed;inset:0;z-index:10000;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center}' + + '.probe-modal{background:#1c1c1c;color:#e0e0e0;font-family:monospace;font-size:12px;white-space:pre;' + + 'padding:16px 20px;border-radius:8px;max-width:700px;max-height:80vh;overflow:auto;' + + 'box-shadow:0 8px 32px rgba(0,0,0,0.5);line-height:1.5;position:relative;min-width:300px}' + + '.probe-modal .probe-note{color:#f0c674;font-family:sans-serif;font-weight:600;font-size:13px;margin-bottom:10px;white-space:normal}' + + '.probe-modal .probe-label{color:#81a2be;font-family:sans-serif;font-weight:700;font-size:11px;text-transform:uppercase;letter-spacing:0.5px;margin-bottom:4px}' + + '.probe-modal .probe-label:not(:first-child){margin-top:12px;padding-top:12px;border-top:1px solid #333}' + + '.probe-modal-close{position:sticky;top:0;float:right;background:none;border:none;color:#808080;font-size:20px;' + + 'cursor:pointer;padding:0 4px;line-height:1;font-family:sans-serif}' + + '.probe-modal-close:hover{color:#fff}'; var style = document.createElement('style'); style.textContent = css; document.head.appendChild(style); + + // Tooltip hover handler (delegated) + var tip = null; + document.addEventListener('mouseover', function (e) { + var target = e.target.closest('[data-tooltip]'); + if (!target) return; + if (tip) { tip.remove(); tip = null; } + var text = target.getAttribute('data-tooltip'); + if (!text) return; + tip = document.createElement('div'); + tip.className = 'probe-tooltip'; + var note = target.getAttribute('data-note'); + var req = target.getAttribute('data-request'); + var html = ''; + if (note) html += '
' + escapeAttr(note) + '
'; + if (req) html += '
Request
' + escapeAttr(req); + if (text) html += '
Response
' + escapeAttr(text); + tip.innerHTML = html; + document.body.appendChild(tip); + var rect = target.getBoundingClientRect(); + var tipRect = tip.getBoundingClientRect(); + var left = rect.left + rect.width / 2 - tipRect.width / 2; + if (left < 4) left = 4; + if (left + tipRect.width > window.innerWidth - 4) left = window.innerWidth - 4 - tipRect.width; + var top = rect.top - tipRect.height - 6; + if (top < 4) top = rect.bottom + 6; + tip.style.left = left + 'px'; + tip.style.top = top + 'px'; + }); + document.addEventListener('mouseout', function (e) { + var target = e.target.closest('[data-tooltip]'); + if (target && tip) { tip.remove(); tip = null; } + }); + + // Modal click handler (delegated) + document.addEventListener('click', function (e) { + var target = e.target.closest('[data-tooltip]'); + if (!target) return; + var text = target.getAttribute('data-tooltip'); + var req = target.getAttribute('data-request'); + if (!text && !req) return; + // Dismiss hover tooltip + if (tip) { tip.remove(); tip = null; } + + var note = target.getAttribute('data-note'); + var html = ''; + if (note) html += '
' + escapeAttr(note) + '
'; + if (req) html += '
Request
' + escapeAttr(req); + if (text) html += '
Response
' + escapeAttr(text); + + var overlay = document.createElement('div'); + overlay.className = 'probe-modal-overlay'; + var modal = document.createElement('div'); + modal.className = 'probe-modal'; + modal.innerHTML = html; + overlay.appendChild(modal); + document.body.appendChild(overlay); + + // Close on X button + modal.querySelector('.probe-modal-close').addEventListener('click', function () { + overlay.remove(); + }); + // Close on overlay click (outside modal) + overlay.addEventListener('click', function (ev) { + if (ev.target === overlay) overlay.remove(); + }); + // Close on Escape + function onKey(ev) { + if (ev.key === 'Escape') { overlay.remove(); document.removeEventListener('keydown', onKey); } + } + document.addEventListener('keydown', onKey); + }); } // ── Test ID → doc page URL mapping ───────────────────────────── @@ -197,8 +292,14 @@ window.ProbeRender = (function () { return TEST_URLS[tid] || ''; } - function pill(bg, label) { - return '' + label + ''; + function pill(bg, label, tooltipRaw, tooltipNote, tooltipReq) { + var extra = ''; + var hasData = tooltipRaw || tooltipReq; + if (hasData) extra += ' data-tooltip="' + escapeAttr(tooltipRaw || '') + '"'; + if (tooltipNote) extra += ' data-note="' + escapeAttr(tooltipNote) + '"'; + if (tooltipReq) extra += ' data-request="' + escapeAttr(tooltipReq) + '"'; + var cursor = hasData ? 'cursor:pointer;' : 'cursor:default;'; + return '' + label + ''; } function verdictBg(v) { @@ -396,7 +497,7 @@ window.ProbeRender = (function () { t += '' + pill(SKIP_BG, '\u2014') + ''; return; } - t += '' + pill(verdictBg(r.verdict), r.got) + ''; + t += '' + pill(verdictBg(r.verdict), r.got, r.rawResponse, r.behavioralNote, r.rawRequest) + ''; }); t += ''; }); diff --git a/src/Http11Probe.Cli/Reporting/JsonReporter.cs b/src/Http11Probe.Cli/Reporting/JsonReporter.cs index c17635f..b66c2b8 100644 --- a/src/Http11Probe.Cli/Reporting/JsonReporter.cs +++ b/src/Http11Probe.Cli/Reporting/JsonReporter.cs @@ -41,7 +41,10 @@ public static string Generate(TestRunReport report) statusCode = r.Response?.StatusCode, connectionState = r.ConnectionState.ToString(), error = r.ErrorMessage, - durationMs = r.Duration.TotalMilliseconds + durationMs = r.Duration.TotalMilliseconds, + rawRequest = r.RawRequest, + rawResponse = r.Response?.RawResponse, + behavioralNote = r.BehavioralNote }) }; diff --git a/src/Http11Probe/Response/HttpResponse.cs b/src/Http11Probe/Response/HttpResponse.cs index b98496a..03ad98d 100644 --- a/src/Http11Probe/Response/HttpResponse.cs +++ b/src/Http11Probe/Response/HttpResponse.cs @@ -7,4 +7,6 @@ public sealed class HttpResponse public required string HttpVersion { get; init; } public required IReadOnlyDictionary Headers { get; init; } public bool IsEmpty { get; init; } + public string? RawResponse { get; init; } + public string? Body { get; init; } } diff --git a/src/Http11Probe/Response/ResponseParser.cs b/src/Http11Probe/Response/ResponseParser.cs index 0f12b4f..f302419 100644 --- a/src/Http11Probe/Response/ResponseParser.cs +++ b/src/Http11Probe/Response/ResponseParser.cs @@ -77,13 +77,30 @@ public static class ResponseParser pos = nextLineEnd + 1; } + // Extract body after \r\n\r\n + string? body = null; + var headerEnd = text.IndexOf("\r\n\r\n", StringComparison.Ordinal); + if (headerEnd >= 0) + { + var bodyStart = headerEnd + 4; + if (bodyStart < text.Length) + { + var bodyText = text[bodyStart..]; + body = bodyText.Length > 4096 ? bodyText[..4096] : bodyText; + } + } + + var rawResponse = text.Length > 8192 ? text[..8192] : text; + return new HttpResponse { StatusCode = statusCode, ReasonPhrase = reasonPhrase, HttpVersion = httpVersion, Headers = headers, - IsEmpty = false + IsEmpty = false, + RawResponse = rawResponse, + Body = body }; } } diff --git a/src/Http11Probe/Runner/TestRunner.cs b/src/Http11Probe/Runner/TestRunner.cs index e8ec42b..5d7be0e 100644 --- a/src/Http11Probe/Runner/TestRunner.cs +++ b/src/Http11Probe/Runner/TestRunner.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Text; using Http11Probe.Client; using Http11Probe.Response; using Http11Probe.TestCases; @@ -78,6 +79,7 @@ private async Task RunSingleAsync(TestCase testCase, TestContext con // Send the primary payload var payload = testCase.PayloadFactory(context); + var rawRequest = Encoding.ASCII.GetString(payload, 0, Math.Min(payload.Length, 8192)); await client.SendAsync(payload); // Read primary response @@ -105,6 +107,7 @@ private async Task RunSingleAsync(TestCase testCase, TestContext con } var verdict = testCase.Expected.Evaluate(response, connectionState); + var behavioralNote = testCase.BehavioralAnalyzer?.Invoke(response); return new TestResult { @@ -113,6 +116,8 @@ private async Task RunSingleAsync(TestCase testCase, TestContext con Response = response, FollowUpResponse = followUpResponse, ConnectionState = connectionState, + BehavioralNote = behavioralNote, + RawRequest = rawRequest, Duration = sw.Elapsed }; } diff --git a/src/Http11Probe/TestCases/Suites/SmugglingSuite.cs b/src/Http11Probe/TestCases/Suites/SmugglingSuite.cs index 91b8538..486a804 100644 --- a/src/Http11Probe/TestCases/Suites/SmugglingSuite.cs +++ b/src/Http11Probe/TestCases/Suites/SmugglingSuite.cs @@ -1,10 +1,56 @@ using System.Text; using Http11Probe.Client; +using Http11Probe.Response; namespace Http11Probe.TestCases.Suites; public static class SmugglingSuite { + // ── Behavioral analyzers ──────────────────────────────────── + // Examine the echoed body to determine which framing the server used. + // Static-config servers (Nginx, Apache, etc.) always return "OK" and cannot echo. + + private const string StaticNote = "Static response — server does not echo POST body"; + + private static bool IsStaticResponse(string body) => body == "OK"; + + private static string? AnalyzeClTeBoth(HttpResponse? r) + { + if (r is null || r.StatusCode is < 200 or >= 300) return null; + var body = (r.Body ?? "").TrimEnd('\r', '\n'); + if (IsStaticResponse(body)) return StaticNote; + if (body.Length == 0) return "Used TE (chunked 0-length → empty body)"; + if (body.Contains("0\r\n\r\n") || body == "0\r\n\r") return "Used CL (read 6 raw bytes including chunk terminator)"; + return $"Body: {Truncate(body)}"; + } + + private static string? AnalyzeDuplicateCl(HttpResponse? r) + { + // Payload: "helloworld" with CL:5 and CL:10 + // CL:5 → "hello", CL:10 → "helloworld" + if (r is null || r.StatusCode is < 200 or >= 300) return null; + var body = (r.Body ?? "").TrimEnd('\r', '\n'); + if (IsStaticResponse(body)) return StaticNote; + if (body == "hello") return "Used first CL (5 bytes)"; + if (body == "helloworld") return "Used second CL (10 bytes)"; + if (body.Length == 0) return "Empty body (server consumed no body)"; + return $"Body: {Truncate(body)}"; + } + + private static string? AnalyzeTeWithClFallback(HttpResponse? r) + { + // Tests with TE variant + CL:5 + body "hello" + // If server used CL → body is "hello"; if TE recognized → empty (chunked parse of "hello") + if (r is null || r.StatusCode is < 200 or >= 300) return null; + var body = (r.Body ?? "").TrimEnd('\r', '\n'); + if (IsStaticResponse(body)) return StaticNote; + if (body == "hello") return "Used CL (ignored TE variant)"; + if (body.Length == 0) return "Used TE (treated as chunked)"; + return $"Body: {Truncate(body)}"; + } + + private static string Truncate(string s) => s.Length > 40 ? s[..40] + "..." : s; + public static IEnumerable GetTestCases() { yield return new TestCase @@ -15,6 +61,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nContent-Length: 6\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n"), + BehavioralAnalyzer = AnalyzeClTeBoth, Expected = new ExpectedBehavior { Description = "400 or 2xx", @@ -39,7 +86,8 @@ public static IEnumerable GetTestCases() Category = TestCategory.Smuggling, RfcReference = "RFC 9110 §8.6", PayloadFactory = ctx => MakeRequest( - $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nContent-Length: 5\r\nContent-Length: 10\r\n\r\nhello"), + $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nContent-Length: 5\r\nContent-Length: 10\r\n\r\nhelloworld"), + BehavioralAnalyzer = AnalyzeDuplicateCl, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -79,6 +127,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: xchunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -94,6 +143,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: chunked \r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -109,6 +159,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §5", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding : chunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -225,6 +276,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: chunked, chunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { Description = "400 or 2xx", @@ -273,6 +325,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: Chunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { Description = "400 or 2xx", @@ -329,6 +382,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.0\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: chunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -407,6 +461,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: \r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -422,6 +477,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9110 §5.6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: , chunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { Description = "400 or 2xx", @@ -447,6 +503,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: chunked\r\nTransfer-Encoding: identity\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -670,6 +727,7 @@ public static IEnumerable GetTestCases() after.CopyTo(payload, before.Length + vtab.Length); return payload; }, + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -694,6 +752,7 @@ public static IEnumerable GetTestCases() after.CopyTo(payload, before.Length + ff.Length); return payload; }, + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -718,6 +777,7 @@ public static IEnumerable GetTestCases() after.CopyTo(payload, before.Length + nul.Length); return payload; }, + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -762,6 +822,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §7", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: identity\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400), @@ -795,6 +856,7 @@ public static IEnumerable GetTestCases() Scored = false, PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer_Encoding: chunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { Description = "400 or 2xx", @@ -844,6 +906,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §7", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: chunked;ext=val\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { Description = "400 or 2xx", @@ -1129,6 +1192,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9112 §5.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding:\r\n chunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { ExpectedStatus = StatusCodeRange.Exact(400) @@ -1143,6 +1207,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9110 §5.6.1", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding: chunked,\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { Description = "400 or 2xx", @@ -1168,6 +1233,7 @@ public static IEnumerable GetTestCases() RfcReference = "RFC 9110 §5.5", PayloadFactory = ctx => MakeRequest( $"POST / HTTP/1.1\r\nHost: {ctx.HostHeader}\r\nTransfer-Encoding:\tchunked\r\nContent-Length: 5\r\n\r\nhello"), + BehavioralAnalyzer = AnalyzeTeWithClFallback, Expected = new ExpectedBehavior { Description = "400 or 2xx", diff --git a/src/Http11Probe/TestCases/TestCase.cs b/src/Http11Probe/TestCases/TestCase.cs index 586a7e2..72e590c 100644 --- a/src/Http11Probe/TestCases/TestCase.cs +++ b/src/Http11Probe/TestCases/TestCase.cs @@ -1,3 +1,5 @@ +using Http11Probe.Response; + namespace Http11Probe.TestCases; public sealed class TestCase @@ -11,4 +13,5 @@ public sealed class TestCase public required ExpectedBehavior Expected { get; init; } public bool RequiresConnectionReuse { get; init; } public bool Scored { get; init; } = true; + public Func? BehavioralAnalyzer { get; init; } } diff --git a/src/Http11Probe/TestCases/TestResult.cs b/src/Http11Probe/TestCases/TestResult.cs index 61f710f..79e1bcc 100644 --- a/src/Http11Probe/TestCases/TestResult.cs +++ b/src/Http11Probe/TestCases/TestResult.cs @@ -11,5 +11,7 @@ public sealed class TestResult public HttpResponse? FollowUpResponse { get; init; } public ConnectionState ConnectionState { get; init; } public string? ErrorMessage { get; init; } + public string? BehavioralNote { get; init; } + public string? RawRequest { get; init; } public TimeSpan Duration { get; init; } } diff --git a/src/Servers/ActixServer/src/main.rs b/src/Servers/ActixServer/src/main.rs index e6cde26..793a81f 100644 --- a/src/Servers/ActixServer/src/main.rs +++ b/src/Servers/ActixServer/src/main.rs @@ -1,9 +1,15 @@ -use actix_web::{web, App, HttpServer, HttpResponse}; +use actix_web::{web, App, HttpServer, HttpRequest, HttpResponse}; -async fn ok() -> HttpResponse { - HttpResponse::Ok() - .content_type("text/plain") - .body("OK") +async fn handler(req: HttpRequest, body: web::Bytes) -> HttpResponse { + if req.method() == actix_web::http::Method::POST { + HttpResponse::Ok() + .content_type("text/plain") + .body(body) + } else { + HttpResponse::Ok() + .content_type("text/plain") + .body("OK") + } } #[actix_web::main] @@ -14,7 +20,7 @@ async fn main() -> std::io::Result<()> { .unwrap_or(8080); HttpServer::new(|| { - App::new().default_service(web::to(ok)) + App::new().default_service(web::to(handler)) }) .bind(("0.0.0.0", port))? .run() diff --git a/src/Servers/AspNetMinimal/Program.cs b/src/Servers/AspNetMinimal/Program.cs index 283d58d..022b93b 100644 --- a/src/Servers/AspNetMinimal/Program.cs +++ b/src/Servers/AspNetMinimal/Program.cs @@ -6,6 +6,11 @@ app.MapGet("/", () => "OK"); -app.MapPost("/", () => "OK"); +app.MapPost("/", async (HttpContext ctx) => +{ + using var reader = new StreamReader(ctx.Request.Body); + var body = await reader.ReadToEndAsync(); + return Results.Text(body); +}); app.Run(); diff --git a/src/Servers/BunServer/server.ts b/src/Servers/BunServer/server.ts index 7ffd53a..8cd288e 100644 --- a/src/Servers/BunServer/server.ts +++ b/src/Servers/BunServer/server.ts @@ -3,7 +3,11 @@ const port = parseInt(Bun.argv[2] || "8080", 10); Bun.serve({ port, hostname: "0.0.0.0", - fetch() { + async fetch(req) { + if (req.method === "POST") { + const body = await req.text(); + return new Response(body); + } return new Response("OK"); }, }); diff --git a/src/Servers/DenoServer/server.ts b/src/Servers/DenoServer/server.ts index 3fe61c5..58efb4c 100644 --- a/src/Servers/DenoServer/server.ts +++ b/src/Servers/DenoServer/server.ts @@ -1,3 +1,7 @@ -Deno.serve({ port: 8080, hostname: "0.0.0.0" }, () => { +Deno.serve({ port: 8080, hostname: "0.0.0.0" }, async (req) => { + if (req.method === "POST") { + const body = await req.text(); + return new Response(body, { headers: { "content-type": "text/plain" } }); + } return new Response("OK", { headers: { "content-type": "text/plain" } }); }); diff --git a/src/Servers/EmbedIOServer/Program.cs b/src/Servers/EmbedIOServer/Program.cs index 2606417..77e31c8 100644 --- a/src/Servers/EmbedIOServer/Program.cs +++ b/src/Servers/EmbedIOServer/Program.cs @@ -7,10 +7,19 @@ using var server = new WebServer(o => o .WithUrlPrefix(url) .WithMode(HttpListenerMode.EmbedIO)) - .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => + .WithModule(new ActionModule("/", HttpVerbs.Any, async ctx => { ctx.Response.ContentType = "text/plain"; - return ctx.SendStringAsync("OK", "text/plain", System.Text.Encoding.UTF8); + if (ctx.Request.HttpVerb == HttpVerbs.Post) + { + using var reader = new System.IO.StreamReader(ctx.Request.InputStream); + var body = await reader.ReadToEndAsync(); + await ctx.SendStringAsync(body, "text/plain", System.Text.Encoding.UTF8); + } + else + { + await ctx.SendStringAsync("OK", "text/plain", System.Text.Encoding.UTF8); + } })); Console.WriteLine($"EmbedIO listening on http://localhost:{port}"); diff --git a/src/Servers/ExpressServer/package-lock.json b/src/Servers/ExpressServer/package-lock.json new file mode 100644 index 0000000..63a1f0a --- /dev/null +++ b/src/Servers/ExpressServer/package-lock.json @@ -0,0 +1,757 @@ +{ + "name": "express-server", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "express-server", + "dependencies": { + "express": "^4.21.0" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" + }, + "node_modules/body-parser": { + "version": "1.20.4", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz", + "integrity": "sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.14.0", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==" + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.22.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz", + "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.3", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.12", + "proxy-addr": "~2.0.7", + "qs": "~6.14.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.14.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz", + "integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "engines": { + "node": ">= 0.8" + } + } + } +} diff --git a/src/Servers/ExpressServer/server.js b/src/Servers/ExpressServer/server.js index 1064a7f..a1aafd4 100644 --- a/src/Servers/ExpressServer/server.js +++ b/src/Servers/ExpressServer/server.js @@ -7,8 +7,10 @@ app.get("/", (_req, res) => { res.send("OK"); }); -app.post("/", (_req, res) => { - res.send("OK"); +app.post("/", (req, res) => { + const chunks = []; + req.on("data", (chunk) => chunks.push(chunk)); + req.on("end", () => res.send(Buffer.concat(chunks))); }); app.listen(port, "127.0.0.1", () => { diff --git a/src/Servers/FastHttpServer/main.go b/src/Servers/FastHttpServer/main.go index dfcd5b5..02cf6e7 100644 --- a/src/Servers/FastHttpServer/main.go +++ b/src/Servers/FastHttpServer/main.go @@ -14,6 +14,10 @@ func main() { handler := func(ctx *fasthttp.RequestCtx) { ctx.SetStatusCode(200) + if string(ctx.Method()) == "POST" { + ctx.SetBody(ctx.Request.Body()) + return + } ctx.SetBodyString("OK") } diff --git a/src/Servers/FlaskServer/app.py b/src/Servers/FlaskServer/app.py index 857ee75..dc37f53 100644 --- a/src/Servers/FlaskServer/app.py +++ b/src/Servers/FlaskServer/app.py @@ -1,5 +1,5 @@ import sys -from flask import Flask +from flask import Flask, request from werkzeug.routing import Rule app = Flask(__name__) @@ -9,6 +9,8 @@ @app.endpoint('catch_all') def catch_all(path): + if request.method == 'POST': + return request.get_data(as_text=True) return "OK" if __name__ == "__main__": diff --git a/src/Servers/GenHttpServer/GenHttpServer.csproj b/src/Servers/GenHttpServer/GenHttpServer.csproj index c423eff..57d2c3c 100644 --- a/src/Servers/GenHttpServer/GenHttpServer.csproj +++ b/src/Servers/GenHttpServer/GenHttpServer.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Servers/GenHttpServer/Program.cs b/src/Servers/GenHttpServer/Program.cs index 8f7b6cf..a5e0792 100644 --- a/src/Servers/GenHttpServer/Program.cs +++ b/src/Servers/GenHttpServer/Program.cs @@ -1,13 +1,29 @@ +using GenHTTP.Api.Content; +using GenHTTP.Api.Protocol; using GenHTTP.Engine.Internal; -using GenHTTP.Modules.IO; +using GenHTTP.Modules.Functional; using GenHTTP.Modules.Practices; var port = args.Length > 0 && int.TryParse(args[0], out var p) ? p : 8080; -var content = Content.From(Resource.FromString("OK")); +var handler = Inline.Create() + .Get(async (IRequest request) => + { + await ValueTask.CompletedTask; + return "OK"; + }) + .Post(async (IRequest request) => + { + if (request.Content is not null) + { + using var reader = new StreamReader(request.Content); + return await reader.ReadToEndAsync(); + } + return ""; + }); await Host.Create() - .Handler(content) + .Handler(handler) .Defaults() .Port((ushort)port) .RunAsync(); diff --git a/src/Servers/GinServer/main.go b/src/Servers/GinServer/main.go index 121b80a..11b589b 100644 --- a/src/Servers/GinServer/main.go +++ b/src/Servers/GinServer/main.go @@ -1,6 +1,7 @@ package main import ( + "io" "os" "github.com/gin-gonic/gin" @@ -15,6 +16,11 @@ func main() { gin.SetMode(gin.ReleaseMode) r := gin.New() r.NoRoute(func(c *gin.Context) { + if c.Request.Method == "POST" { + body, _ := io.ReadAll(c.Request.Body) + c.Data(200, "text/plain", body) + return + } c.String(200, "OK") }) r.Run("0.0.0.0:" + port) diff --git a/src/Servers/GlyphServer/Program.cs b/src/Servers/GlyphServer/Program.cs index a55d088..00b9006 100644 --- a/src/Servers/GlyphServer/Program.cs +++ b/src/Servers/GlyphServer/Program.cs @@ -141,6 +141,9 @@ static async Task HandleClientAsync(TcpClient client, CancellationToken ct) reader.AdvanceTo(headerBuffer.GetPosition(headerByteCount)); // ── Phase 4: consume body ────────────────────────── + var bodyBytes = new MemoryStream(); + const int maxCapture = 4096; + switch (framing.Framing) { case BodyFraming.ContentLength: @@ -151,6 +154,14 @@ static async Task HandleClientAsync(TcpClient client, CancellationToken ct) var result = await reader.ReadAsync(ct); var buffer = result.Buffer; long available = Math.Min(buffer.Length, remaining); + + if (bodyBytes.Length < maxCapture) + { + var toCapture = (int)Math.Min(available, maxCapture - bodyBytes.Length); + foreach (var seg in buffer.Slice(0, toCapture)) + bodyBytes.Write(seg.Span); + } + remaining -= available; reader.AdvanceTo(buffer.GetPosition(available)); @@ -188,9 +199,16 @@ static async Task HandleClientAsync(TcpClient client, CancellationToken ct) int totalConsumed = 0; while (true) { - var cr = chunked.TryReadChunk(span[totalConsumed..], out var consumed, out _, out _); + var localSpan = span[totalConsumed..]; + var cr = chunked.TryReadChunk(localSpan, out var consumed, out var dataOffset, out var dataLength); totalConsumed += consumed; + if (cr == ChunkResult.Chunk && dataLength > 0 && bodyBytes.Length < maxCapture) + { + var toCapture = Math.Min(dataLength, maxCapture - (int)bodyBytes.Length); + bodyBytes.Write(localSpan.Slice(dataOffset, toCapture)); + } + if (cr == ChunkResult.Completed) { done = true; @@ -221,7 +239,8 @@ static async Task HandleClientAsync(TcpClient client, CancellationToken ct) } // ── Phase 5: send response ───────────────────────── - var responseBytes = BuildResponse(method, path); + var capturedBody = bodyBytes.Length > 0 ? Encoding.ASCII.GetString(bodyBytes.ToArray()) : null; + var responseBytes = BuildResponse(method, path, capturedBody); await stream.WriteAsync(responseBytes, ct); } } @@ -244,9 +263,11 @@ static async Task HandleClientAsync(TcpClient client, CancellationToken ct) } } -static byte[] BuildResponse(string method, string path) +static byte[] BuildResponse(string method, string path, string? echoBody) { - var body = $"Hello from GlyphServer\r\nMethod: {method}\r\nPath: {path}\r\n"; + var body = method == "POST" && echoBody is not null + ? echoBody + : $"Hello from GlyphServer\r\nMethod: {method}\r\nPath: {path}\r\n"; return MakeResponse(200, "OK", body); } diff --git a/src/Servers/GunicornServer/__pycache__/app.cpython-312.pyc b/src/Servers/GunicornServer/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000..f3857b0 Binary files /dev/null and b/src/Servers/GunicornServer/__pycache__/app.cpython-312.pyc differ diff --git a/src/Servers/GunicornServer/app.py b/src/Servers/GunicornServer/app.py index ba72deb..669cbe3 100644 --- a/src/Servers/GunicornServer/app.py +++ b/src/Servers/GunicornServer/app.py @@ -1,3 +1,10 @@ def app(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) + if environ['REQUEST_METHOD'] == 'POST': + try: + length = int(environ.get('CONTENT_LENGTH', 0) or 0) + except ValueError: + length = 0 + body = environ['wsgi.input'].read(length) if length > 0 else b'' + return [body] return [b'OK'] diff --git a/src/Servers/H2OServer/h2o.conf b/src/Servers/H2OServer/h2o.conf index 9c4a6ae..0d297b6 100644 --- a/src/Servers/H2OServer/h2o.conf +++ b/src/Servers/H2OServer/h2o.conf @@ -4,4 +4,11 @@ hosts: paths: /: mruby.handler: | - proc {|env| [200, {"content-type" => "text/plain"}, ["OK"]] } + proc {|env| + if env["REQUEST_METHOD"] == "POST" + body = env["rack.input"] ? env["rack.input"].read : "" + [200, {"content-type" => "text/plain"}, [body]] + else + [200, {"content-type" => "text/plain"}, ["OK"]] + end + } diff --git a/src/Servers/HyperServer/src/main.rs b/src/Servers/HyperServer/src/main.rs index 66e14dd..f279878 100644 --- a/src/Servers/HyperServer/src/main.rs +++ b/src/Servers/HyperServer/src/main.rs @@ -9,7 +9,14 @@ use hyper::{Request, Response}; use hyper_util::rt::TokioIo; use tokio::net::TcpListener; -async fn handle(_req: Request) -> Result>, Infallible> { +async fn handle(req: Request) -> Result>, Infallible> { + if req.method() == hyper::Method::POST { + let body = match http_body_util::BodyExt::collect(req.into_body()).await { + Ok(collected) => collected.to_bytes(), + Err(_) => Bytes::new(), + }; + return Ok(Response::new(Full::new(body))); + } Ok(Response::new(Full::new(Bytes::from("OK")))) } diff --git a/src/Servers/JettyServer/src/main/java/server/Application.java b/src/Servers/JettyServer/src/main/java/server/Application.java index 65fc9c9..507d007 100644 --- a/src/Servers/JettyServer/src/main/java/server/Application.java +++ b/src/Servers/JettyServer/src/main/java/server/Application.java @@ -16,10 +16,15 @@ public class Application extends Handler.Abstract { ByteBuffer.wrap("OK".getBytes(StandardCharsets.UTF_8)).asReadOnlyBuffer(); @Override - public boolean handle(Request request, Response response, Callback callback) { + public boolean handle(Request request, Response response, Callback callback) throws Exception { response.setStatus(200); response.getHeaders().put("Content-Type", "text/plain"); - response.write(true, OK_BODY.slice(), callback); + if ("POST".equals(request.getMethod())) { + byte[] body = Request.asInputStream(request).readAllBytes(); + response.write(true, ByteBuffer.wrap(body), callback); + } else { + response.write(true, OK_BODY.slice(), callback); + } return true; } diff --git a/src/Servers/LighttpdServer/index.cgi b/src/Servers/LighttpdServer/index.cgi index ad94d45..8c23b46 100644 --- a/src/Servers/LighttpdServer/index.cgi +++ b/src/Servers/LighttpdServer/index.cgi @@ -1,2 +1,7 @@ #!/bin/sh -printf 'Content-Type: text/plain\r\n\r\nOK' +printf 'Content-Type: text/plain\r\n\r\n' +if [ "$REQUEST_METHOD" = "POST" ]; then + cat +else + printf 'OK' +fi diff --git a/src/Servers/NancyServer/Program.cs b/src/Servers/NancyServer/Program.cs index d261f39..2b8490a 100644 --- a/src/Servers/NancyServer/Program.cs +++ b/src/Servers/NancyServer/Program.cs @@ -21,7 +21,13 @@ public HomeModule() { Get("/{path*}", _ => "OK"); Get("/", _ => "OK"); - Post("/{path*}", _ => "OK"); - Post("/", _ => "OK"); + Post("/{path*}", _ => EchoBody()); + Post("/", _ => EchoBody()); + } + + private string EchoBody() + { + using var reader = new System.IO.StreamReader(Request.Body); + return reader.ReadToEnd(); } } diff --git a/src/Servers/NetCoreServerFramework/Program.cs b/src/Servers/NetCoreServerFramework/Program.cs index f1cf48f..e386ab8 100644 --- a/src/Servers/NetCoreServerFramework/Program.cs +++ b/src/Servers/NetCoreServerFramework/Program.cs @@ -21,7 +21,10 @@ public OkHttpSession(NetCoreServer.HttpServer server) : base(server) { } protected override void OnReceivedRequest(HttpRequest request) { - SendResponseAsync(Response.MakeOkResponse(200).SetBody("OK")); + if (request.Method == "POST" && request.Body.Length > 0) + SendResponseAsync(Response.MakeOkResponse(200).SetBody(request.Body)); + else + SendResponseAsync(Response.MakeOkResponse(200).SetBody("OK")); } protected override void OnReceivedRequestError(HttpRequest request, string error) diff --git a/src/Servers/NodeServer/server.js b/src/Servers/NodeServer/server.js index 5ddab47..c3439b4 100644 --- a/src/Servers/NodeServer/server.js +++ b/src/Servers/NodeServer/server.js @@ -3,8 +3,17 @@ const http = require('http'); const port = parseInt(process.argv[2] || '8080', 10); const server = http.createServer((req, res) => { - res.writeHead(200, { 'Content-Type': 'text/plain' }); - res.end('OK'); + if (req.method === 'POST') { + const chunks = []; + req.on('data', (chunk) => chunks.push(chunk)); + req.on('end', () => { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end(Buffer.concat(chunks)); + }); + } else { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end('OK'); + } }); server.listen(port, '0.0.0.0'); diff --git a/src/Servers/NtexServer/src/main.rs b/src/Servers/NtexServer/src/main.rs index a1813de..cafe1aa 100644 --- a/src/Servers/NtexServer/src/main.rs +++ b/src/Servers/NtexServer/src/main.rs @@ -1,7 +1,16 @@ use ntex::web; +use ntex::util::Bytes; -async fn ok() -> &'static str { - "OK" +async fn handler(req: web::HttpRequest, body: Bytes) -> web::HttpResponse { + if req.method() == ntex::http::Method::POST { + web::HttpResponse::Ok() + .content_type("text/plain") + .body(body) + } else { + web::HttpResponse::Ok() + .content_type("text/plain") + .body("OK") + } } #[ntex::main] @@ -12,7 +21,7 @@ async fn main() -> std::io::Result<()> { .unwrap_or(8080); web::server(|| { - web::App::new().default_service(web::to(ok)) + web::App::new().default_service(web::to(handler)) }) .bind(("0.0.0.0", port))? .run() diff --git a/src/Servers/PhpServer/index.php b/src/Servers/PhpServer/index.php index 897c436..04d3790 100644 --- a/src/Servers/PhpServer/index.php +++ b/src/Servers/PhpServer/index.php @@ -1,3 +1,7 @@ Result { + let is_post = session.req_header().method == pingora::http::Method::POST; + let body = if is_post { + let mut buf = Vec::new(); + while let Some(chunk) = session.read_request_body().await? { + buf.extend_from_slice(&chunk); + } + Bytes::from(buf) + } else { + Bytes::from_static(b"OK") + }; let mut header = ResponseHeader::build(200, None)?; header.insert_header("Content-Type", "text/plain")?; - header.insert_header("Content-Length", "2")?; + header.insert_header("Content-Length", &body.len().to_string())?; session .write_response_header(Box::new(header), false) .await?; session - .write_response_body(Some(Bytes::from_static(b"OK")), true) + .write_response_body(Some(body), true) .await?; Ok(true) } diff --git a/src/Servers/PumaServer/config.ru b/src/Servers/PumaServer/config.ru index 35ce95a..1d4ed48 100644 --- a/src/Servers/PumaServer/config.ru +++ b/src/Servers/PumaServer/config.ru @@ -1,2 +1,9 @@ -app = proc { |_env| [200, { 'content-type' => 'text/plain' }, ['OK']] } +app = proc { |env| + if env['REQUEST_METHOD'] == 'POST' + body = env['rack.input'].read + [200, { 'content-type' => 'text/plain' }, [body]] + else + [200, { 'content-type' => 'text/plain' }, ['OK']] + end +} run app diff --git a/src/Servers/QuarkusServer/src/main/java/server/Application.java b/src/Servers/QuarkusServer/src/main/java/server/Application.java index 0f7052b..0adc237 100644 --- a/src/Servers/QuarkusServer/src/main/java/server/Application.java +++ b/src/Servers/QuarkusServer/src/main/java/server/Application.java @@ -1,5 +1,8 @@ package server; +import java.io.InputStream; +import java.io.IOException; + import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; @@ -19,7 +22,7 @@ public String catchAll() { @POST @Path("{path:.*}") @Produces(MediaType.TEXT_PLAIN) - public String catchAllPost() { - return "OK"; + public byte[] catchAllPost(InputStream body) throws IOException { + return body.readAllBytes(); } } diff --git a/src/Servers/ServiceStackServer/Program.cs b/src/Servers/ServiceStackServer/Program.cs index c8acbea..5286a2c 100644 --- a/src/Servers/ServiceStackServer/Program.cs +++ b/src/Servers/ServiceStackServer/Program.cs @@ -4,7 +4,16 @@ var app = builder.Build(); app.UseServiceStack(new AppHost()); -app.MapFallback(() => Results.Ok("OK")); +app.MapFallback(async (HttpContext ctx) => +{ + if (ctx.Request.Method == "POST") + { + using var reader = new StreamReader(ctx.Request.Body); + var body = await reader.ReadToEndAsync(); + return Results.Text(body); + } + return Results.Ok("OK"); +}); app.Run("http://0.0.0.0:8080"); class AppHost : AppHostBase diff --git a/src/Servers/SimpleWServer/Program.cs b/src/Servers/SimpleWServer/Program.cs index 9748b1d..2d980f5 100644 --- a/src/Servers/SimpleWServer/Program.cs +++ b/src/Servers/SimpleWServer/Program.cs @@ -8,8 +8,8 @@ server.MapGet("/", () => "OK"); server.MapGet("/{path}", () => "OK"); -server.MapPost("/", () => "OK"); -server.MapPost("/{path}", () => "OK"); +server.MapPost("/", (HttpSession session) => session.Request.BodyString); +server.MapPost("/{path}", (HttpSession session) => session.Request.BodyString); Console.WriteLine($"SimpleW listening on http://localhost:{port}"); diff --git a/src/Servers/SiskServer/Program.cs b/src/Servers/SiskServer/Program.cs index 1163b11..e4a0ccf 100644 --- a/src/Servers/SiskServer/Program.cs +++ b/src/Servers/SiskServer/Program.cs @@ -9,6 +9,11 @@ app.Router.SetRoute(RouteMethod.Any, Route.AnyPath, request => { + if (request.Method == HttpMethod.Post && request.Body is not null) + { + var body = request.Body; + return new HttpResponse(200).WithContent(body); + } return new HttpResponse(200).WithContent("OK"); }); diff --git a/src/Servers/SpringBootServer/src/main/java/server/Application.java b/src/Servers/SpringBootServer/src/main/java/server/Application.java index 0117c13..29661cf 100644 --- a/src/Servers/SpringBootServer/src/main/java/server/Application.java +++ b/src/Servers/SpringBootServer/src/main/java/server/Application.java @@ -2,10 +2,14 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import jakarta.servlet.http.HttpServletRequest; +import java.io.IOException; + @SpringBootApplication @RestController public class Application { @@ -14,8 +18,13 @@ public static void main(String[] args) { SpringApplication.run(Application.class, args); } - @RequestMapping(value = "/", method = {RequestMethod.GET, RequestMethod.POST}) - public String index() { + @RequestMapping(value = "/", method = RequestMethod.GET) + public String indexGet() { return "OK"; } + + @RequestMapping(value = "/", method = RequestMethod.POST) + public byte[] indexPost(HttpServletRequest request) throws IOException { + return request.getInputStream().readAllBytes(); + } } diff --git a/src/Servers/TomcatServer/webapp/ok.jsp b/src/Servers/TomcatServer/webapp/ok.jsp index 8534ce6..25d3811 100644 --- a/src/Servers/TomcatServer/webapp/ok.jsp +++ b/src/Servers/TomcatServer/webapp/ok.jsp @@ -1 +1,9 @@ -<%@page contentType="text/plain"%><% out.print("OK"); %> \ No newline at end of file +<%@page contentType="text/plain" import="java.io.*"%><% +if ("POST".equals(request.getMethod())) { + InputStream in = request.getInputStream(); + byte[] buf = in.readAllBytes(); + out.print(new String(buf, "UTF-8")); +} else { + out.print("OK"); +} +%> \ No newline at end of file diff --git a/src/Servers/UvicornServer/__pycache__/app.cpython-312.pyc b/src/Servers/UvicornServer/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000..80f5291 Binary files /dev/null and b/src/Servers/UvicornServer/__pycache__/app.cpython-312.pyc differ diff --git a/src/Servers/UvicornServer/app.py b/src/Servers/UvicornServer/app.py index cd198d2..e5d9f24 100644 --- a/src/Servers/UvicornServer/app.py +++ b/src/Servers/UvicornServer/app.py @@ -1,4 +1,13 @@ async def app(scope, receive, send): + body = b'OK' + if scope.get('method') == 'POST': + chunks = [] + while True: + msg = await receive() + chunks.append(msg.get('body', b'')) + if not msg.get('more_body', False): + break + body = b''.join(chunks) await send({ 'type': 'http.response.start', 'status': 200, @@ -6,5 +15,5 @@ async def app(scope, receive, send): }) await send({ 'type': 'http.response.body', - 'body': b'OK', + 'body': body, }) diff --git a/src/Servers/WatsonServer/Program.cs b/src/Servers/WatsonServer/Program.cs index 0291202..f93adc6 100644 --- a/src/Servers/WatsonServer/Program.cs +++ b/src/Servers/WatsonServer/Program.cs @@ -8,7 +8,16 @@ { ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; - await ctx.Response.Send("OK"); + if (ctx.Request.Method == WatsonWebserver.Core.HttpMethod.POST && ctx.Request.Data != null) + { + using var reader = new StreamReader(ctx.Request.Data); + var body = await reader.ReadToEndAsync(); + await ctx.Response.Send(body); + } + else + { + await ctx.Response.Send("OK"); + } }); server.Start();