vtest "VMOD blob test transcode() n chars"

vinyl v1 -vcl {
	import blob;
	import std;
	backend b None;

	sub vcl_recv {
	  return(synth(200));
	}

	sub vcl_synth {
	    set req.http.foobar = "foo:bar:baz:quux";
	    set req.http.hobbes =
{"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."};
	    set req.http.hobbesb64 =
{"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="};
	    set req.http.hexhobbes = "4d616e2069732064697374696e677569736865642c206e6f74206f6e6c792062792068697320726561736f6e2c2062757420627920746869732073696e67756c61722070617373696f6e2066726f6d206f7468657220616e696d616c732c2077686963682069732061206c757374206f6620746865206d696e642c20746861742062792061207065727365766572616e6365206f662064656c6967687420696e2074686520636f6e74696e75656420616e6420696e6465666174696761626c652067656e65726174696f6e206f66206b6e6f776c656467652c2065786365656473207468652073686f727420766568656d656e6365206f6620616e79206361726e616c20706c6561737572652e";
	    set req.http.hexalldown =
{"fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e0dfdedddcdbdad9d8d7d6d5d4d3d2d1d0cfcecdcccbcac9c8c7c6c5c4c3c2c1c0bfbebdbcbbbab9b8b7b6b5b4b3b2b1b0afaeadacabaaa9a8a7a6a5a4a3a2a1a09f9e9d9c9b9a999897969594939291908f8e8d8c8b8a898887868584838281807f7e7d7c7b7a797877767574737271706f6e6d6c6b6a696867666564636261605f5e5d5c5b5a595857565554535251504f4e4d4c4b4a494847464544434241403f3e3d3c3b3a393837363534333231302f2e2d2c2b2a292827262524232221201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100"};
	    set req.http.hexallup =
{"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"};

	  set resp.http.id2id
	    = blob.transcode(IDENTITY, IDENTITY, length=5,
			     encoded="Hello world");

	  set resp.http.id2b64
	    = blob.transcode(IDENTITY, BASE64, length=5,
			     encoded=req.http.hobbes);

	  set resp.http.id2b64nopad
	    = blob.transcode(IDENTITY, BASE64URLNOPAD, length=5,
			     encoded=req.http.hobbes);

	  set resp.http.id2hex
	    = blob.transcode(IDENTITY, HEX, length=5, encoded=req.http.hobbes);

	  set resp.http.id2hexuc
	    = blob.transcode(IDENTITY, HEX, UPPER, 5, req.http.hobbes);

	  set resp.http.id2hexlc
	    = blob.transcode(IDENTITY, HEX, LOWER, 5, req.http.hobbes);

	  set resp.http.id2url
	    = blob.transcode(IDENTITY, URL, length=5, encoded=req.http.foobar);

	  set resp.http.id2urluc
	    = blob.transcode(IDENTITY, URL, UPPER, 5, req.http.foobar);

	  set resp.http.id2urllc
	    = blob.transcode(IDENTITY, URL, LOWER, 5, req.http.foobar);

	  set resp.http.b642id
	    = blob.transcode(BASE64, IDENTITY, length=8,
			     encoded=req.http.hobbesb64);

	  set resp.http.hex2id
	    = blob.transcode(HEX, IDENTITY, length=12,
			     encoded=req.http.hexhobbes);

	  set resp.http.hexalldown2b64
	    = blob.transcode(HEX, BASE64, length=12,
			     encoded=req.http.hexalldown);

	  set resp.http.hexalldown2b64url
	    = blob.transcode(HEX, BASE64URL, length=12,
			     encoded=req.http.hexalldown);

	  set resp.http.hexalldown2b64nopad
	    = blob.transcode(HEX, BASE64URLNOPAD, length=10,
			     encoded=req.http.hexalldown);

	  set resp.http.hexallup2b64
	    = blob.transcode(HEX, BASE64, length=12, encoded=req.http.hexallup);

	  set resp.http.hexallup2b64url
	    = blob.transcode(HEX, BASE64URL, length=10,
			     encoded=req.http.hexallup);

	  set resp.http.hexallup2b64nopad
	    = blob.transcode(HEX, BASE64URLNOPAD, length=10,
			     encoded=req.http.hexallup);

	  set resp.http.hexalldown2url
	    = blob.transcode(HEX, URL, length=12, encoded=req.http.hexalldown);

	  set resp.http.hexalldown2urluc
	    = blob.transcode(HEX, URL, UPPER, 12, req.http.hexalldown);

	  set resp.http.hexalldown2urllc
	    = blob.transcode(HEX, URL, LOWER, 12, req.http.hexalldown);

	  set resp.http.hexallup2url
	    = blob.transcode(HEX, URL, length=12, encoded=req.http.hexallup);

	  set resp.http.hexallup2urluc
	    = blob.transcode(HEX, URL, UPPER, 12, req.http.hexallup);

	  set resp.http.hexallup2urllc
	    = blob.transcode(HEX, URL, LOWER, 12, req.http.hexallup);

	}
} -start

