forked from coquec/harToCurl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
harToCurl
executable file
·35 lines (27 loc) · 1004 Bytes
/
harToCurl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
import sys
import json
import urllib
f = open(sys.argv[1])
data = json.load(f)
for entry in data['log']['entries']:
request = entry['request']
opts = {}
opts['url'] = request['url']
opts['cookies'] = urllib.urlencode([(cookie['name'], cookie['value'])
for cookie in request['cookies']])
httpVersions = {
'HTTP/1.0': '--http1.0',
'HTTP/1.1': '--http1.1',
'HTTP/2.0': '--http2',
}
opts['httpVersion'] = httpVersions.get(request['httpVersion'].upper(), '')
opts['method'] = request['method']
opts['headers'] = ' '.join(['-H \'' + x['name'] + ': ' + x['value'] + '\''
for x in request['headers']])
if 'postData' in request:
opts['postData'] = request['postData']['text']
else:
opts['postData'] = ''
print('curl -X {method} {httpVersion} -b \'{cookies}\' {headers} '
'-d \'{postData}\' {url}'.format(**opts))