-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathhttp.sh
171 lines (163 loc) · 3.33 KB
/
http.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
_patch_help() {
$@ --help | \
sed \
-e 's/^ / /' \
-e 's/^ \(--\w\+\) \(\S\+\), \(-\w\) \(\S\+\)/ \3, \1 \2/' \
-e 's/^ \(--\w\+\), \(-\w\)/ \2, \1/' \
-e 's/{\(\S\+\(,\S\+\)\+\)},\?/\1/' \
-e '/\S\+\(,\S\+\)\{2,\}/ s/,/|/g'
}
_patch_table() {
_patch_table_edit_options \
'--cert(<CERT_FILE>)' \
'--cert-key(<CERT_KEY_FILE>)' \
'--ciphers;[`_choice_cipher`]' \
'--default-scheme;[http://|http://]' \
'--format-options;[`_choice_format_options`]' \
'--print;[`_choice_print_options`]' \
'--style;[`_choice_style`]' \
'--verify;[yes|no]' \
| \
_patch_table_edit_arguments ';;' 'args;*[`_choice_args`]'
}
_choice_style() {
cat <<-'EOF'
abap
algol
algol_nu
arduino
auto
autumn
borland
bw
colorful
default
dracula
emacs
friendly
friendly_grayscale
fruity
github-dark
gruvbox-dark
gruvbox-light
igor
inkpot
lilypond
lovelace
manni
material
monokai
murphy
native
nord
nord-darker
one-dark
paraiso-dark
paraiso-light
pastie
perldoc
pie
pie-dark
pie-light
rainbow_dash
rrt
sas
solarized
solarized-dark
solarized-light
staroffice
stata
stata-dark
stata-light
tango
trac
vim
vs
xcode
zenburn
EOF
}
_choice_format_options() {
cat <<-'EOF' | _argc_util_comp_kv =
headers.sort=true,false
json.format=true,false
json.indent=
json.sort_keys=true,false
EOF
}
_choice_print_options() {
cat <<-'EOF'
H request headers
B request body
h response headers
b response body
EOF
}
_choice_cipher() {
cat <<-'EOF'
TLS_AES_256_GCM_SHA384
TLS_CHACHA20_POLY1305_SHA256
TLS_AES_128_GCM_SHA256
ECDHE-ECDSA-AES256-GCM-SHA384
ECDHE-RSA-AES256-GCM-SHA384
ECDHE-ECDSA-AES128-GCM-SHA256
ECDHE-RSA-AES128-GCM-SHA256
ECDHE-ECDSA-CHACHA20-POLY1305
ECDHE-RSA-CHACHA20-POLY1305
ECDHE-ECDSA-AES256-SHA384
ECDHE-RSA-AES256-SHA384
ECDHE-ECDSA-AES128-SHA256
ECDHE-RSA-AES128-SHA256
DHE-RSA-AES256-GCM-SHA384
DHE-RSA-AES128-GCM-SHA256
DHE-RSA-AES256-SHA256
DHE-RSA-AES128-SHA256
EOF
}
_choice_args() {
len="${#argc__positionals[@]}"
if [[ $len -eq 1 ]]; then
_module_http_method
elif [[ $len -eq 2 ]]; then
if _module_http_method | grep -q "${argc__positionals[0]}"; then
return
else
_choice_request_item
fi
else
_choice_request_item
fi
}
_choice_request_item() {
local IFS=$'\n'
local sep sep_used
for sep in $(_choice_seperator); do
sep="${sep%% *}"
if [[ "$ARGC_CWORD" == *"$sep"* ]]; then
sep_used="$sep"
break
fi
done
if [[ -z "$sep_used" ]]; then
_choice_seperator | sed 's/^\(.*\)$/'$ARGC_CWORD'\1/'
_module_http_header
else
if [[ "$sep_used" == "=@" ]] || [[ "$sep_used" == ":=@" ]]; then
_argc_util_mode_kv $sep_used
_argc_util_comp_path filter=$argc__kv_filter
elif [[ "$sep_used" == ":" ]]; then
_module_http_header
fi
fi
}
_choice_seperator() {
cat <<-'EOF'
:=@ A raw JSON field like ':=', but takes a file path and embeds its content
== URL parameters to be appended to the request URI
:= Non-string JSON data fields (only with --json, -j)
=@ A data field like '=', but takes a file path and embeds its content
@ Form file fields (only with --form or --multipart)
: HTTP headers
= Data fields to be serialized into a JSON object
EOF
}