client c1 {
	txreq
	rxresp
	expect resp.http.id2id == "Hello"
	expect resp.http.id2b64 == "TWFuIGk="
	expect resp.http.id2b64nopad == "TWFuIGk"
	expect resp.http.id2hex == "4d616e2069"
	expect resp.http.id2hexuc == "4D616E2069"
	expect resp.http.id2hexlc == resp.http.id2hex
	expect resp.http.id2url == "foo%3ab"
	expect resp.http.id2urluc == "foo%3Ab"
	expect resp.http.id2urllc == resp.http.id2url
	expect resp.http.b642id == "Man is"
	expect resp.http.hex2id == "Man is"
	expect resp.http.hexalldown2b64 == "//79/Pv6"
	expect resp.http.hexalldown2b64url == "__79_Pv6"
	expect resp.http.hexalldown2b64nopad == "__79_Ps"
	expect resp.http.hexallup2b64 == "AAECAwQF"
	expect resp.http.hexallup2b64url == "AAECAwQ="
	expect resp.http.hexallup2b64nopad == "AAECAwQ"
	expect resp.http.hexalldown2url == "%ff%fe%fd%fc%fb%fa"
	expect resp.http.hexalldown2urluc == "%FF%FE%FD%FC%FB%FA"
	expect resp.http.hexalldown2urllc == resp.http.hexalldown2url
	expect resp.http.hexallup2url == "%00%01%02%03%04%05"
	expect resp.http.hexallup2urllc == resp.http.hexallup2url
	expect resp.http.hexallup2urllc == resp.http.hexallup2url
} -run

