-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
84 lines (72 loc) · 2.1 KB
/
app.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import { render} from 'react-dom';
const Converter = React.createClass({
getInitialState() {
return {
iterations: 10,
concurrency: 1,
curl: '',
abstring: '',
url: null,
cookie: null
}
},
updateIterations(evt) {
this.setState({
iterations: evt.target.value
}, this.updateOutput);
},
updateConcurrency(evt) {
this.setState({
concurrency: evt.target.value
}, this.updateOutput);
},
updateCurlString(evt) {
this.setState({
curl: evt.target.value
}, this.updateOutput);
},
updateOutput() {
const {
iterations, concurrency, curl
} = this.state;
if (curl && curl.indexOf('curl') === 0) {
const curlComponents = curl.split(' ');
const url = curlComponents[1];
const baseString = `ab -n ${iterations} -c ${concurrency}`;
let cookie = '';
if (curl.indexOf('Cookie') >= 0 || curl.indexOf('cookie') >= 0) {
const cookieString = (curl.match(/-H 'Cookie: (.*?)(?:'|$)/) || curl.match(/-H 'cookie: (.*?)(?:'|$)/));
if (cookieString) {
cookie = `-C '${cookieString[1]}'`;
}
}
const finalString = `${baseString} ${cookie} ${url}`;
this.setState({
abstring: finalString
});
}
},
render() {
const {
iterations, concurrency, url, curl, cookie, abstring
} = this.state;
return <div id='Converter'>
<div className='params'>
<label>AB Iterations</label>
<input name='iterations' type='number' placeholder='Iterations' value={iterations} onChange={this.updateIterations}/>
<label>AB Concurrency</label>
<input type='number' placeholder='Concurrency' value={concurrency} onChange={this.updateConcurrency}/>
</div>
<div className='inputs'>
<div className='paste-area'>
<textarea onChange={this.updateCurlString} value={curl} />
</div>
<div className='result-area'>
<textarea value={abstring} />
</div>
</div>
</div>
}
});
render(<Converter />, document.getElementById('react'));