How to use set_environment_headers method in localstack

Best Python code snippet using localstack_python

request.py

Source:request.py Github

copy

Full Screen

...62 environ["SERVER_PORT"] = "80"63 if remote_addr:64 environ["REMOTE_ADDR"] = remote_addr65 if headers:66 set_environment_headers(environ, headers)67 if not body or isinstance(body, (str, bytes)):68 data = strings.to_bytes(body) if body else b""69 wsgi_input = BytesIO(data)70 if "CONTENT_LENGTH" not in environ:71 # try to determine content length from body72 environ["CONTENT_LENGTH"] = str(len(data))73 else:74 wsgi_input = body75 # WSGI environ keys76 environ["wsgi.version"] = (1, 0)77 environ["wsgi.url_scheme"] = scheme78 environ["wsgi.input"] = wsgi_input79 environ["wsgi.input_terminated"] = True80 environ["wsgi.errors"] = BytesIO()81 environ["wsgi.multithread"] = True82 environ["wsgi.multiprocess"] = False83 environ["wsgi.run_once"] = False84 return environ85def set_environment_headers(environ: "WSGIEnvironment", headers: Union[Dict, Headers]):86 # Collect all the headers to set87 # (this might be is accessing the environment, this needs to be done before removing the items from the env)88 new_headers = {}89 for k, v in headers.items():90 name = k.upper().replace("-", "_")91 if name not in ("CONTENT_TYPE", "CONTENT_LENGTH"):92 name = f"HTTP_{name}"93 val = v94 if name in new_headers:95 val = new_headers[name] + "," + val96 new_headers[name] = val97 # Clear the HTTP headers in the env98 header_keys = [name for name in environ if name.startswith("HTTP_")]99 for name in header_keys:...

Full Screen

Full Screen

proxy.py

Source:proxy.py Github

copy

Full Screen

...89 :param headers: optional headers to overwrite90 :return: a new request with slightly modified underlying environment but the same data stream91 """92 # ensure that the headers in the env are set on the environment93 set_environment_headers(request.environ, request.headers)94 builder = EnvironBuilder.from_environ(request.environ)95 if base_url:96 builder.base_url = base_url97 builder.headers["Host"] = builder.host98 if path is not None:99 builder.path = path100 if headers:101 builder.headers.update(headers)102 # FIXME: unfortunately, EnvironBuilder expects the input stream to be seekable, but we don't have that when using103 # the asgi/wsgi bridge. we need a better way of dealing with IO!104 builder.input_stream = BytesIO(restore_payload(request))105 new_request = builder.get_request()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful