Update doc
This commit is contained in:
parent
3432a0bed9
commit
358b3b0ebc
|
@ -1069,30 +1069,28 @@ BaseRequestHandler usage:</p>
|
|||
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python</span>
|
||||
|
||||
<span class="kn">import</span> <span class="nn">io</span><span class="o">,</span> <span class="nn">ssl</span>
|
||||
<span class="kn">from</span> <span class="nn">pprint</span> <span class="kn">import</span> <span class="n">pprint</span>
|
||||
<span class="kn">import</span> <span class="nn">nghttp2</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Handler</span><span class="p">(</span><span class="n">nghttp2</span><span class="o">.</span><span class="n">BaseRequestHandler</span><span class="p">):</span>
|
||||
|
||||
<span class="k">def</span> <span class="nf">on_headers</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="s">'/css/bootstrap.css'</span><span class="p">,</span>
|
||||
<span class="n">request_headers</span> <span class="o">=</span> <span class="p">[(</span><span class="n">b</span><span class="s">'content-length'</span><span class="p">,</span> <span class="n">b</span><span class="s">'3'</span><span class="p">)],</span>
|
||||
<span class="n">request_headers</span> <span class="o">=</span> <span class="p">[(</span><span class="s">'content-length'</span><span class="p">,</span> <span class="s">'3'</span><span class="p">)],</span>
|
||||
<span class="n">status</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span>
|
||||
<span class="n">body</span><span class="o">=</span><span class="s">'foo'</span><span class="p">)</span>
|
||||
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">push</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="s">'/js/bootstrap.js'</span><span class="p">,</span>
|
||||
<span class="n">method</span><span class="o">=</span><span class="s">'GET'</span><span class="p">,</span>
|
||||
<span class="n">request_headers</span> <span class="o">=</span> <span class="p">[(</span><span class="n">b</span><span class="s">'content-length'</span><span class="p">,</span> <span class="n">b</span><span class="s">'10'</span><span class="p">)],</span>
|
||||
<span class="n">request_headers</span> <span class="o">=</span> <span class="p">[(</span><span class="s">'content-length'</span><span class="p">,</span> <span class="s">'10'</span><span class="p">)],</span>
|
||||
<span class="n">status</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span>
|
||||
<span class="n">body</span><span class="o">=</span><span class="s">'foobarbuzz'</span><span class="p">)</span>
|
||||
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">send_response</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span>
|
||||
<span class="n">headers</span> <span class="o">=</span> <span class="p">[(</span><span class="n">b</span><span class="s">'content-type'</span><span class="p">,</span> <span class="n">b</span><span class="s">'text/plain'</span><span class="p">)],</span>
|
||||
<span class="n">headers</span> <span class="o">=</span> <span class="p">[(</span><span class="s">'content-type'</span><span class="p">,</span> <span class="s">'text/plain'</span><span class="p">)],</span>
|
||||
<span class="n">body</span><span class="o">=</span><span class="n">io</span><span class="o">.</span><span class="n">BytesIO</span><span class="p">(</span><span class="n">b</span><span class="s">'nghttp2-python FTW'</span><span class="p">))</span>
|
||||
|
||||
<span class="n">ctx</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">SSLContext</span><span class="p">(</span><span class="n">ssl</span><span class="o">.</span><span class="n">PROTOCOL_SSLv23</span><span class="p">)</span>
|
||||
<span class="n">ctx</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">OP_ALL</span> <span class="o">|</span> <span class="n">ssl</span><span class="o">.</span><span class="n">OP_NO_SSLv2</span>
|
||||
<span class="n">ctx</span><span class="o">.</span><span class="n">set_npn_protocols</span><span class="p">([</span><span class="s">'h2-10'</span><span class="p">])</span>
|
||||
<span class="n">ctx</span><span class="o">.</span><span class="n">load_cert_chain</span><span class="p">(</span><span class="s">'server.crt'</span><span class="p">,</span> <span class="s">'server.key'</span><span class="p">)</span>
|
||||
|
||||
<span class="c"># give None to ssl to make the server non-SSL/TLS</span>
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue