hyper icon indicating copy to clipboard operation
hyper copied to clipboard

Retain connection in HTTP/2 using hyper to avoid authentication for every request

Open vikramojha89 opened this issue 5 years ago • 0 comments

Hello

I have written, below script to test my code for HTTP/2. But with my current script., I need to send authorization with every request, i.e my connection get closed after every request. Is there any way, we can retain connetion with hyper.

Below is my code:

from hyper import HTTP20Connection

import hyper
import ssl
import time

header = {'Accept': 'application/xhtml+xml;v=2.0', 'Authorization': 'Basic RGVmYXVsdCBVc2VyOnJvYm90aWNz' }

Accept_header = {'Accept': 'application/xhtml+xml;v=2.0'}

context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.options |= ssl.OP_NO_SSLv2
context.options |= ssl.OP_NO_SSLv3

with HTTP20Connection('localhost:443', force_proto='h2', ssl_context=context) as conn:
    conn.request('GET', '/', headers=header)

    resp = conn.get_response()
    
    print(resp.satus)
    
    conn.request('GET', '/ctrl')

    resp = conn.get_response()
    
    print(resp.status)
    print("Sleeping...")
    time.sleep(10)

vikramojha89 avatar Oct 06 '20 04:10 vikramojha89