-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: env /tags endpoint and env based HTTP headers #565
base: master
Are you sure you want to change the base?
Conversation
use _setenv as a context manager (with _setenv ... :) instead of a decorator (@_setenv ...) Since python3.2+ contextlib.contextmanager uses ContextDecorator allowing the decorated function _setenv to be used as a decorator in addition to context manager. contextlib in python2.7 doesn't have ContextDecorator, therefore _setenv must be used as a context manager not a decorator.
good pr, hope merged |
I just found this and would love to see it merged, as I'm playing around with multiple httpbin instances, and having a way to uniquely identify each one would be super helpful. |
@dmuth You could try https://github.com/chinaran/go-httpbin, a golang port of httpbin. |
That worked for me, thanks for sharing it! |
Description
This feature adds a
/tags
endpoint and inserts HTTP headers, both based on environment variables. The new endpoint returns environment variables (and their values) starting withHTTPBIN_
.XHTTPBIN_
environment variables are added as HTTP response headers.HTTPBIN_
as well asXHTTPBIN_
will be stripped from the name, additionally all underscores_
in theXHTTPBIN_
variable name will be converted to a dash-
for better shell variable name and HTTP header support.Motivation
The motivation is that load balancing/horizontal scaling tests usually require unique identification of the instance handling the request. This feature allows to uniquely tag these instances (containers or even multiple httpbin instances on the same server OS). The optional HTTP header provides this identifier across the whole httpbin feature set, not only for the
/tags
endpoint.Examples
Assuming the following environment variables are set:
XHTTPBIN_X_TagHeader="Header Value"
HTTPBIN_Tag=Value
HTTPBIN_AnotherTag="long value..."
If no
HTTPBIN_
environment variables exist, the response for/tags
will look like this: