def test_303(): # Do a follow-up GET on a Location: header # returned from a POST that gave a 303. http = httplib2.Http() routes = { "/final": tests.make_http_reflect(), "": tests.make_http_reflect(status="303 See Other", headers={"location": "/final"}), } with tests.server_route(routes, request_count=2) as uri: response, content = http.request(uri, "POST", " ") assert response.status == 200 reflected = tests.HttpRequest.from_bytes(content) assert reflected.uri == "/final" assert response.previous.status == 303 # Skip follow-up GET http = httplib2.Http() http.follow_redirects = False with tests.server_route(routes, request_count=1) as uri: response, content = http.request(uri, "POST", " ") assert response.status == 303 # All methods can be used http = httplib2.Http() cases = "DELETE GET HEAD POST PUT EVEN_NEW_ONES".split(" ") with tests.server_route(routes, request_count=len(cases) * 2) as uri: for method in cases: response, content = http.request(uri, method, body=b"q q") assert response.status == 200 reflected = tests.HttpRequest.from_bytes(content) assert reflected.method == "GET"
def test_303(): # Do a follow-up GET on a Location: header # returned from a POST that gave a 303. http = httplib2.Http() routes = { '/final': tests.make_http_reflect(), '': tests.make_http_reflect(status='303 See Other', headers={'location': '/final'}), } with tests.server_route(routes, request_count=2) as uri: response, content = http.request(uri, 'POST', " ") assert response.status == 200 reflected = tests.HttpRequest.from_bytes(content) assert reflected.uri == '/final' assert response.previous.status == 303 # Skip follow-up GET http = httplib2.Http() http.follow_redirects = False with tests.server_route(routes, request_count=1) as uri: response, content = http.request(uri, 'POST', " ") assert response.status == 303 # All methods can be used http = httplib2.Http() cases = 'DELETE GET HEAD POST PUT EVEN_NEW_ONES'.split(' ') with tests.server_route(routes, request_count=len(cases) * 2) as uri: for method in cases: response, content = http.request(uri, method, body=b'q q') assert response.status == 200 reflected = tests.HttpRequest.from_bytes(content) assert reflected.method == 'GET'
def test_303(): # Do a follow-up GET on a Location: header # returned from a POST that gave a 303. http = httplib2.Http() routes = { '/final': tests.make_http_reflect(), '': tests.make_http_reflect(status='303 See Other', headers={'location': '/final'}), } with tests.server_route(routes, request_count=2) as uri: response, content = http.request(uri, 'POST', " ") assert response.status == 200 reflected = tests.HttpRequest.from_bytes(content) assert reflected.uri == '/final' assert response.previous.status == 303 # Skip follow-up GET http = httplib2.Http() http.follow_redirects = False with tests.server_route(routes, request_count=1) as uri: response, content = http.request(uri, 'POST', " ") assert response.status == 303 # All methods can be used http = httplib2.Http() cases = 'DELETE GET HEAD POST PUT EVEN_NEW_ONES'.split(' ') with tests.server_route(routes, request_count=len(cases) * 2) as uri: for method in cases: response, content = http.request(uri, method, body=b'q q') assert response.status == 200 reflected = tests.HttpRequest.from_bytes(content) assert reflected.method == 'GET'
def test_303(): # Do a follow-up GET on a Location: header # returned from a POST that gave a 303. http = httplib2.Http() routes = { "/final": tests.make_http_reflect(), "": tests.make_http_reflect( status="303 See Other", headers={"location": "/final"} ), } with tests.server_route(routes, request_count=2) as uri: response, content = http.request(uri, "POST", " ") assert response.status == 200 reflected = tests.HttpRequest.from_bytes(content) assert reflected.uri == "/final" assert response.previous.status == 303 # Skip follow-up GET http = httplib2.Http() http.follow_redirects = False with tests.server_route(routes, request_count=1) as uri: response, content = http.request(uri, "POST", " ") assert response.status == 303 # All methods can be used http = httplib2.Http() cases = "DELETE GET HEAD POST PUT EVEN_NEW_ONES".split(" ") with tests.server_route(routes, request_count=len(cases) * 2) as uri: for method in cases: response, content = http.request(uri, method, body=b"q q") assert response.status == 200 reflected = tests.HttpRequest.from_bytes(content) assert reflected.method == "GET"
def test_change_308(): # 308: follow with same method, cache redirect http = httplib2.Http(cache=tests.get_cache_path(), timeout=1) routes = { "/final": tests.make_http_reflect(), "": tests.http_response_bytes( status="308 Permanent Redirect", add_date=True, headers={ "cache-control": "max-age=300", "location": "/final" }, ), } with tests.server_route(routes, request_count=3) as uri: response, content = http.request(uri, "CHANGE", body=b"hello308") assert response.previous.status == 308 assert not response.previous.fromcache assert response.status == 200 assert not response.fromcache assert content.startswith(b"CHANGE /final HTTP") response, content = http.request(uri, "CHANGE") assert response.previous.status == 308 assert response.previous.fromcache assert response.status == 200 assert not response.fromcache assert content.startswith(b"CHANGE /final HTTP")