vinyl v1 -vcl {
	import blob;
	import std;
	backend b None;

	sub vcl_recv {
	  return(synth(200));
	}

	sub vcl_synth {
	    set req.http.b64all =
{"AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIIIJJJJKKKKLLLLMMMMNNNNOOOOPPPPQQQQRRRRSSSSTTTTUUUUVVVVWWWWXXXXYYYYZZZZaaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz0000111122223333444455556666777788889999++++////"};
	    set req.http.b64allurl =
{"AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIIIJJJJKKKKLLLLMMMMNNNNOOOOPPPPQQQQRRRRSSSSTTTTUUUUVVVVWWWWXXXXYYYYZZZZaaaabbbbccccddddeeeeffffgggghhhhiiiijjjjkkkkllllmmmmnnnnooooppppqqqqrrrrssssttttuuuuvvvvwwwwxxxxyyyyzzzz0000111122223333444455556666777788889999----____"};

	  set resp.http.b64all2hex
	    = blob.transcode(BASE64, HEX, length=8, encoded=req.http.b64all);

	  set resp.http.b64all2hexuc
	    = blob.transcode(BASE64, HEX, UPPER, 8, req.http.b64all);

	  set resp.http.b64all2hexlc
	    = blob.transcode(BASE64, HEX, LOWER, 8, req.http.b64all);

	  set resp.http.b64allurl2hex
	    = blob.transcode(BASE64URL, HEX, length=8,
			     encoded=req.http.b64allurl);

	  set resp.http.b64allurl2hexuc
	    = blob.transcode(BASE64URL, HEX, UPPER, 8, req.http.b64allurl);

	  set resp.http.b64allurl2hexlc
	    = blob.transcode(BASE64URL, HEX, LOWER, 8, req.http.b64allurl);

	  set resp.http.b64all2url
	    = blob.transcode(BASE64, URL, length=8, encoded=req.http.b64all);

	  set resp.http.b64all2urluc
	    = blob.transcode(BASE64, URL, UPPER, 8, req.http.b64all);

	  set resp.http.b64all2urllc
	    = blob.transcode(BASE64, URL, LOWER, 8, req.http.b64all);

	  set resp.http.b64allurl2url
	    = blob.transcode(BASE64URL, URL, length=8,
			     encoded=req.http.b64allurl);

	  set resp.http.b64allurl2urluc
	    = blob.transcode(BASE64URL, URL, UPPER, 8, req.http.b64allurl);

	  set resp.http.b64allurl2urllc
	    = blob.transcode(BASE64URL, URL, LOWER, 8, req.http.b64allurl);

	  set resp.http.hexuc2hex
	    = blob.transcode(HEX, HEX, length=10, encoded="0123456789ABCDEF");

	  set resp.http.hexuc2hexuc
	    = blob.transcode(HEX, HEX, UPPER, 10, "0123456789ABCDEF");

	  set resp.http.hexlc2hex
	    = blob.transcode(HEX, HEX, length=10, encoded="0123456789abcdef");

	  set resp.http.hexlc2hexlc
	    = blob.transcode(HEX, HEX, LOWER, 10, "0123456789abcdef");

	  set resp.http.hexuc2hexlc
	    = blob.transcode(HEX, HEX, LOWER, 9, "0123456789ABCDEF");

	  set resp.http.hexlc2hexuc
	    = blob.transcode(HEX, HEX, UPPER, 9, "0123456789abcdef");

	  set resp.http.hexmix2hex
	    = blob.transcode(HEX, HEX, length=13, encoded="0123456789abcDEF");

	  set resp.http.hexmix2hexuc
	    = blob.transcode(HEX, HEX, UPPER, 15, "0123456789ABCdef");

	  set resp.http.hexmix2hexlc
	    = blob.transcode(HEX, HEX, LOWER, 13, "0123456789abcDEF");

	  set req.http.hexpart1 = "01234567";
	  set req.http.hexpart2 = "89abcdef";
	  set resp.http.hexparam
	    = blob.transcode(encoded="" + req.http.unset + ""
				   + req.http.unset + "" + req.http.hexpart1
				   + "" + req.http.unset + "" + req.http.unset
				   + req.http.hexpart2, decoding=HEX,
				   encoding=HEX, length=10, case=UPPER);

	  set resp.http.b642b64
	    = blob.transcode(BASE64, BASE64, length=36, encoded=
				   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
				   + "ghijklmnopqrstuvwxyz0123456789+/");

	  set resp.http.b64url2b64url =
	    blob.transcode(BASE64URL, BASE64URL, length=34, encoded=
				 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
				 + "ghijklmnopqrstuvwxyz0123456789-_");

	  set resp.http.b64urlnopad2b64urlnopad =
	    blob.transcode(BASE64URLNOPAD, BASE64URLNOPAD, length=34, encoded=
				 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
				 + "ghijklmnopqrstuvwxyz0123456789-_");

	}
}

