Skip to content

Commit 497179b

Browse files
committed
Add basic support for non-POST HTTP Method.
1 parent c18bf8f commit 497179b

File tree

79 files changed

+334
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+334
-244
lines changed

Diff for: src/flags.go

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func displayOut(outText OutTextType) string {
3434
return DisplayType[string(outText)]
3535
}
3636

37+
var explicitlySupportedMethods = map[string]bool{
38+
"GET": true,
39+
"POST": true,
40+
}
41+
3742
var tmpInTextType string
3843
var tmpOutTextType string
3944
var tmpDataTextInferredType InTextType
@@ -55,6 +60,9 @@ func intialiseFlags() {
5560
flags.BoolVarP(&CurrentConfig.InferProtoFiles, "infer-files", "F", false,
5661
"Infer the correct files containing the relevant protobuf messages. All proto files in the proto directory provided by -I will be used. If no -f <file> is provided, this -F is set and the files are inferred.")
5762

63+
flags.StringVarP(&CurrentConfig.Method, "method", "X", "POST",
64+
"HTTP request method. POST (default) and GET supported. Other methods are passed on on to curl optimistically.")
65+
5866
flags.StringVarP(&CurrentConfig.RequestType, "request-type", "i", "",
5967
"Mandatory: Message name or full package path of the Protobuf request type. The path can be shortened to '..', if the name of the request message is unique. E.g. mypackage.MyRequest or ..MyRequest")
6068
AssertSuccess(rootCmd.MarkFlagRequired("request-type"))
@@ -143,6 +151,10 @@ func propagateFlags() {
143151
}
144152
}
145153

