How to use the httpie.cli.dicts.RequestHeadersDict function in httpie

To help you get started, we’ve selected a few httpie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jakubroztocil / httpie / httpie / client.py View on Github external
def finalize_headers(headers: RequestHeadersDict) -> RequestHeadersDict:
    final_headers = RequestHeadersDict()
    for name, value in headers.items():
        if value is not None:
            # “leading or trailing LWS MAY be removed without
            # changing the semantics of the field value”
            # 
            # Also, requests raises `InvalidHeader` for leading spaces.
            value = value.strip()
            if isinstance(value, str):
                # See 
                value = value.encode('utf8')
        final_headers[name] = value
    return final_headers
github jakubroztocil / httpie / httpie / cli / requestitems.py View on Github external
def __init__(self, as_form=False, chunked=False):
        self.headers = RequestHeadersDict()
        self.data = RequestDataDict() if as_form else RequestJSONDataDict()
        self.files = RequestFilesDict()
        self.params = RequestQueryParamsDict()
        self.chunked = chunked
github jakubroztocil / httpie / httpie / client.py View on Github external
def make_default_headers(args: argparse.Namespace) -> RequestHeadersDict:
    default_headers = RequestHeadersDict({
        'User-Agent': DEFAULT_UA
    })

    auto_json = args.data and not args.form
    if args.json or auto_json:
        default_headers['Accept'] = JSON_ACCEPT
        if args.json or (auto_json and args.data):
            default_headers['Content-Type'] = JSON_CONTENT_TYPE

    elif args.form and not args.files:
        # If sending files, `requests` will set
        # the `Content-Type` for us.
        default_headers['Content-Type'] = FORM_CONTENT_TYPE
    return default_headers
github jakubroztocil / httpie / httpie / sessions.py View on Github external
def headers(self) -> RequestHeadersDict:
        return RequestHeadersDict(self['headers'])
github jakubroztocil / httpie / httpie / cli / requestitems.py View on Github external
def __init__(self, as_form=False, chunked=False):
        self.headers = RequestHeadersDict()
        self.data = RequestDataDict() if as_form else RequestJSONDataDict()
        self.files = RequestFilesDict()
        self.params = RequestQueryParamsDict()
        self.chunked = chunked