client c1 {
	txreq
	rxresp
	expect resp.http.b64all2hex == "000000041041"
	expect resp.http.b64all2hexuc == resp.http.b64all2hex
	expect resp.http.b64all2hexlc == resp.http.b64all2hex
	expect resp.http.b64allurl2hex == "000000041041"
	expect resp.http.b64allurl2hexuc == resp.http.b64allurl2hex
	expect resp.http.b64allurl2hexlc == resp.http.b64allurl2hex
	expect resp.http.b64all2url == "%00%00%00%04%10A"
	expect resp.http.b64all2urluc == resp.http.b64all2url
	expect resp.http.b64all2urllc == resp.http.b64all2url
	expect resp.http.b64allurl2url == "%00%00%00%04%10A"
	expect resp.http.b64allurl2urluc == resp.http.b64allurl2url
	expect resp.http.b64allurl2urllc == resp.http.b64allurl2url
	expect resp.http.hexuc2hex == "0123456789"
	expect resp.http.hexlc2hex == resp.http.hexuc2hex
	expect resp.http.hexlc2hexlc == resp.http.hexuc2hex
	expect resp.http.hexuc2hexlc == "0012345678"
	expect resp.http.hexlc2hexuc == resp.http.hexuc2hexlc
	expect resp.http.hexmix2hex == "00123456789abc"
	expect resp.http.hexmix2hexuc == "00123456789ABCDE"
	expect resp.http.hexmix2hexlc == resp.http.hexmix2hex
	expect resp.http.hexparam == "0123456789"
	expect resp.http.b642b64 == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij"
	expect resp.http.b64url2b64url == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgg=="
	expect resp.http.b64urlnopad2b64urlnopad == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefgg"
} -run

