-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
har-to-curl.html
65 lines (57 loc) · 1.86 KB
/
har-to-curl.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<!-- saved from url=(0036)http://mattcg.github.io/har-to-curl/ -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Convert HAR (HTTP Archive) to cURL command</title>
<script type="application/javascript" src="./har-to-curl.js"></script>
<script type="application/javascript">
window.onload = function() {
var $ = function(id) {
return document.getElementById(id);
};
$('hartext').onchange = function() {
var out, result, harText = $('hartext').value;
if (!harText) {
return;
}
out = $('curltext');
try {
result = harToCurl(harText);
} catch (e) {
out.value = 'Error parsing HAR: ' + e.message + '.';
if (e.stack) {
out.value += '\n\n' + e.stack;
}
return;
}
if (Array.isArray(result)) {
result.forEach(function(command, i) {
if (!command) {
command = 'Unable to parse at index ' + i + '.';
}
if (i > 0) {
out.value += '\n\n' + command;
} else {
out.value = command;
}
});
} else {
out.value = result;
}
};
};
</script>
<style type="text/css">
body { margin: 0; font-family: Helvetica, Arial, sans-serif; }
form { position: absolute; width: 100%; height: 100%; padding: 2em; box-sizing: border-box; }
textarea { width: 40%; height: 80%; display: inline-block; border: 1px dashed black; }
#hartext { margin-right: 2em; }
</style>
</head>
<body>
<form>
<textarea id="hartext" name="har"></textarea>
<textarea id="curltext" name="curl"></textarea>
<p>HAR goes on the left and cURL comes out on the right.</p>
<p><a href="https://github.com/mattcg/har-to-curl">har-to-curl.js</a> is hosted on GitHub. By <a href="https://twitter.com/mcaruanagalizia">@mcaruanagalizia</a>.</p>
</form>
</body></html>