add CURLINFO_RETRY_AFTER
[m6w6/ext-http] / tests / negotiate001.phpt
1 --TEST--
2 negotiate
3 --SKIPIF--
4 <?php include "skipif.inc"; ?>
5 --ENV--
6 HTTP_ACCEPT=text/html,text/plain,text/xml;q=0.1,image/*;q=0.1,*/*;q=0
7 HTTP_ACCEPT_CHARSET=utf-8,iso-8859-1;q=0.8,iso-8859-15;q=0
8 HTTP_ACCEPT_ENCODING=gzip,deflate;q=0
9 HTTP_ACCEPT_LANGUAGE=de-DE,de-AT;q=0.9,en;q=0.8,fr;q=0
10 --FILE--
11 CONTENT TYPE
12
13 <?php
14
15 function dump($ctr) {
16 print_r(array_map(function($v){return round($v,2);}, $ctr));
17 }
18
19 $ct = http\Env::negotiateContentType(array("text/html","text/xml","text/json"), $ctr);
20 echo "$ct: "; dump($ctr);
21 $ct = http\Env::negotiateContentType(array("text/xml","text/json"), $ctr);
22 echo "$ct: "; dump($ctr);
23 $ct = http\Env::negotiateContentType(array("text/json"), $ctr);
24 echo "$ct: "; dump($ctr);
25 ?>
26
27 CHARSET
28
29 <?php
30 $cs = http\Env::negotiateCharset(array("utf-8", "iso-8859-1", "iso-8859-15"), $csr);
31 echo "$cs: "; dump($csr);
32 $cs = http\Env::negotiateCharset(array("iso-8859-1", "iso-8859-15"), $csr);
33 echo "$cs: "; dump($csr);
34 $cs = http\Env::negotiateCharset(array("utf-16", "iso-8859-15", "iso-8859-2"), $csr);
35 echo "$cs: "; dump($csr);
36 ?>
37
38 ENCODING
39
40 <?php
41 $ce = http\Env::negotiateEncoding(array("gzip", "deflate", "sdch"), $cer);
42 echo "$ce: "; dump($cer);
43 $ce = http\Env::negotiateEncoding(array("", "sdch"), $cer);
44 echo "$ce: "; dump($cer);
45 ?>
46
47 LANGUAGE
48
49 <?php
50 $ln = http\Env::negotiateLanguage(array("de", "en", "fr"), $lnr);
51 echo "$ln: "; dump($lnr);
52 $ln = http\Env::negotiateLanguage(array("de-DE", "de-AT", "en"), $lnr);
53 echo "$ln: "; dump($lnr);
54 $ln = http\Env::negotiateLanguage(array("nl", "fr", "en"), $lnr);
55 echo "$ln: "; dump($lnr);
56 ?>
57
58 CUSTOM
59
60 <?php
61 $cc = http\Env::negotiate("a, a.b;q=0.9, c.d;q=0, *.* ; q=0.1",
62 array("a.x", "c.d", "c.e", "a.b"), ".", $ccr);
63 echo "$cc: "; dump($ccr);
64 ?>
65 DONE
66 --EXPECT--
67 CONTENT TYPE
68
69 text/html: Array
70 (
71 [text/html] => 0.99
72 [text/xml] => 0.1
73 )
74 text/xml: Array
75 (
76 [text/xml] => 0.1
77 )
78 text/json: Array
79 (
80 )
81
82 CHARSET
83
84 utf-8: Array
85 (
86 [utf-8] => 0.99
87 [iso-8859-1] => 0.8
88 )
89 iso-8859-1: Array
90 (
91 [iso-8859-1] => 0.8
92 )
93 utf-16: Array
94 (
95 )
96
97 ENCODING
98
99 gzip: Array
100 (
101 [gzip] => 0.99
102 )
103 : Array
104 (
105 )
106
107 LANGUAGE
108
109 de: Array
110 (
111 [de] => 0.97
112 [en] => 0.8
113 )
114 de-DE: Array
115 (
116 [de-DE] => 0.99
117 [de-AT] => 0.9
118 [en] => 0.8
119 )
120 en: Array
121 (
122 [en] => 0.8
123 )
124
125 CUSTOM
126
127 a.b: Array
128 (
129 [a.b] => 0.9
130 [a.x] => 0.08
131 [c.e] => 0.08
132 )
133 DONE