vinyl v1 -vcl {
	import blob;
	import std;
	backend b None;

	sub vcl_recv {
	  return(synth(200));
	}

	sub vcl_synth {
	    set req.http.urlhobbeslc = "Man%20is%20distinguished%2c%20not%20only%20by%20his%20reason%2c%20but%20by%20this%20singular%20passion%20from%20other%20animals%2c%20which%20is%20a%20lust%20of%20the%20mind%2c%20that%20by%20a%20perseverance%20of%20delight%20in%20the%20continued%20and%20indefatigable%20generation%20of%20knowledge%2c%20exceeds%20the%20short%20vehemence%20of%20any%20carnal%20pleasure.";
	    set req.http.urlhobbesuc = "Man%20is%20distinguished%2C%20not%20only%20by%20his%20reason%2C%20but%20by%20this%20singular%20passion%20from%20other%20animals%2C%20which%20is%20a%20lust%20of%20the%20mind%2C%20that%20by%20a%20perseverance%20of%20delight%20in%20the%20continued%20and%20indefatigable%20generation%20of%20knowledge%2C%20exceeds%20the%20short%20vehemence%20of%20any%20carnal%20pleasure.";
	    set req.http.urlallupuc = "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%7F%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF";
	    set req.http.urlalluplc = "%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f%20%21%22%23%24%25%26%27%28%29%2a%2b%2c-.%2f0123456789%3a%3b%3c%3d%3e%3f%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5b%5c%5d%5e_%60abcdefghijklmnopqrstuvwxyz%7b%7c%7d~%7f%80%81%82%83%84%85%86%87%88%89%8a%8b%8c%8d%8e%8f%90%91%92%93%94%95%96%97%98%99%9a%9b%9c%9d%9e%9f%a0%a1%a2%a3%a4%a5%a6%a7%a8%a9%aa%ab%ac%ad%ae%af%b0%b1%b2%b3%b4%b5%b6%b7%b8%b9%ba%bb%bc%bd%be%bf%c0%c1%c2%c3%c4%c5%c6%c7%c8%c9%ca%cb%cc%cd%ce%cf%d0%d1%d2%d3%d4%d5%d6%d7%d8%d9%da%db%dc%dd%de%df%e0%e1%e2%e3%e4%e5%e6%e7%e8%e9%ea%eb%ec%ed%ee%ef%f0%f1%f2%f3%f4%f5%f6%f7%f8%f9%fa%fb%fc%fd%fe%ff";
	    set req.http.urlalldownuc = "%FF%FE%FD%FC%FB%FA%F9%F8%F7%F6%F5%F4%F3%F2%F1%F0%EF%EE%ED%EC%EB%EA%E9%E8%E7%E6%E5%E4%E3%E2%E1%E0%DF%DE%DD%DC%DB%DA%D9%D8%D7%D6%D5%D4%D3%D2%D1%D0%CF%CE%CD%CC%CB%CA%C9%C8%C7%C6%C5%C4%C3%C2%C1%C0%BF%BE%BD%BC%BB%BA%B9%B8%B7%B6%B5%B4%B3%B2%B1%B0%AF%AE%AD%AC%AB%AA%A9%A8%A7%A6%A5%A4%A3%A2%A1%A0%9F%9E%9D%9C%9B%9A%99%98%97%96%95%94%93%92%91%90%8F%8E%8D%8C%8B%8A%89%88%87%86%85%84%83%82%81%80%7F~%7D%7C%7Bzyxwvutsrqponmlkjihgfedcba%60_%5E%5D%5C%5BZYXWVUTSRQPONMLKJIHGFEDCBA%40%3F%3E%3D%3C%3B%3A9876543210%2F.-%2C%2B%2A%29%28%27%26%25%24%23%22%21%20%1F%1E%1D%1C%1B%1A%19%18%17%16%15%14%13%12%11%10%0F%0E%0D%0C%0B%0A%09%08%07%06%05%04%03%02%01%00";
	    set req.http.urlalldownlc = "%ff%fe%fd%fc%fb%fa%f9%f8%f7%f6%f5%f4%f3%f2%f1%f0%ef%ee%ed%ec%eb%ea%e9%e8%e7%e6%e5%e4%e3%e2%e1%e0%df%de%dd%dc%db%da%d9%d8%d7%d6%d5%d4%d3%d2%d1%d0%cf%ce%cd%cc%cb%ca%c9%c8%c7%c6%c5%c4%c3%c2%c1%c0%bf%be%bd%bc%bb%ba%b9%b8%b7%b6%b5%b4%b3%b2%b1%b0%af%ae%ad%ac%ab%aa%a9%a8%a7%a6%a5%a4%a3%a2%a1%a0%9f%9e%9d%9c%9b%9a%99%98%97%96%95%94%93%92%91%90%8f%8e%8d%8c%8b%8a%89%88%87%86%85%84%83%82%81%80%7f~%7d%7c%7bzyxwvutsrqponmlkjihgfedcba%60_%5e%5d%5c%5bZYXWVUTSRQPONMLKJIHGFEDCBA%40%3f%3e%3d%3c%3b%3a9876543210%2f.-%2c%2b%2a%29%28%27%26%25%24%23%22%21%20%1f%1e%1d%1c%1b%1a%19%18%17%16%15%14%13%12%11%10%0f%0e%0d%0c%0b%0a%09%08%07%06%05%04%03%02%01%00";

	  set resp.http.urluc2id
	    = blob.transcode(URL, IDENTITY, length=27,
			     encoded=req.http.urlhobbesuc);

	  set resp.http.urllc2id
	    = blob.transcode(URL, IDENTITY, length=63,
			     encoded=req.http.urlhobbeslc);

	  set resp.http.urlalldownuc2b64
	    = blob.transcode(URL, BASE64, length=18,
			     encoded=req.http.urlalldownuc);

	  set resp.http.urlalldownuc2b64url
	    = blob.transcode(URL, BASE64URL, length=15,
			     encoded=req.http.urlalldownuc);

	  set resp.http.urlalldownuc2b64nopad
	    = blob.transcode(URL, BASE64URLNOPAD, length=15,
			     encoded=req.http.urlalldownuc);

	  set resp.http.urlalldownlc2b64
	    = blob.transcode(URL, BASE64, length=18,
			     encoded=req.http.urlalldownlc);

	  set resp.http.urlalldownlc2b64url
	    = blob.transcode(URL, BASE64URL, length=15,
			     encoded=req.http.urlalldownlc);

	  set resp.http.urlalldownlc2b64nopad
	    = blob.transcode(URL, BASE64URLNOPAD, length=15,
			     encoded=req.http.urlalldownlc);

	  set resp.http.urlallupuc2b64
	    = blob.transcode(URL, BASE64, length=36,
			     encoded=req.http.urlallupuc);

	  set resp.http.urlallupuc2b64url
	    = blob.transcode(URL, BASE64URL, length=33,
			     encoded=req.http.urlallupuc);

	  set resp.http.urlallupuc2b64nopad
	    = blob.transcode(URL, BASE64URLNOPAD, length=33,
			     encoded=req.http.urlallupuc);

	  set resp.http.urlalluplc2b64
	    = blob.transcode(URL, BASE64, length=36,
			     encoded=req.http.urlalluplc);

	  set resp.http.urlalluplc2b64url
	    = blob.transcode(URL, BASE64URL, length=33,
			     encoded=req.http.urlalluplc);

	  set resp.http.urlalluplc2b64nopad
	    = blob.transcode(URL, BASE64URLNOPAD, length=33,
			     encoded=req.http.urlalluplc);

	  set resp.http.urlalldownuc2url
	    = blob.transcode(URL, URL, length=423,
			     encoded=req.http.urlalldownuc);

	  set resp.http.urlalldownuc2urluc
	    = blob.transcode(URL, URL, UPPER, 423, req.http.urlalldownuc);

	  set resp.http.urlalldownuc2urllc
	    = blob.transcode(URL, URL, LOWER, 423, req.http.urlalldownuc);

	  set resp.http.urlalldownlc2url
	    = blob.transcode(URL, URL, length=423,
			     encoded=req.http.urlalldownlc);

	  set resp.http.urlalldownlc2urluc
	    = blob.transcode(URL, URL, UPPER, 423, req.http.urlalldownlc);

	  set resp.http.urlalldownlc2urllc
	    = blob.transcode(URL, URL, LOWER, 423, req.http.urlalldownlc);

	  set resp.http.urlallupuc2url
	    = blob.transcode(URL, URL, length=197, encoded=req.http.urlallupuc);

	  set resp.http.urlallupuc2urluc
	    = blob.transcode(URL, URL, UPPER, 197, req.http.urlallupuc);

	  set resp.http.urlallupuc2urllc
	    = blob.transcode(URL, URL, LOWER, 197, req.http.urlallupuc);

	  set resp.http.urlalluplc2url
	    = blob.transcode(URL, URL, length=197, encoded=req.http.urlalluplc);

	  set resp.http.urlalluplc2urluc
	    = blob.transcode(URL, URL, UPPER, 197, req.http.urlalluplc);

	  set resp.http.urlalluplc2urllc
	    = blob.transcode(URL, URL, LOWER, 197, req.http.urlalluplc);

	  }
}

