-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathclient.ts
More file actions
63 lines (53 loc) · 1.55 KB
/
client.ts
File metadata and controls
63 lines (53 loc) · 1.55 KB
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
/**
* @description
* HTTP code snippet generator for the Shell using Wget.
*
* @author
* @AhmadNassri
*
* for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
*/
import { CodeBuilder } from '../../../helpers/code-builder';
import { escape, quote } from '../../../helpers/shell';
import { Client } from '../../targets';
export interface WgetOptions {
short?: boolean;
verbose?: boolean;
}
export const wget: Client<WgetOptions> = {
info: {
key: 'wget',
title: 'Wget',
link: 'https://www.gnu.org/software/wget/',
description: 'a free software package for retrieving files using HTTP, HTTPS',
},
convert: ({ method, postData, allHeaders, fullUrl }, options) => {
const opts = {
indent: ' ',
short: false,
verbose: false,
...options,
};
const { push, join } = new CodeBuilder({
indent: opts.indent,
// @ts-expect-error SEEMS LEGIT
join: opts.indent !== false ? ` \\\n${opts.indent}` : ' ',
});
if (opts.verbose) {
push(`wget ${opts.short ? '-v' : '--verbose'}`);
} else {
push(`wget ${opts.short ? '-q' : '--quiet'}`);
}
push(`--method ${quote(method)}`);
Object.keys(allHeaders).forEach(key => {
const header = `${key}: ${allHeaders[key]}`;
push(`--header ${quote(header)}`);
});
if (postData.text) {
push(`--body-data ${escape(quote(postData.text))}`);
}
push((opts.short ? '-O' : '--output-document') + ' -');
push(quote(fullUrl));
return join();
},
};