How to use the httpie.utils.get_content_type 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 / cli / requestitems.py View on Github external
def parse_file_item(self, item):
        fn = item.value
        try:
            with open(os.path.expanduser(fn), 'rb') as f:
                contents = f.read()
        except IOError as e:
            raise ParseError('"%s": %s' % (item.orig, e))
        return os.path.basename(fn), BytesIO(contents), get_content_type(fn)
github jakubroztocil / httpie / httpie / cli / argparser.py View on Github external
if self.args.files and not self.args.form:
            # `http url @/path/to/file`
            file_fields = list(self.args.files.keys())
            if file_fields != ['']:
                self.error(
                    'Invalid file fields (perhaps you meant --form?): %s'
                    % ','.join(file_fields))

            fn, fd, ct = self.args.files['']
            self.args.files = {}

            self._body_from_file(fd)

            if 'Content-Type' not in self.args.headers:
                content_type = get_content_type(fn)
                if content_type:
                    self.args.headers['Content-Type'] = content_type
github jakubroztocil / httpie / httpie / cli / requestitems.py View on Github external
def process_file_upload_arg(arg: KeyValueArg) -> Tuple[str, IO, str]:
    filename = arg.value
    try:
        with open(os.path.expanduser(filename), 'rb') as f:
            contents = f.read()
    except IOError as e:
        raise ParseError('"%s": %s' % (arg.orig, e))
    return (
        os.path.basename(filename),
        BytesIO(contents),
        get_content_type(filename),
    )
github jakubroztocil / httpie / httpie / cli / requestitems.py View on Github external
def parse_file_item_chunked(arg: KeyValueArg):
    fn = arg.value
    try:
        f = open(os.path.expanduser(fn), 'rb')
    except IOError as e:
        raise ParseError('"%s": %s' % (arg.orig, e))
    return os.path.basename(fn), f, get_content_type(fn)
github jakubroztocil / httpie / httpie / cli / requestitems.py View on Github external
def parse_file_item_chunked(self, item):
        fn = item.value
        try:
            f = open(os.path.expanduser(fn), 'rb')
        except IOError as e:
            raise ParseError('"%s": %s' % (item.orig, e))
        return os.path.basename(fn), f, get_content_type(fn)
github jakubroztocil / httpie / httpie / cli / argparser.py View on Github external
if self.args.files and not self.args.form:
            # `http url @/path/to/file`
            file_fields = list(self.args.files.keys())
            if file_fields != ['']:
                self.error(
                    'Invalid file fields (perhaps you meant --form?): %s'
                    % ','.join(file_fields))

            fn, fd, ct = self.args.files['']
            self.args.files = {}

            self._body_from_file(fd)

            if 'Content-Type' not in self.args.headers:
                content_type = get_content_type(fn)
                if content_type:
                    self.args.headers['Content-Type'] = content_type