@@ -35,6 +35,8 @@ local POST_URL = "http://127.0.0.1:7090/post"
3535local weak_ptr , gc_collect , is_curl_ge , read_file , stream , Stream , dump_request =
3636 utils .import (' weak_ptr' , ' gc_collect' , ' is_curl_ge' , ' read_file' , ' stream' , ' Stream' , ' dump_request' )
3737
38+ local null = curl .null
39+
3840local ENABLE = true
3941
4042local _ENV = TEST_CASE ' curl error' if ENABLE then
@@ -1060,4 +1062,53 @@ end
10601062
10611063end
10621064
1065+ local _ENV = TEST_CASE ' set_null' if ENABLE then
1066+
1067+ local c
1068+
1069+ function teardown ()
1070+ if c then c :close () end
1071+ c = nil
1072+ end
1073+
1074+ function test_string ()
1075+ c = curl .easy ()
1076+ c :setopt_accept_encoding (' gzip' )
1077+ local body , headers = assert_string (dump_request (c ))
1078+ assert_match (" Accept%-Encoding:%s*gzip" , headers )
1079+
1080+ c :setopt_accept_encoding (null )
1081+ body , headers = assert_string (dump_request (c ))
1082+ assert_not_match (" Accept%-Encoding:%s*gzip" , headers )
1083+ end
1084+
1085+ function test_string_via_table ()
1086+ c = curl .easy ()
1087+ c :setopt_accept_encoding (' gzip' )
1088+ local body , headers = assert_string (dump_request (c ))
1089+ assert_match (" Accept%-Encoding:%s*gzip" , headers )
1090+
1091+ c :setopt { accept_encoding = null }
1092+ body , headers = assert_string (dump_request (c ))
1093+ assert_not_match (" Accept%-Encoding:%s*gzip" , headers )
1094+ end
1095+
1096+ function test_slist ()
1097+ c = curl .easy ()
1098+ c :setopt_httpheader ({' X-Custom: value' })
1099+ c :setopt_httpheader (null )
1100+ local body , headers = assert_string (dump_request (c ))
1101+ assert_not_match (" X%-Custom:%s*value\r\n " , headers )
1102+ end
1103+
1104+ function test_slist_via_table ()
1105+ c = curl .easy ()
1106+ c :setopt_httpheader ({' X-Custom: value' })
1107+ c :setopt {httpheader = null }
1108+ local body , headers = assert_string (dump_request (c ))
1109+ assert_not_match (" X%-Custom:%s*value\r\n " , headers )
1110+ end
1111+
1112+ end
1113+
10631114RUN ()
0 commit comments