Skip to content

Commit

Permalink
Allow custom URL schemes
Browse files Browse the repository at this point in the history
Closes #299

See also #276
  • Loading branch information
jkbrzt committed Feb 5, 2015
1 parent 92a4352 commit b125ce5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion httpie/input.py
Expand Up @@ -21,6 +21,10 @@
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_GET = 'GET'
HTTP = 'http://'
Expand Down Expand Up @@ -132,7 +136,7 @@ def parse_args(self, env, args=None, namespace=None):
self._parse_items()
if not self.args.ignore_stdin and not env.stdin_isatty:
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

# See if we're using curl style shorthand for localhost (:3000/foo)
Expand Down
11 changes: 10 additions & 1 deletion tests/test_cli.py
Expand Up @@ -2,9 +2,9 @@
import json
# noinspection PyCompatibility
import argparse
import os

import pytest
from requests.exceptions import InvalidSchema

from httpie import input
from httpie.input import KeyValue, KeyValueArgType, DataDict
Expand Down Expand Up @@ -321,3 +321,12 @@ def test_ignore_stdin_cannot_prompt_password(self, httpbin):
error_exit_ok=True)
assert r.exit_status == ExitStatus.ERROR
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')

0 comments on commit b125ce5

Please sign in to comment.