From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM, NUMERIC_HTTP_ADDR,URIBL_BLOCKED,WEIRD_PORT autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [180.246.144.41]) by gnuweeb.org (Postfix) with ESMTPSA id C3F1080A16; Sun, 21 Aug 2022 11:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1661081148; bh=fJnQtqcm880tVQenrGlHX3vcxYfJvpaa8Me3flupZ/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t7ugodPxFnl6eTyGTKTaCTay7PyqnqRvYR6dQWLGEhFia7aFqvo9MSgUbjs9Wk7WB uNt7dnb9OV8Qki/sA69KVZeP0P2CCr2z3MoTH3/0TuWsian4c30813lPnxdxBotA/C EUA0m1MDRMMJapzBMRwEdAYLoxZZtabdq+/F70bXT+y/m/c9aeYnyPQfpZnTbzhzta DiJbLwz10K0EwISIqLZuM4XC702beSNhkXH6k89u6qYhdWS95VHKVCdWGSSdbUIDxa qYpFYIQftd4q0aqEZbkWRziIdWNb2JFRadomGBtuv6UkBPnAfSNDw+GsqXBReKS5IV OBmmOgPRFUqZQ== From: Ammar Faizi To: Alviro Iskandar Setiawan Cc: Ammar Faizi , Muhammad Rizki , Kanna Scarlet , GNU/Weeb Mailing List Subject: [PATCH v1 14/22] tests/js/ring: Add more set header function test Date: Sun, 21 Aug 2022 18:24:45 +0700 Message-Id: <20220821112453.3026255-15-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220821112453.3026255-1-ammarfaizi2@gnuweeb.org> References: <20220821112453.3026255-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Now, let's test that content-type header can be set properly. Signed-off-by: Ammar Faizi --- tests/index.php | 8 ++++++++ tests/js/ring.js | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tests/index.php b/tests/index.php index 55639c6..4a56233 100644 --- a/tests/index.php +++ b/tests/index.php @@ -20,4 +20,12 @@ case "body": case "user_agent": echo $_SERVER["HTTP_USER_AGENT"] ?? ""; break; +case "print_post": + if (!isset($_GET["key"]) || !is_string($_GET["key"])) { + echo "Missing key!"; + break; + } + + echo $_POST[$_GET["key"]] ?? ""; + break; } diff --git a/tests/js/ring.js b/tests/js/ring.js index 4b081ae..6752fe1 100644 --- a/tests/js/ring.js +++ b/tests/js/ring.js @@ -151,12 +151,26 @@ function test_simple_http_set_header() assert(h.ch.read_ret() === ua.length); } +function test_simple_http_post_set_header() +{ + const ss = "This is just a test string!"; + let h = new SimpleHttp("http://127.0.0.1:8000/index.php?action=print_post&key=test", "POST"); + h.ch.set_request_header("User-Agent", ss); + h.ch.set_request_header("Content-type", "application/x-www-form-urlencoded"); + h.ch.set_payload("test="+encodeURIComponent(ss)); + h.prep_read(1024); + h.run(); + assert(h.get_buffer() === ss); + assert(h.ch.read_ret() === ss.length); +} + function main() { test_nop(); test_chnet_ring_multiple(); test_simple_http(); test_simple_http_set_header(); + test_simple_http_post_set_header(); } main(); -- Ammar Faizi