mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-12-18 08:02:12 +03:00
23 lines
2.9 KiB
HTML
23 lines
2.9 KiB
HTML
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"></span><span class="comment"># In this test, the data returned by the server is encoded using GB2312.</span>
|
|
<span class="line"></span>
|
|
<span class="line"></span><span class="comment"># The 'Content-Type' HTTP response header precise the charset 'gb2312'</span>
|
|
<span class="line"></span><span class="comment"># so any text based assert are using GB2312 and can be used.</span>
|
|
<span class="line"></span><span class="comment"># See the sibling fail test where there is no charset => tests_failed/hello_gb2312_failed.hurl</span>
|
|
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/hello_gb2312</span></span>
|
|
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
|
<span class="line"><span class="section-header">[Asserts]</span></span>
|
|
<span class="line"><span class="query-type">header</span> <span class="string">"Content-Type"</span> <span class="predicate-type">==</span> <span class="string">"text/html; charset=gb2312"</span></span>
|
|
<span class="line"><span class="query-type">bytes</span> <span class="predicate-type">contains</span> hex,<span class="hex">c4e3bac3cac0bde7</span>;</span> <span class="comment"># 你好世界 encoded in GB2312</span>
|
|
<span class="line"><span class="query-type">xpath</span> <span class="string">"string(//body)"</span> <span class="predicate-type">==</span> <span class="string">"你好世界"</span></span>
|
|
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
|
|
<span class="line"></span>
|
|
<span class="line"></span><span class="comment"># The 'Content-Type' HTTP response header does not precise the charset 'gb2312'</span>
|
|
<span class="line"></span><span class="comment"># so body must be decoded explicitly by Hurl before processing any text based assert</span>
|
|
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/hello_gb2312_implicit</span></span>
|
|
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
|
|
<span class="line"><span class="section-header">[Asserts]</span></span>
|
|
<span class="line"><span class="query-type">header</span> <span class="string">"Content-Type"</span> <span class="predicate-type">==</span> <span class="string">"text/html"</span></span>
|
|
<span class="line"><span class="query-type">bytes</span> <span class="predicate-type">contains</span> hex,<span class="hex">c4e3bac3cac0bde7</span>;</span> <span class="comment"># 你好世界 encoded in GB2312</span>
|
|
<span class="line"><span class="query-type">bytes</span> <span class="filter-type">decode</span> <span class="string">"gb2312"</span> <span class="filter-type">xpath</span> <span class="string">"string(//body)"</span> <span class="predicate-type">==</span> <span class="string">"你好世界"</span></span>
|
|
</span></span></code></pre>
|