Skip to content

Commit 754a8e0

Browse files
committed
add http method option to configuration
1 parent 59c48ff commit 754a8e0

8 files changed

Lines changed: 283 additions & 24 deletions

File tree

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/xenOs76/https-wrench/refs/heads/main/https-wrench.schema.json
2+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
3+
---
4+
debug: false
5+
verbose: true
6+
requests:
7+
- name: httpBunGetDefault
8+
9+
requestHeaders:
10+
- key: x-custom-header
11+
value: custom-header-value
12+
13+
# printResponseHeaders: true
14+
# printResponseBody: true
15+
16+
hosts:
17+
- name: httpbun.com
18+
uriList:
19+
- /get?method=DefaultGet
20+
21+
- name: httpBunGetDeclared
22+
requestMethod: GET
23+
24+
requestHeaders:
25+
- key: x-custom-header
26+
value: custom-header-value
27+
28+
# printResponseHeaders: true
29+
# printResponseBody: true
30+
31+
hosts:
32+
- name: httpbun.com
33+
uriList:
34+
- /get?clientMethod=GET
35+
36+
- name: httpBunPost
37+
requestMethod: POST
38+
39+
requestHeaders:
40+
- key: x-custom-header
41+
value: custom-header-value
42+
43+
# printResponseHeaders: true
44+
# printResponseBody: true
45+
46+
hosts:
47+
- name: httpbun.com
48+
uriList:
49+
- /post
50+
51+
- name: httpBunPostBodyText
52+
requestMethod: POST
53+
54+
requestHeaders:
55+
- key: content-type
56+
value: text/plain
57+
58+
requestBody: "plain requestBody \non a multiline string\n"
59+
# printResponseHeaders: true
60+
# printResponseBody: true
61+
62+
hosts:
63+
- name: httpbun.com
64+
uriList:
65+
- /post
66+
67+
- name: httpBunPostBodyJson
68+
requestMethod: POST
69+
70+
requestHeaders:
71+
- key: content-type
72+
value: application/json
73+
74+
requestBody: '{"a": 1, "b": 2, "c": 3}'
75+
# printResponseHeaders: true
76+
# printResponseBody: true
77+
78+
hosts:
79+
- name: httpbun.com
80+
uriList:
81+
- /post
82+
83+
- name: httpBunPut
84+
requestMethod: PUT
85+
86+
# printResponseHeaders: true
87+
# printResponseBody: true
88+
89+
hosts:
90+
- name: httpbun.com
91+
uriList:
92+
- /put
93+
94+
- name: httpBunDelete
95+
requestMethod: DELETE
96+
97+
# printResponseHeaders: true
98+
# printResponseBody: true
99+
100+
hosts:
101+
- name: httpbun.com
102+
uriList:
103+
- /delete
104+
105+
- name: httpBunPatch
106+
requestMethod: PATCH
107+
108+
# printResponseHeaders: true
109+
# printResponseBody: true
110+
111+
hosts:
112+
- name: httpbun.com
113+
uriList:
114+
- /patch
115+
116+
- name: reqBinOptions
117+
requestMethod: OPTIONS
118+
119+
# printResponseHeaders: true
120+
# printResponseBody: true
121+
requestHeaders:
122+
- key: Access-Control-Request-Method
123+
value: PUT
124+
- key: Origin
125+
value: https://reqbin.com
126+
- key: Access-Control-Request-Headers
127+
value: content-type
128+
129+
hosts:
130+
- name: api.reqbin.com
131+
uriList:
132+
- /api/v1/requests
133+
134+
- name: httpBunTraceNotAllowed
135+
requestMethod: TRACE
136+
137+
# printResponseHeaders: true
138+
# printResponseBody: true
139+
140+
hosts:
141+
- name: httpbun.com
142+
uriList:
143+
- /get
144+
145+
- name: httpBunTrace
146+
requestMethod: TRACE
147+
148+
# printResponseHeaders: true
149+
# printResponseBody: true
150+
151+
hosts:
152+
- name: httpbun.com
153+
uriList:
154+
- /any
155+
156+
- name: httpBunHead
157+
requestMethod: HEAD
158+
159+
# requestDebug: true
160+
# printResponseHeaders: true
161+
162+
hosts:
163+
- name: httpbun.com
164+

examples/https-wrench-request-timeout.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/xenOs76/https-wrench/refs/heads/main/https-wrench.schema.json
22
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
33
---
4-
debug: false
54
verbose: true
65
requests:
76
- name: Os76RequestDrop

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