client c1 {
	txreq
	rxresp
	expect resp.http.urluc2id == "Man is distinguished,"
	expect resp.http.urllc2id == "Man is distinguished, not only by his reason,"
	expect resp.http.urlalldownuc2b64 == "//79/Pv6"
	expect resp.http.urlalldownuc2b64url == "__79_Ps="
	expect resp.http.urlalldownuc2b64nopad == "__79_Ps"
	expect resp.http.urlalldownlc2b64 == "//79/Pv6"
	expect resp.http.urlalldownlc2b64url == "__79_Ps="
	expect resp.http.urlalldownlc2b64nopad == "__79_Ps"
	expect resp.http.urlallupuc2b64 == "AAECAwQFBgcICQoL"
	expect resp.http.urlallupuc2b64url == "AAECAwQFBgcICQo="
	expect resp.http.urlallupuc2b64nopad == "AAECAwQFBgcICQo"
	expect resp.http.urlalluplc2b64 == "AAECAwQFBgcICQoL"
	expect resp.http.urlalluplc2b64url == "AAECAwQFBgcICQo="
	expect resp.http.urlalluplc2b64nopad == "AAECAwQFBgcICQo"
	expect resp.http.urlalldownuc2url == "%ff%fe%fd%fc%fb%fa%f9%f8%f7%f6%f5%f4%f3%f2%f1%f0%ef%ee%ed%ec%eb%ea%e9%e8%e7%e6%e5%e4%e3%e2%e1%e0%df%de%dd%dc%db%da%d9%d8%d7%d6%d5%d4%d3%d2%d1%d0%cf%ce%cd%cc%cb%ca%c9%c8%c7%c6%c5%c4%c3%c2%c1%c0%bf%be%bd%bc%bb%ba%b9%b8%b7%b6%b5%b4%b3%b2%b1%b0%af%ae%ad%ac%ab%aa%a9%a8%a7%a6%a5%a4%a3%a2%a1%a0%9f%9e%9d%9c%9b%9a%99%98%97%96%95%94%93%92%91%90%8f%8e%8d%8c%8b%8a%89%88%87%86%85%84%83%82%81%80%7f~%7d%7c%7bzyxwvutsrqponmlkjihgfedcba"
	expect resp.http.urlalldownuc2urluc == "%FF%FE%FD%FC%FB%FA%F9%F8%F7%F6%F5%F4%F3%F2%F1%F0%EF%EE%ED%EC%EB%EA%E9%E8%E7%E6%E5%E4%E3%E2%E1%E0%DF%DE%DD%DC%DB%DA%D9%D8%D7%D6%D5%D4%D3%D2%D1%D0%CF%CE%CD%CC%CB%CA%C9%C8%C7%C6%C5%C4%C3%C2%C1%C0%BF%BE%BD%BC%BB%BA%B9%B8%B7%B6%B5%B4%B3%B2%B1%B0%AF%AE%AD%AC%AB%AA%A9%A8%A7%A6%A5%A4%A3%A2%A1%A0%9F%9E%9D%9C%9B%9A%99%98%97%96%95%94%93%92%91%90%8F%8E%8D%8C%8B%8A%89%88%87%86%85%84%83%82%81%80%7F~%7D%7C%7Bzyxwvutsrqponmlkjihgfedcba"
	expect resp.http.urlalldownuc2urllc == resp.http.urlalldownuc2url
	expect resp.http.urlalldownlc2url == "%ff%fe%fd%fc%fb%fa%f9%f8%f7%f6%f5%f4%f3%f2%f1%f0%ef%ee%ed%ec%eb%ea%e9%e8%e7%e6%e5%e4%e3%e2%e1%e0%df%de%dd%dc%db%da%d9%d8%d7%d6%d5%d4%d3%d2%d1%d0%cf%ce%cd%cc%cb%ca%c9%c8%c7%c6%c5%c4%c3%c2%c1%c0%bf%be%bd%bc%bb%ba%b9%b8%b7%b6%b5%b4%b3%b2%b1%b0%af%ae%ad%ac%ab%aa%a9%a8%a7%a6%a5%a4%a3%a2%a1%a0%9f%9e%9d%9c%9b%9a%99%98%97%96%95%94%93%92%91%90%8f%8e%8d%8c%8b%8a%89%88%87%86%85%84%83%82%81%80%7f~%7d%7c%7bzyxwvutsrqponmlkjihgfedcba"
	expect resp.http.urlalldownlc2urluc == "%FF%FE%FD%FC%FB%FA%F9%F8%F7%F6%F5%F4%F3%F2%F1%F0%EF%EE%ED%EC%EB%EA%E9%E8%E7%E6%E5%E4%E3%E2%E1%E0%DF%DE%DD%DC%DB%DA%D9%D8%D7%D6%D5%D4%D3%D2%D1%D0%CF%CE%CD%CC%CB%CA%C9%C8%C7%C6%C5%C4%C3%C2%C1%C0%BF%BE%BD%BC%BB%BA%B9%B8%B7%B6%B5%B4%B3%B2%B1%B0%AF%AE%AD%AC%AB%AA%A9%A8%A7%A6%A5%A4%A3%A2%A1%A0%9F%9E%9D%9C%9B%9A%99%98%97%96%95%94%93%92%91%90%8F%8E%8D%8C%8B%8A%89%88%87%86%85%84%83%82%81%80%7F~%7D%7C%7Bzyxwvutsrqponmlkjihgfedcba"
	expect resp.http.urlalldownlc2urllc == resp.http.urlalldownlc2url
	expect resp.http.urlallupuc2url == "%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f%20%21%22%23%24%25%26%27%28%29%2a%2b%2c-.%2f0123456789%3a%3b%3c%3d%3e%3f%40ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	expect resp.http.urlalluplc2url == "%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f%20%21%22%23%24%25%26%27%28%29%2a%2b%2c-.%2f0123456789%3a%3b%3c%3d%3e%3f%40ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	expect resp.http.urlallupuc2urluc == "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	expect resp.http.urlalluplc2urluc == "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	expect resp.http.urlallupuc2urllc == resp.http.urlallupuc2url
	expect resp.http.urlalluplc2urllc == resp.http.urlalluplc2url
} -run

