@@ -19,6 +19,8 @@ local weak_ptr, gc_collect, dump_mime_ = utils.import('weak_ptr', 'gc_collect',
1919
2020local GET_URL = ' http://127.0.0.1:7090/get'
2121
22+ local null = curl .null
23+
2224local function is_freed (c )
2325 return not not string.find (tostring (c ), ' %(freed%)' )
2426end
@@ -313,6 +315,15 @@ function test_unset_name()
313315 assert_not_match (' Content%-Disposition:.-name="test"' , info )
314316end
315317
318+ function test_unset_name_by_null ()
319+ mime :addpart ():data (' hello' , ' test/html' , ' test' ):name (null )
320+
321+ local info = assert_string (dump_mime (mime ))
322+ assert_match (' \r\n\r\n hello' , info )
323+ assert_match (' Content%-Type:%s+test/html' , info )
324+ assert_not_match (' Content%-Disposition:.-name="test"' , info )
325+ end
326+
316327function test_unset_type ()
317328 mime :addpart ():data (' hello' , ' test/html' ):type (false )
318329
@@ -321,6 +332,14 @@ function test_unset_type()
321332 assert_not_match (' Content%-Type:%s+test/html' , info )
322333end
323334
335+ function test_unset_type_by_null ()
336+ mime :addpart ():data (' hello' , ' test/html' ):type (null )
337+
338+ local info = assert_string (dump_mime (mime ))
339+ assert_match (' \r\n\r\n hello' , info )
340+ assert_not_match (' Content%-Type:%s+test/html' , info )
341+ end
342+
324343function test_unset_headers ()
325344 mime :addpart ():data (' hello' , ' test/html' ,{
326345 ' X-Custom-Header: hello'
@@ -331,6 +350,26 @@ function test_unset_headers()
331350 assert_not_match (' X%-Custom%-Header:%s*hello' , info )
332351end
333352
353+ function test_unset_headers_by_null ()
354+ mime :addpart ():data (' hello' , ' test/html' ,{
355+ ' X-Custom-Header: hello'
356+ }):headers (null )
357+
358+ local info = assert_string (dump_mime (mime ))
359+ assert_match (' \r\n\r\n hello' , info )
360+ assert_not_match (' X%-Custom%-Header:%s*hello' , info )
361+ end
362+
363+ function test_unset_headers_by_empty_array ()
364+ mime :addpart ():data (' hello' , ' test/html' ,{
365+ ' X-Custom-Header: hello'
366+ }):headers ({})
367+
368+ local info = assert_string (dump_mime (mime ))
369+ assert_match (' \r\n\r\n hello' , info )
370+ assert_not_match (' X%-Custom%-Header:%s*hello' , info )
371+ end
372+
334373function test_unset_data ()
335374 mime :addpart ():data (' hello' , ' test/html' , ' test' ):data (false )
336375
@@ -340,6 +379,15 @@ function test_unset_data()
340379 assert_match (' Content%-Disposition:.-name="test"' , info )
341380end
342381
382+ function test_unset_data_by_null ()
383+ mime :addpart ():data (' hello' , ' test/html' , ' test' ):data (null )
384+
385+ local info = assert_string (dump_mime (mime ))
386+ assert_not_match (' \r\n\r\n hello' , info )
387+ assert_match (' Content%-Type:%s+test/html' , info )
388+ assert_match (' Content%-Disposition:.-name="test"' , info )
389+ end
390+
343391function test_unset_data_type_1 ()
344392 local part = mime :addpart ():data (' hello' , ' test/html' , ' test' , {
345393 ' X-Custom-Header: hello'
@@ -352,6 +400,18 @@ function test_unset_data_type_1()
352400 assert_match (' X%-Custom%-Header:%s*hello' , info )
353401end
354402
403+ function test_unset_data_type_1_by_null ()
404+ local part = mime :addpart ():data (' hello' , ' test/html' , ' test' , {
405+ ' X-Custom-Header: hello'
406+ }):data (' hello' , null )
407+
408+ local info = assert_string (dump_mime (mime ))
409+ assert_match (' \r\n\r\n hello' , info )
410+ assert_not_match (' Content%-Type:%s+test/html' , info )
411+ assert_match (' Content%-Disposition:.-name="test"' , info )
412+ assert_match (' X%-Custom%-Header:%s*hello' , info )
413+ end
414+
355415function test_unset_data_type_2 ()
356416 local part = mime :addpart ():data (' hello' , ' test/html' , ' test' , {
357417 ' X-Custom-Header: hello'
@@ -376,6 +436,18 @@ function test_unset_data_name_1()
376436 assert_match (' X%-Custom%-Header:%s*hello' , info )
377437end
378438
439+ function test_unset_data_name_1_by_null ()
440+ local part = mime :addpart ():data (' hello' , ' test/html' , ' test' , {
441+ ' X-Custom-Header: hello'
442+ }):data (' hello' , nil , null )
443+
444+ local info = assert_string (dump_mime (mime ))
445+ assert_match (' \r\n\r\n hello' , info )
446+ assert_match (' Content%-Type:%s+test/html' , info )
447+ assert_not_match (' Content%-Disposition:.-name="test"' , info )
448+ assert_match (' X%-Custom%-Header:%s*hello' , info )
449+ end
450+
379451function test_unset_data_name_2 ()
380452 local part = mime :addpart ():data (' hello' , ' test/html' , ' test' , {
381453 ' X-Custom-Header: hello'
@@ -400,6 +472,18 @@ function test_unset_data_header()
400472 assert_not_match (' X%-Custom%-Header:%s*hello' , info )
401473end
402474
475+ function test_unset_data_header_by_null ()
476+ local part = mime :addpart ():data (' hello' , ' test/html' , ' test' , {
477+ ' X-Custom-Header: hello'
478+ }):data (' hello' , nil , nil , nil , null )
479+
480+ local info = assert_string (dump_mime (mime ))
481+ assert_match (' \r\n\r\n hello' , info )
482+ assert_match (' Content%-Type:%s+test/html' , info )
483+ assert_match (' Content%-Disposition:.-name="test"' , info )
484+ assert_not_match (' X%-Custom%-Header:%s*hello' , info )
485+ end
486+
403487function test_unset_data_filename_1 ()
404488 local part = mime :addpart ():data (' hello' , ' test/html' , ' test' , ' test.html' , {
405489 ' X-Custom-Header: hello'
@@ -409,7 +493,20 @@ function test_unset_data_filename_1()
409493 assert_match (' \r\n\r\n hello' , info )
410494 assert_match (' Content%-Type:%s+test/html' , info )
411495 assert_match (' Content%-Disposition:.-%sname="test"' , info )
412- assert_not_match (' Content%-Disposition:.-%sname="test%.html"' , info )
496+ assert_not_match (' Content%-Disposition:.-%sfilename="test%.html"' , info )
497+ assert_match (' X%-Custom%-Header:%s*hello' , info )
498+ end
499+
500+ function test_unset_data_filename_1_by_null ()
501+ local part = mime :addpart ():data (' hello' , ' test/html' , ' test' , ' test.html' , {
502+ ' X-Custom-Header: hello'
503+ }):data (' hello' , nil , nil , null )
504+
505+ local info = assert_string (dump_mime (mime ))
506+ assert_match (' \r\n\r\n hello' , info )
507+ assert_match (' Content%-Type:%s+test/html' , info )
508+ assert_match (' Content%-Disposition:.-%sname="test"' , info )
509+ assert_not_match (' Content%-Disposition:.-%sfilename="test%.html"' , info )
413510 assert_match (' X%-Custom%-Header:%s*hello' , info )
414511end
415512
0 commit comments