You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Summary
#### Added
- `url:decode` method
- `ada.decode` function
- `search:decode` method
- `search:decode_all` method
- `ada.search_encode` function
- `ada.search.encode` function
- `ada.search_decode` function
- `ada.search.decode` function
- `ada.search_decode_all` function
- `ada.search.decode_all` function
#### Changed
- The `set_port` to not allow negative or positive inf or NaN
#### Updated
- The CI is now executed against Ada 2.9.1
Signed-off-by: Aapo Talvensaari <aapo.talvensaari@gmail.com>
<p> This function will return the following table:</p>
681
+
682
+
<pre><code>{
683
+
origin = "https://example.com:1234",
684
+
scheme_type = 2,
685
+
protocol = "https:",
686
+
username = "user",
687
+
password = "pass",
688
+
host_type = 0,
689
+
host = "example.com:1234",
690
+
hostname = "example.com",
691
+
port = 1234,
692
+
pathname = "/foo/bar",
693
+
search = "?baz",
694
+
hash = "#quux",
695
+
}
696
+
</code></pre>
697
+
698
+
<p> The missing ones will be returned as empty string <code>""</code> (rather than <code>nil</code>).
699
+
700
+
701
+
702
+
<h3>Returns:</h3>
703
+
<ol>
704
+
<li>
705
+
<spanclass="types"><aclass="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <spanclass="type">nil</span></span>
706
+
table of URL components (except on errors <code>nil</code>)</li>
707
+
<li>
708
+
<spanclass="types"><spanclass="type">nil</span> or <aclass="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
709
+
error message</li>
710
+
</ol>
711
+
712
+
<h3>Raises:</h3>
713
+
error when url is not a string
714
+
715
+
716
+
<h3>Usage:</h3>
717
+
<ul>
718
+
<preclass="example"><spanclass="keyword">local</span> ada = <spanclass="global">require</span>(<spanclass="string">"resty.ada"</span>)
719
+
<spanclass="keyword">local</span> res = ada.<spanclass="function-name">decode</span>(<spanclass="string">"https://user:pass@host:1234/path?search#hash"</span>)</pre>
<preclass="example"><spanclass="keyword">local</span> ada = <spanclass="global">require</span>(<spanclass="string">"resty.ada"</span>)
2387
+
<spanclass="keyword">local</span> res = ada.<spanclass="function-name">search_parse</span>(<spanclass="string">"http://host/?a=b&c=d&e=f&a=g"</span>)</pre>
2388
+
</ul>
2389
+
2390
+
</dd>
2391
+
<dt>
2392
+
<aname = "search_encode"></a>
2393
+
<strong>search_encode (url)</strong>
2394
+
</dt>
2395
+
<dd>
2396
+
Encodes search parameters from URL and returns an query string.
<preclass="example"><spanclass="keyword">local</span> ada = <spanclass="global">require</span>(<spanclass="string">"resty.ada"</span>)
2421
+
<spanclass="keyword">local</span> res = ada.<spanclass="function-name">search_encode</span>(<spanclass="string">"http://host/?a=b&c=d&e=f&a=g"</span>)</pre>
2422
+
</ul>
2423
+
2424
+
</dd>
2425
+
<dt>
2426
+
<aname = "search_decode"></a>
2427
+
<strong>search_decode (url)</strong>
2428
+
</dt>
2429
+
<dd>
2430
+
Decodes search parameters from URL and returns a Lua table of them.</p>
2431
+
2432
+
<p> If same parameter appears multiple times, only the value of the
<spanclass="types"><aclass="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <spanclass="type">nil</span></span>
2458
+
a table of all search parameters (a string:string map).</li>
2459
+
<li>
2460
+
<spanclass="types"><spanclass="type">nil</span> or <aclass="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
2461
+
error message</li>
2462
+
</ol>
2463
+
2464
+
<h3>Raises:</h3>
2465
+
error when url is not a string
2466
+
2467
+
2468
+
<h3>Usage:</h3>
2469
+
<ul>
2470
+
<preclass="example"><spanclass="keyword">local</span> ada = <spanclass="global">require</span>(<spanclass="string">"resty.ada"</span>)
2471
+
<spanclass="keyword">local</span> res = ada.<spanclass="function-name">search_decode</span>(<spanclass="string">"http://host/?a=b&c=d&e=f&a=g"</span>)</pre>
2472
+
</ul>
2473
+
2474
+
</dd>
2475
+
<dt>
2476
+
<aname = "search_decode_all"></a>
2477
+
<strong>search_decode_all (url)</strong>
2478
+
</dt>
2479
+
<dd>
2480
+
Decodes all search parameters and returns a Lua table of them.</p>
<spanclass="types"><aclass="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <spanclass="type">nil</span></span>
2504
+
a table of all search parameters (a string:table [array] map).</li>
2505
+
<li>
2506
+
<spanclass="types"><spanclass="type">nil</span> or <aclass="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
2507
+
error message</li>
2508
+
</ol>
2509
+
2510
+
<h3>Raises:</h3>
2511
+
error when url is not a string
2512
+
2513
+
2514
+
<h3>Usage:</h3>
2515
+
<ul>
2516
+
<preclass="example"><spanclass="keyword">local</span> ada = <spanclass="global">require</span>(<spanclass="string">"resty.ada"</span>)
2517
+
<spanclass="keyword">local</span> res = ada.<spanclass="function-name">search_decode_all</span>(<spanclass="string">"http://host/?a=b&a=c&d=e"</span>)</pre>
2310
2518
</ul>
2311
2519
2312
2520
</dd>
@@ -2976,7 +3184,7 @@ <h3>Usage:</h3>
2976
3184
</div><!-- id="main" -->
2977
3185
<divid="about">
2978
3186
<i>generated by <ahref="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i>
<spanclass="keyword">local</span> result = search.<spanclass="function-name">append</span>(<spanclass="string">"a=b&c=d&e=f"</span>, <spanclass="string">"a"</span>, <spanclass="string">"g"</span>)</pre>
456
472
</ul>
457
473
474
+
</dd>
475
+
</dl>
476
+
<h2class="section-header "><aname="Encode_and_Decode_Functions"></a>Encode and Decode Functions </h2>
477
+
478
+
<dlclass="function">
479
+
<dt>
480
+
<aname = "encode"></a>
481
+
<strong>encode (params)</strong>
482
+
</dt>
483
+
<dd>
484
+
Encodes search parameters and returns an query string.</p>
485
+
486
+
<ul>
487
+
<li>only <ahref="https://www.lua.org/manual/5.1/manual.html#5.4">string</a> keys are allowed.</li>
488
+
<li>only <ahref="https://www.lua.org/manual/5.1/manual.html#5.4">string</a>, <code>boolean</code> and <code>number</code> values are allowed or an array of them</li>
489
+
<li><code>false</code> value is treated as missing (same as <code>nil</code>)</li>
<li>negative and positive <code>inf</code> and <code>NaN</code> are not allowed as numbers in values</li>
492
+
</ul>
493
+
494
+
495
+
<p> When passing a table the keys will be sorted and with string the given order
496
+
is preserved.
497
+
498
+
499
+
<h3>Parameters:</h3>
500
+
<ul>
501
+
<li><spanclass="parameter">params</span>
502
+
<spanclass="types"><aclass="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <aclass="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
503
+
search parameters to encode (either a <ahref="https://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <ahref="https://www.lua.org/manual/5.1/manual.html#5.4">string</a>)
<spanclass="keyword">local</span> result = search.<spanclass="function-name">decode</span>(<spanclass="string">"a=b&c=d&e=f&a=g"</span>)</pre>
573
+
</ul>
574
+
575
+
</dd>
576
+
<dt>
577
+
<aname = "decode_all"></a>
578
+
<strong>decode_all (search)</strong>
579
+
</dt>
580
+
<dd>
581
+
Decodes all search parameters and returns a Lua table of them.</p>
0 commit comments