https-wrench.schema.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
}
2121
},
2222
"required": [
23-
"debug",
2423
"requests",
2524
"verbose"
2625
],
@@ -44,6 +43,12 @@
4443
"clientTimeout": {
4544
"type": "number"
4645
},
46+
"requestDebug": {
47+
"type": "boolean"
48+
},
49+
"responseDebug": {
50+
"type": "boolean"
51+
},
4752
"printResponseBody": {
4853
"type": "boolean"
4954
},
@@ -57,19 +62,26 @@
5762
"pattern": "^[A-Z]"
5863
}
5964
},
60-
"hosts": {
65+
"requestBody": {
66+
"type": "string"
67+
},
68+
"requestMethod": {
69+
"type": "string",
70+
"pattern": "^(POST|GET|HEAD|PUT|DELETE|PATCH|HEAD|OPTIONS|TRACE)$"
71+
},
72+
"requestHeaders": {
6173
"type": "array",
6274
"items": {
63-
"$ref": "#/definitions/Host"
75+
"$ref": "#/definitions/RequestHeader"
6476
}
6577
},
6678
"userAgent": {
6779
"type": "string"
6880
},
69-
"requestHeaders": {
81+
"hosts": {
7082
"type": "array",
7183
"items": {
72-
"$ref": "#/definitions/RequestHeader"
84+
"$ref": "#/definitions/Host"
7385
}
7486
}
7587
},

src/cmd/config.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7-
"log"
87
"net/http"
98
"regexp"
109
"time"
@@ -27,14 +26,18 @@ type RequestHeader struct {
2726

2827
type RequestConfig struct {
2928
Name string `mapstructure:"name"`
29+
ClientTimeout time.Duration `mapstructure:"clientTimeout"`
3030
UserAgent string `mapstructure:"userAgent"`
31-
PrintResponseBody bool `mapstructure:"printResponseBody"`
32-
PrintResponseHeaders bool `mapstructure:"printResponseHeaders"`
3331
TransportOverrideUrl string `mapstructure:"transportOverrideUrl"`
32+
RequestDebug bool `mapstructure:"requestDebug"`
3433
RequestHeaders []RequestHeader `mapstructure:"requestHeaders"`
34+
RequestMethod string `mapstructure:"requestMethod"`
35+
RequestBody string `mapstructure:"requestBody"`
36+
ResponseDebug bool `mapstructure:"responseDebug"`
3537
ResponseHeadersFilter []string `mapstructure:"responseHeadersFilter"`
38+
PrintResponseBody bool `mapstructure:"printResponseBody"`
39+
PrintResponseHeaders bool `mapstructure:"printResponseHeaders"`
3640
Hosts []Host `mapstructure:"hosts"`
37-
ClientTimeout time.Duration `mapstructure:"clientTimeout"`
3841
}
3942

4043
type ResponseData struct {
@@ -62,7 +65,7 @@ func (h ResponseHeader) String() string {
6265
func (u Uri) Parse() bool {
6366
matched, err := regexp.Match(`^\/.*`, []byte(u))
6467
if err != nil {
65-
log.Fatalf("Unable to parse Uri %s", u)
68+
return false
6669
}
6770
return matched
6871
}

src/cmd/embedded/config-example.yaml

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44
debug: false
55
verbose: true
66
requests:
7-
- name: httpBunCom
7+
- name: httpBunComGet
8+
89
transportOverrideUrl: https://cat.httpbun.com:443
910
clientTimeout: 3
10-
userAgent: wrench-httpbun-ua
11+
12+
requestDebug: false
13+
responseDebug: false
14+
15+
printResponseBody: true
16+
printResponseHeaders: true
17+
18+
userAgent: wrench-custom-ua
1119

1220
requestHeaders:
1321
- key: x-custom-header
1422
value: custom-header-value
1523
- key: x-api-key
1624
value: api-value
1725

18-
printResponseBody: true
19-
printResponseHeaders: true
2026
responseHeadersFilter:
2127
- X-Powered-By
2228
- Via
@@ -29,3 +35,43 @@ requests:
2935
- /status/302
3036
- /status/404
3137
- /status/503
38+
39+
- name: httpBinGoPost
40+
41+
userAgent: wrench-request-post
42+
43+
printResponseBody: true
44+
printResponseHeaders: true
45+
46+
requestHeaders:
47+
- key: Content-Type
48+
value: text/plain
49+
50+
requestMethod: POST
51+
requestBody: request body via post
52+
53+
responseHeadersFilter:
54+
- Content-Type
55+
56+
hosts:
57+
- name: httpbingo.org
58+
uriList:
59+
- /post
60+
61+
- name: httpBinGoHead
62+
63+
# requestDebug: true
64+
# responseDebug: true
65+
66+
printResponseHeaders: true
67+
68+
requestHeaders:
69+
- key: Content-Type
70+
value: text/plain
71+
72+
requestMethod: HEAD
73+
74+
hosts:
75+
- name: httpbingo.org
76+
uriList:
77+
- /head

0 commit comments

Comments
 (0)