# Decode failures

server s1 -repeat 11 -keepalive {
	rxreq
	txresp
} -start

vinyl v1 -vcl+backend {
	import blob;

	sub vcl_deliver {
		set req.http.foo = "AAA=";
		if (req.url == "/1") {
			set resp.http.good
			    = blob.transcode(URL, IDENTITY, length=3,
					     encoded="%2c%q");
		}
		elsif (req.url == "/2") {
			set resp.http.good
			    = blob.transcode(URL, IDENTITY, length=3,
					     encoded="%3a%2q");
		}
		elsif (req.url == "/3") {
			set resp.http.bad
			    = blob.transcode(HEX, IDENTITY, length=8,
					     encoded="0x123456");
		}
		elsif (req.url == "/4") {
			set resp.http.bad
			    = blob.transcode(BASE64, IDENTITY, length=4,
					     encoded="-_-_" + req.http.foo);
		}
		elsif (req.url == "/5") {
			set resp.http.bad
			    = blob.transcode(BASE64URL, IDENTITY, length=4,
					     encoded="+/+/" + req.http.foo);
		}
		elsif (req.url == "/6") {
			set resp.http.bad
			    = blob.transcode(BASE64URLNOPAD, IDENTITY, length=8,
					     encoded="TWFu" + req.http.foo);
		}
		elsif (req.url == "/7") {
			set resp.http.bad
			    = blob.transcode(BASE64, BASE64, length=4,
					     encoded="_-_-" + req.http.foo);
		}
		elsif (req.url == "/8") {
			set resp.http.bad
			    = blob.transcode(BASE64URL, BASE64URL, length=4,
					     encoded="/+/+" + req.http.foo);
		}
		elsif (req.url == "/9") {
			set resp.http.bad
			    = blob.transcode(BASE64URLNOPAD,
					     BASE64URLNOPAD, length=8,
					     encoded="Zm9v" + req.http.foo);
		}
		elsif (req.url == "/10") {
			set resp.http.bad
			    = blob.transcode(URL, IDENTITY, length=1,
					     encoded="%20");
		}
		elsif (req.url == "/11") {
			set resp.http.bad
			    = blob.transcode(URL, IDENTITY, length=2,
					     encoded="%20");
		}
	}
}

client c1 {
	txreq -url /1
	rxresp
	expect resp.status == 200
	expect resp.http.good == ","
	txreq -url /2
	rxresp
	expect resp.status == 200
	expect resp.http.good == ":"
	txreq -url /3
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

client c1 {
	txreq -url /4
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

client c1 {
	txreq -url /5
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

client c1 {
	txreq -url /6
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

client c1 {
	txreq -url /7
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

client c1 {
	txreq -url /8
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

client c1 {
	txreq -url /9
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

client c1 {
	txreq -url /10
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

client c1 {
	txreq -url /11
	rxresp
	expect resp.status == 503
	expect resp.reason == "VCL failed"
	expect resp.http.bad == <undef>
} -run

logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "0x123456"$}
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "-_-_"$}
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "\+/\+/"$}
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "TWFu"$}
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "_-_-"$}
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "/\+/\+"$}
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "Zm9v"$}
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "%20"$}
	expect * * VCL_Error {^vmod blob error: cannot decode, illegal encoding beginning with "%20"$}
} -run
