Skip to content

Commit 417a414

Browse files
authored
Merge pull request ywangd#402 from onyxware/dev
Add new option to CURL
2 parents 0ccd3b2 + 5134add commit 417a414

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

bin/curl.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
import argparse
77
import requests
88

9-
try:
10-
from urllib.parse import urlparse
11-
except ImportError:
12-
from urlparse import urlparse
9+
from six.moves.urllib.parse import urlparse
1310

1411
try:
1512
import clipboard
1613
except ImportError:
17-
pass
14+
clipboard = None
1815

1916

2017
def main(args):
@@ -27,6 +24,12 @@ def main(args):
2724
action='store_true',
2825
help='write output to a local file named like the remote file we get'
2926
)
27+
ap.add_argument(
28+
'-L',
29+
'--location',
30+
action='store_true',
31+
help='follow redirects to other web pages (if the URL has a 3XX response code)'
32+
)
3033
ap.add_argument(
3134
'-X',
3235
'--request-method',
@@ -49,11 +52,24 @@ def main(args):
4952
headers[name.strip()] = value.strip()
5053

5154
if ns.request_method == 'GET':
52-
r = requests.get(url, headers=headers)
55+
r = requests.get(
56+
url,
57+
headers=headers,
58+
allow_redirects=ns.location
59+
)
5360
elif ns.request_method == 'POST':
54-
r = requests.post(url, data=ns.data, headers=headers)
61+
r = requests.post(
62+
url,
63+
data=ns.data,
64+
headers=headers,
65+
allow_redirects=ns.location
66+
)
5567
elif ns.request_method == 'HEAD':
56-
r = requests.head(url, headers=headers)
68+
r = requests.head(
69+
url,
70+
headers=headers,
71+
allow_redirects=ns.location
72+
)
5773
else:
5874
print('unknown request method: {}'.format(ns.request_method))
5975
return

0 commit comments

Comments
 (0)