154+
if !explicitlySupportedMethods[CurrentConfig.Method] && CurrentConfig.Verbose {
155+
fmt.Printf("Got method %s which is not explicitly supported. Proceeding optimistically.", CurrentConfig.Method)
156+
}
157+
146158
if strings.HasPrefix(strings.TrimSpace(CurrentConfig.DataText), "{") {
147159
tmpDataTextInferredType = IJson
148160
} else {

Diff for: src/httpRequest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func invokeCurlRequest(requestBinary []byte, curlPath string) ([]byte, string) {
6767
curlArgs := []string{
6868
curlPath,
6969
"-s",
70-
"-X", "POST",
70+
"-X", CurrentConfig.Method,
7171
"--data-binary", "@" + requestBinaryFile,
7272
"--output", responseBinaryFile,
7373
"--dump-header", responseHeadersTextFile,

Diff for: src/protocurl.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Config struct {
1818
RequestType string
1919
ResponseType string
2020
Url string
21+
Method string
2122
DataText string
2223
InTextType InTextType
2324
OutTextType OutTextType
@@ -107,13 +108,13 @@ func encodeToBinary(requestType string, text string, registry *protoregistry.Fil
107108
)
108109

109110
if !CurrentConfig.ShowOutputOnly {
110-
fmt.Printf("%s Request %s %s %s\n%s\n",
111-
VISUAL_SEPARATOR, displayIn(CurrentConfig.InTextType), VISUAL_SEPARATOR,
111+
fmt.Printf("%s %s Request %s %s %s\n%s\n",
112+
VISUAL_SEPARATOR, CurrentConfig.Method, displayIn(CurrentConfig.InTextType), VISUAL_SEPARATOR,
112113
SEND, reconstructedRequestText)
113114
}
114115

115116
if !CurrentConfig.ShowOutputOnly && CurrentConfig.DisplayBinaryAndHttp {
116-
fmt.Printf("%s Request Binary %s %s\n%s", VISUAL_SEPARATOR, VISUAL_SEPARATOR, SEND, hex.Dump(requestBinary))
117+
fmt.Printf("%s %s Request Binary %s %s\n%s", VISUAL_SEPARATOR, CurrentConfig.Method, VISUAL_SEPARATOR, SEND, hex.Dump(requestBinary))
117118
}
118119

119120
return requestBinary
@@ -145,18 +146,18 @@ func invokeHttpRequestBasedOnConfig(requestBinary []byte) ([]byte, string) {
145146

146147
func decodeResponse(responseBinary []byte, responseHeaders string, registry *protoregistry.Files) {
147148
if !CurrentConfig.ShowOutputOnly && CurrentConfig.DisplayBinaryAndHttp {
148-
fmt.Printf("%s Response Headers %s %s\n%s\n", VISUAL_SEPARATOR, VISUAL_SEPARATOR, RECV, responseHeaders)
149+
fmt.Printf("%s %s Response Headers %s %s\n%s\n", VISUAL_SEPARATOR, CurrentConfig.Method, VISUAL_SEPARATOR, RECV, responseHeaders)
149150

150-
fmt.Printf("%s Response Binary %s %s\n%s", VISUAL_SEPARATOR, VISUAL_SEPARATOR, RECV, hex.Dump(responseBinary))
151+
fmt.Printf("%s %s Response Binary %s %s\n%s", VISUAL_SEPARATOR, CurrentConfig.Method, VISUAL_SEPARATOR, RECV, hex.Dump(responseBinary))
151152
}
152153

153154
responseMessageType := properResponseTypeIfProvidedOrEmptyType()
154155

155156
responseText, _ := protoBinaryToMsgAndText(responseMessageType, responseBinary, CurrentConfig.OutTextType, registry)
156157

157158
if !CurrentConfig.ShowOutputOnly {
158-
fmt.Printf("%s Response %s %s %s\n",
159-
VISUAL_SEPARATOR, displayOut(CurrentConfig.OutTextType), VISUAL_SEPARATOR, RECV)
159+
fmt.Printf("%s %s Response %s %s %s\n",
160+
VISUAL_SEPARATOR, CurrentConfig.Method, displayOut(CurrentConfig.OutTextType), VISUAL_SEPARATOR, RECV)
160161
}
161162
fmt.Printf("%s\n", responseText)
162163
}

Diff for: test/results/additional-curl-args-expected.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
date: {
44
seconds: 1642044939
55
nanos: 152000000
66
}
77
includeReason: true
8-
=========================== Request Binary =========================== >>>
8+
=========================== POST Request Binary =========================== >>>
99
00000000 0a 0b 08 8b bc fe 8e 06 10 80 ac bd 48 10 01 |............H..|
10-
=========================== Response Headers =========================== <<<
10+
=========================== POST Response Headers =========================== <<<
1111
HTTP/1.1 200 OK
1212
Content-Type: application/x-protobuf
13-
Date: Fri, 17 Mar 2023 11:27:07 GMT
13+
Date: Fri, 29 Sep 2023 23:20:05 GMT
1414
Connection: keep-alive
1515
Keep-Alive: timeout=5
1616
Content-Length: 65
17-
=========================== Response Binary =========================== <<<
17+
=========================== POST Response Binary =========================== <<<
1818
00000000 08 01 12 1c 54 68 75 72 73 64 61 79 20 69 73 20 |....Thursday is |
1919
00000010 61 20 48 61 70 70 79 20 44 61 79 21 20 e2 ad 90 |a Happy Day! ...|
2020
00000020 1a 1d 54 68 75 2c 20 31 33 20 4a 61 6e 20 32 30 |..Thu, 13 Jan 20|
2121
00000030 32 32 20 30 33 3a 33 35 3a 33 39 20 47 4d 54 22 |22 03:35:39 GMT"|
2222
00000040 00 |.|
23-
=========================== Response Text =========================== <<<
23+
=========================== POST Response Text =========================== <<<
2424
isHappyDay: true
2525
reason: "Thursday is a Happy Day! ⭐"
2626
formattedDate: "Thu, 13 Jan 2022 03:35:39 GMT"

Diff for: test/results/additional-curl-args-verbose-expected.txt

+8-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Invoked with following default & parsed arguments:
1010
"RequestType": "..HappyDayRequest",
1111
"ResponseType": "..HappyDayResponse",
1212
"Url": "http://localhost:8080/happy-day/verify",
13+
"Method": "POST",
1314
"DataText": "includeReason: true, date: { seconds: 1642044939, nanos: 152000000 }",
1415
"InTextType": "text",
1516
"OutTextType": "text",
@@ -234,13 +235,13 @@ Searching for message with base name: HappyDayRequest
234235
Resolved message package-paths for name HappyDayRequest: [happyday.HappyDayRequest]
235236
Searching for message with base name: HappyDayRequest
236237
Resolved message package-paths for name HappyDayRequest: [happyday.HappyDayRequest]
237-
=========================== Request Text =========================== >>>
238+
=========================== POST Request Text =========================== >>>
238239
date: {
239240
seconds: 1642044939
240241
nanos: 152000000
241242
}
242243
includeReason: true
243-
=========================== Request Binary =========================== >>>
244+
=========================== POST Request Binary =========================== >>>
244245
00000000 0a 0b 08 8b bc fe 8e 06 10 80 ac bd 48 10 01 |............H..|
245246
Expecting to find curl executable due to forced use of curl.
246247
Found curl: /usr/bin/curl
@@ -278,30 +279,30 @@ Total curl args:
278279
* Mark bundle as not supporting multiuse
279280
< HTTP/1.1 200 OK
280281
< Content-Type: application/x-protobuf
281-
< Date: Tue, 20 Jun 2023 20:38:59 GMT
282+
< Date: Fri, 29 Sep 2023 23:20:05 GMT
282283
< Connection: keep-alive
283284
< Keep-Alive: timeout=5
284285
< Content-Length: 65
285286
<
286287
{ [65 bytes data]
287288
* Connection #0 to host localhost left intact
288289

289-
=========================== Response Headers =========================== <<<
290+
=========================== POST Response Headers =========================== <<<
290291
HTTP/1.1 200 OK
291292
Content-Type: application/x-protobuf
292-
Date: Tue, 20 Jun 2023 20:38:59 GMT
293+
Date: Fri, 29 Sep 2023 23:20:05 GMT
293294
Connection: keep-alive
294295
Keep-Alive: timeout=5
295296
Content-Length: 65
296-
=========================== Response Binary =========================== <<<
297+
=========================== POST Response Binary =========================== <<<
297298
00000000 08 01 12 1c 54 68 75 72 73 64 61 79 20 69 73 20 |....Thursday is |
298299
00000010 61 20 48 61 70 70 79 20 44 61 79 21 20 e2 ad 90 |a Happy Day! ...|
299300
00000020 1a 1d 54 68 75 2c 20 31 33 20 4a 61 6e 20 32 30 |..Thu, 13 Jan 20|
300301
00000030 32 32 20 30 33 3a 33 35 3a 33 39 20 47 4d 54 22 |22 03:35:39 GMT"|
301302
00000040 00 |.|
302303
Searching for message with base name: HappyDayResponse
303304
Resolved message package-paths for name HappyDayResponse: [happyday.HappyDayResponse]
304-
=========================== Response Text =========================== <<<
305+
=========================== POST Response Text =========================== <<<
305306
isHappyDay: true
306307
reason: "Thursday is a Happy Day! ⭐"
307308
formattedDate: "Thu, 13 Jan 2022 03:35:39 GMT"

Diff for: test/results/display-binary-and-headers-expected.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
date: {
44
seconds: 1642044939
55
nanos: 152000000
66
}
77
includeReason: true
8-
=========================== Request Binary =========================== >>>
8+
=========================== POST Request Binary =========================== >>>
99
00000000 0a 0b 08 8b bc fe 8e 06 10 80 ac bd 48 10 01 |............H..|
10-
=========================== Response Headers =========================== <<<
10+
=========================== POST Response Headers =========================== <<<
1111
HTTP/1.1 200 OK
1212
Content-Type: application/x-protobuf
13-
Date: Fri, 17 Mar 2023 11:27:06 GMT
13+
Date: Fri, 29 Sep 2023 23:20:04 GMT
1414
Connection: keep-alive
1515
Keep-Alive: timeout=5
1616
Content-Length: 65
17-
=========================== Response Binary =========================== <<<
17+
=========================== POST Response Binary =========================== <<<
1818
00000000 08 01 12 1c 54 68 75 72 73 64 61 79 20 69 73 20 |....Thursday is |
1919
00000010 61 20 48 61 70 70 79 20 44 61 79 21 20 e2 ad 90 |a Happy Day! ...|
2020
00000020 1a 1d 54 68 75 2c 20 31 33 20 4a 61 6e 20 32 30 |..Thu, 13 Jan 20|
2121
00000030 32 32 20 30 33 3a 33 35 3a 33 39 20 47 4d 54 22 |22 03:35:39 GMT"|
2222
00000040 00 |.|
23-
=========================== Response Text =========================== <<<
23+
=========================== POST Response Text =========================== <<<
2424
isHappyDay: true
2525
reason: "Thursday is a Happy Day! ⭐"
2626
formattedDate: "Thu, 13 Jan 2022 03:35:39 GMT"

Diff for: test/results/display-binary-and-headers-no-curl-expected.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
date: {
44
seconds: 1642044939
55
nanos: 152000000
66
}
77
includeReason: true
8-
=========================== Request Binary =========================== >>>
8+
=========================== POST Request Binary =========================== >>>
99
00000000 0a 0b 08 8b bc fe 8e 06 10 80 ac bd 48 10 01 |............H..|
10-
=========================== Response Headers =========================== <<<
10+
=========================== POST Response Headers =========================== <<<
1111
HTTP/1.1 200 OK
1212
Content-Length: 65
1313
Connection: keep-alive
1414
Content-Type: application/x-protobuf
15-
Date: Fri, 17 Mar 2023 11:27:07 GMT
15+
Date: Fri, 29 Sep 2023 23:20:04 GMT
1616
Keep-Alive: timeout=5
17-
=========================== Response Binary =========================== <<<
17+
=========================== POST Response Binary =========================== <<<
1818
00000000 08 01 12 1c 54 68 75 72 73 64 61 79 20 69 73 20 |....Thursday is |
1919
00000010 61 20 48 61 70 70 79 20 44 61 79 21 20 e2 ad 90 |a Happy Day! ...|
2020
00000020 1a 1d 54 68 75 2c 20 31 33 20 4a 61 6e 20 32 30 |..Thu, 13 Jan 20|
2121
00000030 32 32 20 30 33 3a 33 35 3a 33 39 20 47 4d 54 22 |22 03:35:39 GMT"|
2222
00000040 00 |.|
23-
=========================== Response Text =========================== <<<
23+
=========================== POST Response Text =========================== <<<
2424
isHappyDay: true
2525
reason: "Thursday is a Happy Day! ⭐"
2626
formattedDate: "Thu, 13 Jan 2022 03:35:39 GMT"

Diff for: test/results/echo-empty-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33

4-
=========================== Response Text =========================== <<<
4+
=========================== POST Response Text =========================== <<<
55

66
######### STDERR #########
77
######### EXIT 0 #########

Diff for: test/results/echo-empty-no-curl-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33

4-
=========================== Response Text =========================== <<<
4+
=========================== POST Response Text =========================== <<<
55

66
######### STDERR #########
77
######### EXIT 0 #########

Diff for: test/results/echo-empty-with-curl-args-expected.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
includeReason: true
44
=========================== CURL ERROR ===========================
55
* Trying 127.0.0.1:8080...
@@ -16,15 +16,15 @@ includeReason: true
1616
* Mark bundle as not supporting multiuse
1717
< HTTP/1.1 200 OK
1818
< Content-Type: application/x-protobuf
19-
< Date: Tue, 20 Jun 2023 20:39:05 GMT
19+
< Date: Fri, 29 Sep 2023 23:20:13 GMT
2020
< Connection: keep-alive
2121
< Keep-Alive: timeout=5
2222
< Content-Length: 2
2323
<
2424
{ [2 bytes data]
2525
* Connection #0 to host localhost left intact
2626

27-
=========================== Response Text =========================== <<<
27+
=========================== POST Response Text =========================== <<<
2828
includeReason: true
2929
######### STDERR #########
3030
######### EXIT 0 #########

Diff for: test/results/echo-filled-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
date: {
44
seconds: 1648044939
55
nanos: 152000000
66
}
77
includeReason: true
8-
=========================== Response Text =========================== <<<
8+
=========================== POST Response Text =========================== <<<
99
date: {
1010
seconds: 1648044939
1111
nanos: 152000000

Diff for: test/results/echo-filled-no-curl-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
date: {
44
seconds: 1648044939
55
nanos: 152000000
66
}
77
includeReason: true
8-
=========================== Response Text =========================== <<<
8+
=========================== POST Response Text =========================== <<<
99
date: {
1010
seconds: 1648044939
1111
nanos: 152000000

Diff for: test/results/echo-full-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
date: {
44
seconds: 1648044939
55
nanos: 152000000
@@ -21,7 +21,7 @@ misc: {
2121
fooString: "abc"
2222
}
2323
float: 0.123
24-
=========================== Response Text =========================== <<<
24+
=========================== POST Response Text =========================== <<<
2525
date: {
2626
seconds: 1648044939
2727
nanos: 152000000

Diff for: test/results/echo-full-json-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
######### STDOUT #########
2-
=========================== Request JSON =========================== >>>
2+
=========================== POST Request JSON =========================== >>>
33
{"includeReason":true,"double":0.12346789,"int32":123123123,"int64":"123123123123123","string":"some string here","bytes":"AAEC//79","fooEnum":"BAZ","misc":[{},{"weatherOfPastFewDays":["1","2"],"fooEnum":"FAZ"},{"fooString":"abc"}],"float":0.123}
4-
=========================== Response JSON =========================== <<<
4+
=========================== POST Response JSON =========================== <<<
55
{"includeReason":true,"double":0.12346789,"int32":123123123,"int64":"123123123123123","string":"some string here","bytes":"AAEC//79","fooEnum":"BAZ","misc":[{},{"weatherOfPastFewDays":["1","2"],"fooEnum":"FAZ"},{"fooString":"abc"}],"float":0.123}
66
######### STDERR #########
77
######### EXIT 0 #########

Diff for: test/results/echo-full-no-curl-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
date: {
44
seconds: 1648044939
55
nanos: 152000000
@@ -21,7 +21,7 @@ misc: {
2121
fooString: "abc"
2222
}
2323
float: 0.123
24-
=========================== Response Text =========================== <<<
24+
=========================== POST Response Text =========================== <<<
2525
date: {
2626
seconds: 1648044939
2727
nanos: 152000000

Diff for: test/results/empty-day-epoch-time-thursday-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
includeReason: true
4-
=========================== Response Text =========================== <<<
4+
=========================== POST Response Text =========================== <<<
55
isHappyDay: true
66
reason: "Thursday is a Happy Day! ⭐"
77
formattedDate: "Thu, 01 Jan 1970 00:00:00 GMT"

Diff for: test/results/empty-day-epoch-time-thursday-missing-curl-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
includeReason: true
4-
=========================== Response Text =========================== <<<
4+
=========================== POST Response Text =========================== <<<
55
isHappyDay: true
66
reason: "Thursday is a Happy Day! ⭐"
77
formattedDate: "Thu, 01 Jan 1970 00:00:00 GMT"

Diff for: test/results/empty-day-epoch-time-thursday-missing-curl-no-curl-expected.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
######### STDOUT #########
2-
=========================== Request Text =========================== >>>
2+
=========================== POST Request Text =========================== >>>
33
includeReason: true
4-
=========================== Response Text =========================== <<<
4+
=========================== POST Response Text =========================== <<<
55
isHappyDay: true
66
reason: "Thursday is a Happy Day! ⭐"
77
formattedDate: "Thu, 01 Jan 1970 00:00:00 GMT"

0 commit comments

Comments
 (0)