Skip to content

Commit

Permalink
[add] cgiスクリプトでプリントされたConnectionが適用されているかのテスト追加
Browse files Browse the repository at this point in the history
  • Loading branch information
eito2002 committed Oct 11, 2024
1 parent 7a55d34 commit 7d2dd5b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions root/cgi-bin/print_ok_close.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/perl

use strict;
use warnings;

print "Connection: close\r\n";
print "Content-Type: text/plain\r\n\r\n";
print "OK\n"
8 changes: 8 additions & 0 deletions root/cgi-bin/print_ok_keep.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/perl

use strict;
use warnings;

print "Connection: keep-alive\r\n";
print "Content-Type: text/plain\r\n\r\n";
print "OK\n"
27 changes: 27 additions & 0 deletions test/webserv/integration/test_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ def test_print_ok_pl_keep(self):
except HTTPException as e:
self.fail(f"Request failed: {e}")

# CgiResponseの中のConnectionヘッダーが適用されているか
def test_print_ok_close_pl(self):
try:
self.con.request(
"GET",
"/cgi-bin/print_ok_close.pl",
headers={"Connection": "keep-alive"},
)
response = self.con.getresponse()
assert_status_line(response, HTTPStatus.OK)
assert_header(response, "Connection", "close")
self.assertEqual(response.read(), b"OK\n")
except HTTPException as e:
self.fail(f"Request failed: {e}")

def test_print_ok_keep_pl(self):
try:
self.con.request(
"GET", "/cgi-bin/print_ok_keep.pl", headers={"Connection": "close"}
)
response = self.con.getresponse()
assert_status_line(response, HTTPStatus.OK)
assert_header(response, "Connection", "keep-alive")
self.assertEqual(response.read(), b"OK\n")
except HTTPException as e:
self.fail(f"Request failed: {e}")

def test_print_env_pl(self):
try:
self.con.request("GET", "/cgi-bin/print_env.pl")
Expand Down

0 comments on commit 7d2dd5b

Please sign in to comment.