mirror of
https://github.com/httpie/cli.git
synced 2024-11-08 00:44:45 +01:00
parent
92a4352f10
commit
b125ce5eae
@ -21,6 +21,10 @@ from httpie.sessions import VALID_SESSION_NAME_PATTERN
|
|||||||
from httpie.utils import load_json_preserve_order
|
from httpie.utils import load_json_preserve_order
|
||||||
|
|
||||||
|
|
||||||
|
# ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
|
||||||
|
# <http://tools.ietf.org/html/rfc3986#section-3.1>
|
||||||
|
URL_SCHEME_RE = re.compile(r'^[a-z][a-z0-9.+-]*://', re.IGNORECASE)
|
||||||
|
|
||||||
HTTP_POST = 'POST'
|
HTTP_POST = 'POST'
|
||||||
HTTP_GET = 'GET'
|
HTTP_GET = 'GET'
|
||||||
HTTP = 'http://'
|
HTTP = 'http://'
|
||||||
@ -132,7 +136,7 @@ class Parser(ArgumentParser):
|
|||||||
self._parse_items()
|
self._parse_items()
|
||||||
if not self.args.ignore_stdin and not env.stdin_isatty:
|
if not self.args.ignore_stdin and not env.stdin_isatty:
|
||||||
self._body_from_file(self.env.stdin)
|
self._body_from_file(self.env.stdin)
|
||||||
if not (self.args.url.startswith((HTTP, HTTPS))):
|
if not URL_SCHEME_RE.match(self.args.url):
|
||||||
scheme = HTTP
|
scheme = HTTP
|
||||||
|
|
||||||
# See if we're using curl style shorthand for localhost (:3000/foo)
|
# See if we're using curl style shorthand for localhost (:3000/foo)
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
import json
|
import json
|
||||||
# noinspection PyCompatibility
|
# noinspection PyCompatibility
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from requests.exceptions import InvalidSchema
|
||||||
|
|
||||||
from httpie import input
|
from httpie import input
|
||||||
from httpie.input import KeyValue, KeyValueArgType, DataDict
|
from httpie.input import KeyValue, KeyValueArgType, DataDict
|
||||||
@ -321,3 +321,12 @@ class TestIgnoreStdin:
|
|||||||
error_exit_ok=True)
|
error_exit_ok=True)
|
||||||
assert r.exit_status == ExitStatus.ERROR
|
assert r.exit_status == ExitStatus.ERROR
|
||||||
assert 'because --ignore-stdin' in r.stderr
|
assert 'because --ignore-stdin' in r.stderr
|
||||||
|
|
||||||
|
|
||||||
|
class TestSchemes:
|
||||||
|
|
||||||
|
def test_custom_scheme(self):
|
||||||
|
# InvalidSchema is expected because HTTPie
|
||||||
|
# shouldn't touch a formally valid scheme.
|
||||||
|
with pytest.raises(InvalidSchema):
|
||||||
|
http('foo+bar-BAZ.123://bah')
|
||||||
|
Loading…
Reference in New Issue
Block a user