Skip to content

Commit

Permalink
Strip leading :// from URLs to allow quick conversion of a pasted U…
Browse files Browse the repository at this point in the history
…RL to calls

Closes #1195
  • Loading branch information
jkbrzt committed Nov 5, 2021
1 parent 434512e commit 19471cd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## [2.7.0.dev0](https://github.com/httpie/httpie/compare/2.6.0...master) (unreleased)

- Added support for sending multiple HTTP headers with the same name. ([#130](https://github.com/httpie/httpie/issues/130))
- Added support for keeping `://` in the URL argument to allow quick conversions of pasted URLs into HTTPie calls just by adding a space after the protocol name (`$ https ://pie.dev/get``GET https://pie.dev/get`) . ([#1195](https://github.com/httpie/httpie/issues/1195))

## [2.6.0](https://github.com/httpie/httpie/compare/2.5.0...2.6.0) (2021-10-14)

Expand Down
15 changes: 13 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,14 +482,25 @@ The default scheme is `http://` and can be omitted from the argument:
```bash
$ http example.org
# => http://example.org
# http://example.org
```
HTTPie also installs an `https` executable, where the default scheme is `https://`:
```bash
$ https example.org
# => https://example.org
# → https://example.org
```
When you paste a URL into the terminal, you can even keep the `://` bit in the URL argument to quickly convert the URL into an HTTPie call just by adding a space after the protocol name.
```bash
# Paste https://example.org, add a space, submit:
$ https ://example.org
```
```bash
# Paste http://example.org, add a space, submit:
$ http ://example.org
```
### Querystring parameters
Expand Down
3 changes: 3 additions & 0 deletions httpie/cli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def _process_request_type(self):
}

def _process_url(self):
if self.args.url.startswith('://'):
# Paste URL & add space shortcut: `http ://pie.dev` → `GET https://pie.dev/get`
self.args.url = self.args.url[3:]
if not URL_SCHEME_RE.match(self.args.url):
if os.path.basename(self.env.program_name) == 'https':
scheme = 'https://'
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ def test_query_string_params_in_url_and_items_with_duplicates(self,
assert f'"url": "{url}"' in r


@pytest.mark.parametrize(['program_name', 'url_arg', 'parsed_url'], [
('http', '://pie.dev/get', 'http://pie.dev/get'),
('https', '://pie.dev/get', 'https://pie.dev/get'),
])
def test_colon_slash_slash(program_name, url_arg, parsed_url):
env = MockEnvironment(program_name=program_name)
args = parser.parse_args(args=[url_arg], env=env)
assert args.url == parsed_url


class TestLocalhostShorthand:
def test_expand_localhost_shorthand(self):
args = parser.parse_args(args=[':'], env=MockEnvironment())
Expand Down

0 comments on commit 19471cd

Please sign in to comment.