From 962eadae5d922ac61d2df4b293683a7a6ba70d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=83=9C=ED=98=81?= Date: Sat, 18 Mar 2023 08:24:26 +0900 Subject: [PATCH] Enable to overwrite default headers by command line options (#111) * add 'no-default-headers' flag * amend test cases and docs * Cleanup and refactor --------- Co-authored-by: GollyTicker --- .gitattributes | 4 +- EXAMPLES.md | 23 +- doc/generate-docs.sh | 17 ++ doc/generated.usage.txt | 3 +- doc/template.EXAMPLES.md | 9 + src/flags.go | 5 +- src/httpRequest.go | 7 +- src/protocurl.go | 7 +- .../results/additional-curl-args-expected.txt | 2 +- .../additional-curl-args-verbose-expected.txt | 5 +- .../display-binary-and-headers-expected.txt | 2 +- ...ay-binary-and-headers-no-curl-expected.txt | 2 +- .../echo-empty-with-curl-args-expected.txt | 2 +- test/results/far-future-json--v-expected.txt | 3 +- test/results/help-expected.txt | 3 +- test/results/help-missing-curl-expected.txt | 3 +- .../help-missing-curl-no-curl-expected.txt | 3 +- test/results/help-no-curl-expected.txt | 3 +- ...inferred-message-package-path-expected.txt | 3 +- ...path-name-clash-explicit-path-expected.txt | 3 +- test/results/json-in-text-output-expected.txt | 3 +- test/results/missing-args-expected.txt | 3 +- .../results/missing-args-no-curl-expected.txt | 3 +- .../results/missing-args-partial-expected.txt | 3 +- .../missing-args-partial-no-curl-expected.txt | 3 +- ...curl-header-args-not-possible-expected.txt | 2 +- test/results/missing-protoc-expected.txt | 1 + .../missing-protoc-global-expected.txt | 1 + .../missing-protocurl-internal-expected.txt | 1 + test/results/moved-lib-expected.txt | 1 + ...th-custom-content-type-header-expected.txt | 275 ++++++++++++++++++ ...rs-with-no-additional-headers-expected.txt | 271 +++++++++++++++++ ...ult-headers-with-no-curl-flag-expected.txt | 242 +++++++++++++++ ...-type-arg-inferred-decode-raw-expected.txt | 3 +- ...type-arg-overidden-decode-raw-expected.txt | 3 +- test/results/text-in-json-output-expected.txt | 3 +- .../verbose-custom-headers-expected.txt | 3 +- ...erbose-custom-headers-no-curl-expected.txt | 2 +- test/results/verbose-expected.txt | 3 +- ...verbose-long-args-equals-args-expected.txt | 3 +- .../results/verbose-missing-curl-expected.txt | 3 +- test/results/verbose-no-curl-expected.txt | 3 +- test/suite/testcases.json | 24 ++ 43 files changed, 933 insertions(+), 35 deletions(-) create mode 100644 test/results/no-default-headers-with-custom-content-type-header-expected.txt create mode 100644 test/results/no-default-headers-with-no-additional-headers-expected.txt create mode 100644 test/results/no-default-headers-with-no-curl-flag-expected.txt diff --git a/.gitattributes b/.gitattributes index 81bfbd8..39daf77 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ test/results/*.txt text eol=lf -**.md text eol=lf -**.sh text eol=lf \ No newline at end of file +**/*.md text eol=lf +**/**.sh text eol=lf diff --git a/EXAMPLES.md b/EXAMPLES.md index b35c203..744a50b 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -146,6 +146,26 @@ will produce no output, exit with a non-zero exitcode and only show this error: Error: Request was unsuccessful. Received response status code outside of 2XX. Got: HTTP/1.1 404 Not Found ``` +**No Default Header** + +Some headers use default values (e.g. `Content-Type: application/x-protobuf`). If you do not want to use these default values, use `--no-default-headers` flag (only work when using `--curl`). + +```bash +$ docker run -v "$PWD/test/proto:/proto" --network host qaware/protocurl \ + -i ..HappyDayRequest -o ..HappyDayResponse \ + -u http://localhost:8080/happy-day/verify \ + -d "date: { seconds: 1648044939}" \ + --curl -n -H 'Content-Type: application/octet-stream' + +=========================== Request Text =========================== >>> +date: { + seconds: 1648044939 +} +=========================== Response Text =========================== <<< +formattedDate: "Wed, 23 Mar 2022 14:15:39 GMT" +``` + + **Verbose via -v** ```bash @@ -170,6 +190,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -413,7 +434,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Sat, 11 Jun 2022 11:15:35 GMT +Date: Fri, 17 Mar 2023 23:19:03 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 35 diff --git a/doc/generate-docs.sh b/doc/generate-docs.sh index 2b15a1e..d382706 100755 --- a/doc/generate-docs.sh +++ b/doc/generate-docs.sh @@ -171,6 +171,22 @@ $(docker run -v "$WORKING_DIR/test/proto:/proto" --network host protocurl \ escapeString "$EXAMPLE_4" EXAMPLE_4="$ESCAPED" +# EXAMPLE_NO_DEFAULT_HEADER ============================ +EXAMPLE_NO_DEFAULT_HEADER="\$ docker run -v \"\$PWD/test/proto:/proto\" --network host qaware/protocurl \\ + -i ..HappyDayRequest -o ..HappyDayResponse \\ + -u http://localhost:8080/happy-day/verify \\ + -d \"date: { seconds: 1648044939}\" \\ + --curl -n -H 'Content-Type: application/octet-stream' + +$(docker run -v "$WORKING_DIR/test/proto:/proto" --network host protocurl \ + -i ..HappyDayRequest -o ..HappyDayResponse \ + -u http://localhost:8080/happy-day/verify \ + -d "date: { seconds: 1648044939}" \ + --curl -n -H'Content-Type: application/octet-stream')" + +escapeString "$EXAMPLE_NO_DEFAULT_HEADER" +EXAMPLE_NO_DEFAULT_HEADER="$ESCAPED" + # replacements ============================ echo "$EXAMPLES_TEMPLATE" | sed "s%___EXAMPLE_1___%$EXAMPLE_1%" | @@ -182,6 +198,7 @@ echo "$EXAMPLES_TEMPLATE" | sed "s%___EXAMPLE_OUTPUT_ONLY___%$EXAMPLE_OUTPUT_ONLY%" | sed "s%___EXAMPLE_OUTPUT_ONLY_WITH_ERR_1___%$EXAMPLE_OUTPUT_ONLY_WITH_ERR_1%" | sed "s%___EXAMPLE_OUTPUT_ONLY_WITH_ERR_2___%$EXAMPLE_OUTPUT_ONLY_WITH_ERR_2%" | + sed "s%___EXAMPLE_NO_DEFAULT_HEADER___%$EXAMPLE_NO_DEFAULT_HEADER%" | sed "s%___EXAMPLE_4___%$EXAMPLE_4%" >EXAMPLES.md normaliseOutput EXAMPLES.md diff --git a/doc/generated.usage.txt b/doc/generated.usage.txt index bf70497..78a456f 100644 --- a/doc/generated.usage.txt +++ b/doc/generated.usage.txt @@ -9,7 +9,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -29,6 +29,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/doc/template.EXAMPLES.md b/doc/template.EXAMPLES.md index 6c77719..6f09ad5 100644 --- a/doc/template.EXAMPLES.md +++ b/doc/template.EXAMPLES.md @@ -82,6 +82,15 @@ will produce no output, exit with a non-zero exitcode and only show this error: ___EXAMPLE_OUTPUT_ONLY_WITH_ERR_2___ ``` +**No Default Header** + +Some headers use default values (e.g. `Content-Type: application/x-protobuf`). If you do not want to use these default values, use `--no-default-headers` flag (only work when using `--curl`). + +```bash +___EXAMPLE_NO_DEFAULT_HEADER___ +``` + + **Verbose via -v** ```bash diff --git a/src/flags.go b/src/flags.go index 4951809..23eb01c 100644 --- a/src/flags.go +++ b/src/flags.go @@ -84,6 +84,9 @@ func intialiseFlags() { "The format can be set explicitly via --in. See "+GithubRepositoryLink) AssertSuccess(rootCmd.MarkFlagRequired("data-text")) + flags.BoolVarP(&CurrentConfig.NoDefaultHeaders, "no-default-headers", "n", false, + "Default headers (e.g. \"Content-Type\") will not be passed to curl. Assumes --curl. Use \"-n -H 'Content-Type: FooBar'\" to override the default content type.") + flags.StringArrayVarP(&CurrentConfig.RequestHeaders, "request-header", "H", []string{}, "Adds the `string` header to the invocation of cURL. This option is not supported when --no-curl is active. E.g. -H 'MyHeader: FooBar'.") @@ -209,5 +212,5 @@ func propagateFlags() { } func PanicDueToUnsupportedHeadersWhenInternalHttp(headers []string) { - PanicWithMessage(fmt.Sprintf("Custom headers are not supported when using internal http. Please provide curl in path and avoid using --no-curl. Found headers: %+q", headers)) + PanicWithMessage(fmt.Sprintf("Non-default or custom headers are not supported when using internal http. Please provide curl in path and avoid using --no-curl. Found headers: %+q", headers)) } diff --git a/src/httpRequest.go b/src/httpRequest.go index a7911b8..d5a5aa3 100644 --- a/src/httpRequest.go +++ b/src/httpRequest.go @@ -21,7 +21,7 @@ func invokeInternalHttpRequest(requestBinary []byte) ([]byte, string) { fmt.Println("Invoking internal http request.") } - if len(CurrentConfig.RequestHeaders) != 1 || CurrentConfig.RequestHeaders[0] != DefaultHeaders[0] { + if usingUnsupportedNonDefaultHeaders() { PanicDueToUnsupportedHeadersWhenInternalHttp(CurrentConfig.RequestHeaders) } @@ -40,6 +40,11 @@ func invokeInternalHttpRequest(requestBinary []byte) ([]byte, string) { return body, strings.TrimSpace(headersString) } +func usingUnsupportedNonDefaultHeaders() bool { + usingNonDefaultHeaders := len(CurrentConfig.RequestHeaders) != 1 || CurrentConfig.RequestHeaders[0] != DefaultHeaders[0] + return CurrentConfig.NoDefaultHeaders || usingNonDefaultHeaders +} + func invokeCurlRequest(requestBinary []byte, curlPath string) ([]byte, string) { if CurrentConfig.Verbose { fmt.Println("Invoking curl http request.") diff --git a/src/protocurl.go b/src/protocurl.go index 3730273..ce7d283 100644 --- a/src/protocurl.go +++ b/src/protocurl.go @@ -23,6 +23,7 @@ type Config struct { OutTextType OutTextType DecodeRawResponse bool DisplayBinaryAndHttp bool + NoDefaultHeaders bool RequestHeaders []string CustomCurlPath string AdditionalCurlArgs string @@ -65,7 +66,7 @@ var rootCmd = &cobra.Command{ "It uses a bundled '" + ProtocExecutableName + "' (by default) which is used to parse the .proto files.\n" + "The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via '" + ProtocExecutableName + "'.\n" + "If the bundled '" + ProtocExecutableName + "' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used.\n" + - "The Header 'Content-Type: application/x-protobuf' is set as a request header by default.\n" + + "The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n)\n" + "When converting between binary and text, the encoding UTF-8 is always used.\n" + "When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format.\n\n" + "Enhancements and bugs: " + EnhancementsAndBugsLink, @@ -172,6 +173,10 @@ func properResponseTypeIfProvidedOrEmptyType() string { } func addDefaultHeaderArgument() { + if CurrentConfig.NoDefaultHeaders { + return + } + if CurrentConfig.Verbose { fmt.Printf("Adding default header argument to request headers : %s\n", DefaultHeaders) } diff --git a/test/results/additional-curl-args-expected.txt b/test/results/additional-curl-args-expected.txt index d16063d..c5236f0 100644 --- a/test/results/additional-curl-args-expected.txt +++ b/test/results/additional-curl-args-expected.txt @@ -10,7 +10,7 @@ includeReason: true =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Tue, 26 Apr 2022 22:34:28 GMT +Date: Fri, 17 Mar 2023 11:27:07 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 65 diff --git a/test/results/additional-curl-args-verbose-expected.txt b/test/results/additional-curl-args-verbose-expected.txt index 8fddf2e..b853102 100644 --- a/test/results/additional-curl-args-verbose-expected.txt +++ b/test/results/additional-curl-args-verbose-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -277,7 +278,7 @@ Total curl args: * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Content-Type: application/x-protobuf -< Date: Mon, 16 May 2022 22:09:07 GMT +< Date: Fri, 17 Mar 2023 11:27:08 GMT < Connection: keep-alive < Keep-Alive: timeout=5 < Content-Length: 65 @@ -288,7 +289,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:09:07 GMT +Date: Fri, 17 Mar 2023 11:27:08 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 65 diff --git a/test/results/display-binary-and-headers-expected.txt b/test/results/display-binary-and-headers-expected.txt index 449395c..3deac4a 100644 --- a/test/results/display-binary-and-headers-expected.txt +++ b/test/results/display-binary-and-headers-expected.txt @@ -10,7 +10,7 @@ includeReason: true =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Tue, 26 Apr 2022 22:34:21 GMT +Date: Fri, 17 Mar 2023 11:27:06 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 65 diff --git a/test/results/display-binary-and-headers-no-curl-expected.txt b/test/results/display-binary-and-headers-no-curl-expected.txt index e59dee3..ab8c437 100644 --- a/test/results/display-binary-and-headers-no-curl-expected.txt +++ b/test/results/display-binary-and-headers-no-curl-expected.txt @@ -12,7 +12,7 @@ HTTP/1.1 200 OK Content-Length: 65 Connection: keep-alive Content-Type: application/x-protobuf -Date: Tue, 26 Apr 2022 22:34:24 GMT +Date: Fri, 17 Mar 2023 11:27:07 GMT Keep-Alive: timeout=5 =========================== Response Binary =========================== <<< 00000000 08 01 12 1c 54 68 75 72 73 64 61 79 20 69 73 20 |....Thursday is | diff --git a/test/results/echo-empty-with-curl-args-expected.txt b/test/results/echo-empty-with-curl-args-expected.txt index 3d64f43..e2dfa72 100644 --- a/test/results/echo-empty-with-curl-args-expected.txt +++ b/test/results/echo-empty-with-curl-args-expected.txt @@ -16,7 +16,7 @@ includeReason: true * Mark bundle as not supporting multiuse < HTTP/1.1 200 OK < Content-Type: application/x-protobuf -< Date: Tue, 26 Apr 2022 22:35:42 GMT +< Date: Fri, 17 Mar 2023 11:27:23 GMT < Connection: keep-alive < Keep-Alive: timeout=5 < Content-Length: 2 diff --git a/test/results/far-future-json--v-expected.txt b/test/results/far-future-json--v-expected.txt index 7358531..22fe487 100644 --- a/test/results/far-future-json--v-expected.txt +++ b/test/results/far-future-json--v-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "json", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -256,7 +257,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:09:10 GMT +Date: Fri, 17 Mar 2023 11:27:12 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 63 diff --git a/test/results/help-expected.txt b/test/results/help-expected.txt index 2c8d588..9ecb275 100644 --- a/test/results/help-expected.txt +++ b/test/results/help-expected.txt @@ -10,7 +10,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -30,6 +30,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/test/results/help-missing-curl-expected.txt b/test/results/help-missing-curl-expected.txt index 2c8d588..9ecb275 100644 --- a/test/results/help-missing-curl-expected.txt +++ b/test/results/help-missing-curl-expected.txt @@ -10,7 +10,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -30,6 +30,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/test/results/help-missing-curl-no-curl-expected.txt b/test/results/help-missing-curl-no-curl-expected.txt index 2c8d588..9ecb275 100644 --- a/test/results/help-missing-curl-no-curl-expected.txt +++ b/test/results/help-missing-curl-no-curl-expected.txt @@ -10,7 +10,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -30,6 +30,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/test/results/help-no-curl-expected.txt b/test/results/help-no-curl-expected.txt index 2c8d588..9ecb275 100644 --- a/test/results/help-no-curl-expected.txt +++ b/test/results/help-no-curl-expected.txt @@ -10,7 +10,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -30,6 +30,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/test/results/inferred-message-package-path-expected.txt b/test/results/inferred-message-package-path-expected.txt index 800e202..cda548d 100644 --- a/test/results/inferred-message-package-path-expected.txt +++ b/test/results/inferred-message-package-path-expected.txt @@ -14,6 +14,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -258,7 +259,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:08:45 GMT +Date: Fri, 17 Mar 2023 11:26:40 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 68 diff --git a/test/results/inferred-message-package-path-name-clash-explicit-path-expected.txt b/test/results/inferred-message-package-path-name-clash-explicit-path-expected.txt index 3b9c75a..52e2ba7 100644 --- a/test/results/inferred-message-package-path-name-clash-explicit-path-expected.txt +++ b/test/results/inferred-message-package-path-name-clash-explicit-path-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -323,7 +324,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:08:50 GMT +Date: Fri, 17 Mar 2023 11:26:47 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 68 diff --git a/test/results/json-in-text-output-expected.txt b/test/results/json-in-text-output-expected.txt index 224b09d..d1e021a 100644 --- a/test/results/json-in-text-output-expected.txt +++ b/test/results/json-in-text-output-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -256,7 +257,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:08:57 GMT +Date: Fri, 17 Mar 2023 11:26:55 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 68 diff --git a/test/results/missing-args-expected.txt b/test/results/missing-args-expected.txt index 5296fc2..0317d41 100644 --- a/test/results/missing-args-expected.txt +++ b/test/results/missing-args-expected.txt @@ -8,7 +8,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -28,6 +28,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/test/results/missing-args-no-curl-expected.txt b/test/results/missing-args-no-curl-expected.txt index 5296fc2..0317d41 100644 --- a/test/results/missing-args-no-curl-expected.txt +++ b/test/results/missing-args-no-curl-expected.txt @@ -8,7 +8,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -28,6 +28,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/test/results/missing-args-partial-expected.txt b/test/results/missing-args-partial-expected.txt index 51a1bf5..e4901ab 100644 --- a/test/results/missing-args-partial-expected.txt +++ b/test/results/missing-args-partial-expected.txt @@ -8,7 +8,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -28,6 +28,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/test/results/missing-args-partial-no-curl-expected.txt b/test/results/missing-args-partial-no-curl-expected.txt index 51a1bf5..e4901ab 100644 --- a/test/results/missing-args-partial-no-curl-expected.txt +++ b/test/results/missing-args-partial-no-curl-expected.txt @@ -8,7 +8,7 @@ It uses 'curl' from PATH. If none was found, it will fall back to an internal no It uses a bundled 'protoc' (by default) which is used to parse the .proto files. The bundle also includes the well-known Google Protobuf files necessary to create FileDescriptorSet payloads via 'protoc'. If the bundled 'protoc' is used, then these .proto files are included. Otherwise .proto files from the system-wide include are used. -The Header 'Content-Type: application/x-protobuf' is set as a request header by default. +The Header 'Content-Type: application/x-protobuf' is set as a request header by default. (disable via -n) When converting between binary and text, the encoding UTF-8 is always used. When the correct response type is unknown or being debugged, omitting -o will attempt to show the response in raw format. @@ -28,6 +28,7 @@ Flags: --in string Specifies, in which format the input -d should be interpreted in. 'text' (default) uses the Protobuf text format and 'json' uses JSON. The type is inferred as JSON if the first token is a '{'. -F, --infer-files 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 is provided, this -F is set and the files are inferred. --no-curl Forces the use of the built-in internal http request instead of curl. + -n, --no-default-headers Default headers (e.g. "Content-Type") will not be passed to curl. Assumes --curl. Use "-n -H 'Content-Type: FooBar'" to override the default content type. --out string Produces the output in the specified format. 'text' (default) produces Protobuf text format. 'json' produces dense JSON and 'json:pretty' produces pretty-printed JSON. The produced JSON always uses the original Protobuf field names instead of lowerCamelCasing them. -I, --proto-dir string Uses the specified directory to find the proto-file. (default "/proto") -f, --proto-file string Uses the specified file path to find the Protobuf definition of the message types within 'proto-dir' (relative file path). diff --git a/test/results/missing-curl-header-args-not-possible-expected.txt b/test/results/missing-curl-header-args-not-possible-expected.txt index 053c9c2..b4458af 100644 --- a/test/results/missing-curl-header-args-not-possible-expected.txt +++ b/test/results/missing-curl-header-args-not-possible-expected.txt @@ -6,5 +6,5 @@ date: { } includeReason: true ######### STDERR ######### -Error: Custom headers are not supported when using internal http. Please provide curl in path and avoid using --no-curl. Found headers: ["Content-Type: application/x-protobuf" "x-abc: def"] +Error: Non-default or custom headers are not supported when using internal http. Please provide curl in path and avoid using --no-curl. Found headers: ["Content-Type: application/x-protobuf" "x-abc: def"] ######### EXIT 1 ######### diff --git a/test/results/missing-protoc-expected.txt b/test/results/missing-protoc-expected.txt index 52a3f9a..9ad0204 100644 --- a/test/results/missing-protoc-expected.txt +++ b/test/results/missing-protoc-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], diff --git a/test/results/missing-protoc-global-expected.txt b/test/results/missing-protoc-global-expected.txt index cbf1f3a..0d07ad0 100644 --- a/test/results/missing-protoc-global-expected.txt +++ b/test/results/missing-protoc-global-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], diff --git a/test/results/missing-protocurl-internal-expected.txt b/test/results/missing-protocurl-internal-expected.txt index 38673cb..e2b7361 100644 --- a/test/results/missing-protocurl-internal-expected.txt +++ b/test/results/missing-protocurl-internal-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], diff --git a/test/results/moved-lib-expected.txt b/test/results/moved-lib-expected.txt index 54d9493..c1b60bc 100644 --- a/test/results/moved-lib-expected.txt +++ b/test/results/moved-lib-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], diff --git a/test/results/no-default-headers-with-custom-content-type-header-expected.txt b/test/results/no-default-headers-with-custom-content-type-header-expected.txt new file mode 100644 index 0000000..566217b --- /dev/null +++ b/test/results/no-default-headers-with-custom-content-type-header-expected.txt @@ -0,0 +1,275 @@ +######### STDOUT ######### +Inferred input text type as text. +protocurl , build , https://github.com/qaware/protocurl +Invoked with following default & parsed arguments: +{ + "ProtoFilesDir": "/proto", + "ProtoInputFilePath": "happyday.proto", + "RequestType": "happyday.HappyDayRequest", + "ResponseType": "happyday.HappyDayResponse", + "Url": "http://localhost:8080/happy-day/verify", + "DataText": "includeReason: true, date: { seconds: 1648044939, nanos: 152000000 }", + "InTextType": "text", + "OutTextType": "text", + "DecodeRawResponse": false, + "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": true, + "RequestHeaders": [ + "Content-Type: application/octet-stream" + ], + "CustomCurlPath": "", + "AdditionalCurlArgs": "", + "Verbose": true, + "ShowOutputOnly": false, + "ForceNoCurl": false, + "ForceCurl": true, + "GlobalProtoc": false, + "CustomProtocPath": "", + "InferProtoFiles": false +} +Found bundled protoc at /protocurl/protocurl-internal/bin/protoc +Using google protobuf include: /protocurl/protocurl-internal/include +Converting file happyday.proto in /proto to a FileDescriptorSet. +=========================== .proto descriptor =========================== +file: { + name: "google/protobuf/timestamp.proto" + package: "google.protobuf" + message_type: { + name: "Timestamp" + field: { + name: "seconds" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_INT64 + json_name: "seconds" + } + field: { + name: "nanos" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_INT32 + json_name: "nanos" + } + } + options: { + java_package: "com.google.protobuf" + java_outer_classname: "TimestampProto" + java_multiple_files: true + go_package: "google.golang.org/protobuf/types/known/timestamppb" + cc_enable_arenas: true + objc_class_prefix: "GPB" + csharp_namespace: "Google.Protobuf.WellKnownTypes" + } + syntax: "proto3" +} +file: { + name: "happyday.proto" + package: "happyday" + dependency: "google/protobuf/timestamp.proto" + message_type: { + name: "HappyDayRequest" + field: { + name: "date" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_MESSAGE + type_name: ".google.protobuf.Timestamp" + json_name: "date" + } + field: { + name: "includeReason" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_BOOL + json_name: "includeReason" + } + field: { + name: "double" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_DOUBLE + json_name: "double" + } + field: { + name: "int32" + number: 4 + label: LABEL_OPTIONAL + type: TYPE_INT32 + json_name: "int32" + } + field: { + name: "int64" + number: 5 + label: LABEL_OPTIONAL + type: TYPE_INT64 + json_name: "int64" + } + field: { + name: "string" + number: 6 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "string" + } + field: { + name: "bytes" + number: 7 + label: LABEL_OPTIONAL + type: TYPE_BYTES + json_name: "bytes" + } + field: { + name: "fooEnum" + number: 8 + label: LABEL_OPTIONAL + type: TYPE_ENUM + type_name: ".happyday.Foo" + json_name: "fooEnum" + } + field: { + name: "misc" + number: 9 + label: LABEL_REPEATED + type: TYPE_MESSAGE + type_name: ".happyday.MiscInfo" + json_name: "misc" + } + field: { + name: "float" + number: 10 + label: LABEL_OPTIONAL + type: TYPE_FLOAT + json_name: "float" + } + field: { + name: "NonCamel_case_FieldName" + number: 11 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "NonCamelCaseFieldName" + } + } + message_type: { + name: "HappyDayResponse" + field: { + name: "isHappyDay" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_BOOL + json_name: "isHappyDay" + } + field: { + name: "reason" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "reason" + } + field: { + name: "formattedDate" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "formattedDate" + } + field: { + name: "err" + number: 4 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "err" + } + } + message_type: { + name: "MiscInfo" + field: { + name: "weatherOfPastFewDays" + number: 1 + label: LABEL_REPEATED + type: TYPE_STRING + json_name: "weatherOfPastFewDays" + } + field: { + name: "fooString" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_STRING + oneof_index: 0 + json_name: "fooString" + } + field: { + name: "fooEnum" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_ENUM + type_name: ".happyday.Foo" + oneof_index: 0 + json_name: "fooEnum" + } + oneof_decl: { + name: "alternative" + } + } + enum_type: { + name: "Foo" + value: { + name: "BAR" + number: 0 + } + value: { + name: "BAZ" + number: 1 + } + value: { + name: "FAZ" + number: 2 + } + } + syntax: "proto3" +} +Looking up message with full name: happyday.HappyDayRequest +Looking up message with full name: happyday.HappyDayRequest +=========================== Request Text =========================== >>> +date: { + seconds: 1648044939 + nanos: 152000000 +} +includeReason: true +=========================== Request Binary =========================== >>> +00000000 0a 0b 08 8b d7 ec 91 06 10 80 ac bd 48 10 01 |............H..| +Expecting to find curl executable due to forced use of curl. +Found curl: /usr/bin/curl +Invoking curl http request. +Understood additional curl args: [] +Total curl args: + -s + -X + POST + --data-binary + @ + --output + + --dump-header + + -H + Content-Type: application/octet-stream + http://localhost:8080/happy-day/verify +=========================== Response Headers =========================== <<< +HTTP/1.1 200 OK +Content-Type: application/x-protobuf +Date: Fri, 17 Mar 2023 11:27:37 GMT +Connection: keep-alive +Keep-Alive: timeout=5 +Content-Length: 68 +=========================== Response Binary =========================== <<< +00000000 08 00 12 1f 54 6f 75 67 68 20 6c 75 63 6b 20 6f |....Tough luck o| +00000010 6e 20 57 65 64 6e 65 73 64 61 79 2e 2e 2e 20 f0 |n Wednesday... .| +00000020 9f 98 95 1a 1d 57 65 64 2c 20 32 33 20 4d 61 72 |.....Wed, 23 Mar| +00000030 20 32 30 32 32 20 31 34 3a 31 35 3a 33 39 20 47 | 2022 14:15:39 G| +00000040 4d 54 22 00 |MT".| +Looking up message with full name: happyday.HappyDayResponse +=========================== Response Text =========================== <<< +reason: "Tough luck on Wednesday... 😕" +formattedDate: "Wed, 23 Mar 2022 14:15:39 GMT" +######### STDERR ######### +######### EXIT 0 ######### diff --git a/test/results/no-default-headers-with-no-additional-headers-expected.txt b/test/results/no-default-headers-with-no-additional-headers-expected.txt new file mode 100644 index 0000000..28f0ec0 --- /dev/null +++ b/test/results/no-default-headers-with-no-additional-headers-expected.txt @@ -0,0 +1,271 @@ +######### STDOUT ######### +Inferred input text type as text. +protocurl , build , https://github.com/qaware/protocurl +Invoked with following default & parsed arguments: +{ + "ProtoFilesDir": "/proto", + "ProtoInputFilePath": "happyday.proto", + "RequestType": "happyday.HappyDayRequest", + "ResponseType": "happyday.HappyDayResponse", + "Url": "http://localhost:8080/happy-day/verify", + "DataText": "includeReason: true, date: { seconds: 1648044939, nanos: 152000000 }", + "InTextType": "text", + "OutTextType": "text", + "DecodeRawResponse": false, + "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": true, + "RequestHeaders": [], + "CustomCurlPath": "", + "AdditionalCurlArgs": "", + "Verbose": true, + "ShowOutputOnly": false, + "ForceNoCurl": false, + "ForceCurl": true, + "GlobalProtoc": false, + "CustomProtocPath": "", + "InferProtoFiles": false +} +Found bundled protoc at /protocurl/protocurl-internal/bin/protoc +Using google protobuf include: /protocurl/protocurl-internal/include +Converting file happyday.proto in /proto to a FileDescriptorSet. +=========================== .proto descriptor =========================== +file: { + name: "google/protobuf/timestamp.proto" + package: "google.protobuf" + message_type: { + name: "Timestamp" + field: { + name: "seconds" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_INT64 + json_name: "seconds" + } + field: { + name: "nanos" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_INT32 + json_name: "nanos" + } + } + options: { + java_package: "com.google.protobuf" + java_outer_classname: "TimestampProto" + java_multiple_files: true + go_package: "google.golang.org/protobuf/types/known/timestamppb" + cc_enable_arenas: true + objc_class_prefix: "GPB" + csharp_namespace: "Google.Protobuf.WellKnownTypes" + } + syntax: "proto3" +} +file: { + name: "happyday.proto" + package: "happyday" + dependency: "google/protobuf/timestamp.proto" + message_type: { + name: "HappyDayRequest" + field: { + name: "date" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_MESSAGE + type_name: ".google.protobuf.Timestamp" + json_name: "date" + } + field: { + name: "includeReason" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_BOOL + json_name: "includeReason" + } + field: { + name: "double" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_DOUBLE + json_name: "double" + } + field: { + name: "int32" + number: 4 + label: LABEL_OPTIONAL + type: TYPE_INT32 + json_name: "int32" + } + field: { + name: "int64" + number: 5 + label: LABEL_OPTIONAL + type: TYPE_INT64 + json_name: "int64" + } + field: { + name: "string" + number: 6 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "string" + } + field: { + name: "bytes" + number: 7 + label: LABEL_OPTIONAL + type: TYPE_BYTES + json_name: "bytes" + } + field: { + name: "fooEnum" + number: 8 + label: LABEL_OPTIONAL + type: TYPE_ENUM + type_name: ".happyday.Foo" + json_name: "fooEnum" + } + field: { + name: "misc" + number: 9 + label: LABEL_REPEATED + type: TYPE_MESSAGE + type_name: ".happyday.MiscInfo" + json_name: "misc" + } + field: { + name: "float" + number: 10 + label: LABEL_OPTIONAL + type: TYPE_FLOAT + json_name: "float" + } + field: { + name: "NonCamel_case_FieldName" + number: 11 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "NonCamelCaseFieldName" + } + } + message_type: { + name: "HappyDayResponse" + field: { + name: "isHappyDay" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_BOOL + json_name: "isHappyDay" + } + field: { + name: "reason" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "reason" + } + field: { + name: "formattedDate" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "formattedDate" + } + field: { + name: "err" + number: 4 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "err" + } + } + message_type: { + name: "MiscInfo" + field: { + name: "weatherOfPastFewDays" + number: 1 + label: LABEL_REPEATED + type: TYPE_STRING + json_name: "weatherOfPastFewDays" + } + field: { + name: "fooString" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_STRING + oneof_index: 0 + json_name: "fooString" + } + field: { + name: "fooEnum" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_ENUM + type_name: ".happyday.Foo" + oneof_index: 0 + json_name: "fooEnum" + } + oneof_decl: { + name: "alternative" + } + } + enum_type: { + name: "Foo" + value: { + name: "BAR" + number: 0 + } + value: { + name: "BAZ" + number: 1 + } + value: { + name: "FAZ" + number: 2 + } + } + syntax: "proto3" +} +Looking up message with full name: happyday.HappyDayRequest +Looking up message with full name: happyday.HappyDayRequest +=========================== Request Text =========================== >>> +date: { + seconds: 1648044939 + nanos: 152000000 +} +includeReason: true +=========================== Request Binary =========================== >>> +00000000 0a 0b 08 8b d7 ec 91 06 10 80 ac bd 48 10 01 |............H..| +Expecting to find curl executable due to forced use of curl. +Found curl: /usr/bin/curl +Invoking curl http request. +Understood additional curl args: [] +Total curl args: + -s + -X + POST + --data-binary + @ + --output + + --dump-header + + http://localhost:8080/happy-day/verify +=========================== Response Headers =========================== <<< +HTTP/1.1 200 OK +Content-Type: application/x-protobuf +Date: Fri, 17 Mar 2023 11:27:36 GMT +Connection: keep-alive +Keep-Alive: timeout=5 +Content-Length: 68 +=========================== Response Binary =========================== <<< +00000000 08 00 12 1f 54 6f 75 67 68 20 6c 75 63 6b 20 6f |....Tough luck o| +00000010 6e 20 57 65 64 6e 65 73 64 61 79 2e 2e 2e 20 f0 |n Wednesday... .| +00000020 9f 98 95 1a 1d 57 65 64 2c 20 32 33 20 4d 61 72 |.....Wed, 23 Mar| +00000030 20 32 30 32 32 20 31 34 3a 31 35 3a 33 39 20 47 | 2022 14:15:39 G| +00000040 4d 54 22 00 |MT".| +Looking up message with full name: happyday.HappyDayResponse +=========================== Response Text =========================== <<< +reason: "Tough luck on Wednesday... 😕" +formattedDate: "Wed, 23 Mar 2022 14:15:39 GMT" +######### STDERR ######### +######### EXIT 0 ######### diff --git a/test/results/no-default-headers-with-no-curl-flag-expected.txt b/test/results/no-default-headers-with-no-curl-flag-expected.txt new file mode 100644 index 0000000..127d2f9 --- /dev/null +++ b/test/results/no-default-headers-with-no-curl-flag-expected.txt @@ -0,0 +1,242 @@ +######### STDOUT ######### +Inferred input text type as text. +protocurl , build , https://github.com/qaware/protocurl +Invoked with following default & parsed arguments: +{ + "ProtoFilesDir": "/proto", + "ProtoInputFilePath": "happyday.proto", + "RequestType": "happyday.HappyDayRequest", + "ResponseType": "happyday.HappyDayResponse", + "Url": "http://localhost:8080/happy-day/verify", + "DataText": "includeReason: true, date: { seconds: 1648044939, nanos: 152000000 }", + "InTextType": "text", + "OutTextType": "text", + "DecodeRawResponse": false, + "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": true, + "RequestHeaders": [], + "CustomCurlPath": "", + "AdditionalCurlArgs": "", + "Verbose": true, + "ShowOutputOnly": false, + "ForceNoCurl": true, + "ForceCurl": false, + "GlobalProtoc": false, + "CustomProtocPath": "", + "InferProtoFiles": false +} +Found bundled protoc at /protocurl/protocurl-internal/bin/protoc +Using google protobuf include: /protocurl/protocurl-internal/include +Converting file happyday.proto in /proto to a FileDescriptorSet. +=========================== .proto descriptor =========================== +file: { + name: "google/protobuf/timestamp.proto" + package: "google.protobuf" + message_type: { + name: "Timestamp" + field: { + name: "seconds" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_INT64 + json_name: "seconds" + } + field: { + name: "nanos" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_INT32 + json_name: "nanos" + } + } + options: { + java_package: "com.google.protobuf" + java_outer_classname: "TimestampProto" + java_multiple_files: true + go_package: "google.golang.org/protobuf/types/known/timestamppb" + cc_enable_arenas: true + objc_class_prefix: "GPB" + csharp_namespace: "Google.Protobuf.WellKnownTypes" + } + syntax: "proto3" +} +file: { + name: "happyday.proto" + package: "happyday" + dependency: "google/protobuf/timestamp.proto" + message_type: { + name: "HappyDayRequest" + field: { + name: "date" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_MESSAGE + type_name: ".google.protobuf.Timestamp" + json_name: "date" + } + field: { + name: "includeReason" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_BOOL + json_name: "includeReason" + } + field: { + name: "double" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_DOUBLE + json_name: "double" + } + field: { + name: "int32" + number: 4 + label: LABEL_OPTIONAL + type: TYPE_INT32 + json_name: "int32" + } + field: { + name: "int64" + number: 5 + label: LABEL_OPTIONAL + type: TYPE_INT64 + json_name: "int64" + } + field: { + name: "string" + number: 6 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "string" + } + field: { + name: "bytes" + number: 7 + label: LABEL_OPTIONAL + type: TYPE_BYTES + json_name: "bytes" + } + field: { + name: "fooEnum" + number: 8 + label: LABEL_OPTIONAL + type: TYPE_ENUM + type_name: ".happyday.Foo" + json_name: "fooEnum" + } + field: { + name: "misc" + number: 9 + label: LABEL_REPEATED + type: TYPE_MESSAGE + type_name: ".happyday.MiscInfo" + json_name: "misc" + } + field: { + name: "float" + number: 10 + label: LABEL_OPTIONAL + type: TYPE_FLOAT + json_name: "float" + } + field: { + name: "NonCamel_case_FieldName" + number: 11 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "NonCamelCaseFieldName" + } + } + message_type: { + name: "HappyDayResponse" + field: { + name: "isHappyDay" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_BOOL + json_name: "isHappyDay" + } + field: { + name: "reason" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "reason" + } + field: { + name: "formattedDate" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "formattedDate" + } + field: { + name: "err" + number: 4 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "err" + } + } + message_type: { + name: "MiscInfo" + field: { + name: "weatherOfPastFewDays" + number: 1 + label: LABEL_REPEATED + type: TYPE_STRING + json_name: "weatherOfPastFewDays" + } + field: { + name: "fooString" + number: 2 + label: LABEL_OPTIONAL + type: TYPE_STRING + oneof_index: 0 + json_name: "fooString" + } + field: { + name: "fooEnum" + number: 3 + label: LABEL_OPTIONAL + type: TYPE_ENUM + type_name: ".happyday.Foo" + oneof_index: 0 + json_name: "fooEnum" + } + oneof_decl: { + name: "alternative" + } + } + enum_type: { + name: "Foo" + value: { + name: "BAR" + number: 0 + } + value: { + name: "BAZ" + number: 1 + } + value: { + name: "FAZ" + number: 2 + } + } + syntax: "proto3" +} +Looking up message with full name: happyday.HappyDayRequest +Looking up message with full name: happyday.HappyDayRequest +=========================== Request Text =========================== >>> +date: { + seconds: 1648044939 + nanos: 152000000 +} +includeReason: true +=========================== Request Binary =========================== >>> +00000000 0a 0b 08 8b d7 ec 91 06 10 80 ac bd 48 10 01 |............H..| +Using internal http request due to forced avoidance of curl. +Invoking internal http request. +######### STDERR ######### +Error: Non-default or custom headers are not supported when using internal http. Please provide curl in path and avoid using --no-curl. Found headers: [] +######### EXIT 1 ######### diff --git a/test/results/response-type-arg-inferred-decode-raw-expected.txt b/test/results/response-type-arg-inferred-decode-raw-expected.txt index 796cba7..f09491d 100644 --- a/test/results/response-type-arg-inferred-decode-raw-expected.txt +++ b/test/results/response-type-arg-inferred-decode-raw-expected.txt @@ -16,6 +16,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": true, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -258,7 +259,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Tue, 17 May 2022 21:49:45 GMT +Date: Fri, 17 Mar 2023 11:26:45 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 65 diff --git a/test/results/response-type-arg-overidden-decode-raw-expected.txt b/test/results/response-type-arg-overidden-decode-raw-expected.txt index 0147a7a..6a82a84 100644 --- a/test/results/response-type-arg-overidden-decode-raw-expected.txt +++ b/test/results/response-type-arg-overidden-decode-raw-expected.txt @@ -16,6 +16,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -257,7 +258,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Tue, 17 May 2022 21:49:46 GMT +Date: Fri, 17 Mar 2023 11:26:46 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 65 diff --git a/test/results/text-in-json-output-expected.txt b/test/results/text-in-json-output-expected.txt index c631083..1ee38cc 100644 --- a/test/results/text-in-json-output-expected.txt +++ b/test/results/text-in-json-output-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "json", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -260,7 +261,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:08:56 GMT +Date: Fri, 17 Mar 2023 11:26:54 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 68 diff --git a/test/results/verbose-custom-headers-expected.txt b/test/results/verbose-custom-headers-expected.txt index c89e9c5..8033063 100644 --- a/test/results/verbose-custom-headers-expected.txt +++ b/test/results/verbose-custom-headers-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf", "x-abc: def", @@ -266,7 +267,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:09:03 GMT +Date: Fri, 17 Mar 2023 11:27:02 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 65 diff --git a/test/results/verbose-custom-headers-no-curl-expected.txt b/test/results/verbose-custom-headers-no-curl-expected.txt index e5b2a4f..df46098 100644 --- a/test/results/verbose-custom-headers-no-curl-expected.txt +++ b/test/results/verbose-custom-headers-no-curl-expected.txt @@ -2,5 +2,5 @@ Inferred input text type as text. Infering proto files (-F), since -f was not provided. ######### STDERR ######### -Error: Custom headers are not supported when using internal http. Please provide curl in path and avoid using --no-curl. Found headers: ["x-abc: def" "x-ghi: jkl"] +Error: Non-default or custom headers are not supported when using internal http. Please provide curl in path and avoid using --no-curl. Found headers: ["x-abc: def" "x-ghi: jkl"] ######### EXIT 1 ######### diff --git a/test/results/verbose-expected.txt b/test/results/verbose-expected.txt index 0100623..cef9c04 100644 --- a/test/results/verbose-expected.txt +++ b/test/results/verbose-expected.txt @@ -14,6 +14,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -256,7 +257,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:09:01 GMT +Date: Fri, 17 Mar 2023 11:27:00 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 65 diff --git a/test/results/verbose-long-args-equals-args-expected.txt b/test/results/verbose-long-args-equals-args-expected.txt index 8e929ec..04230a1 100644 --- a/test/results/verbose-long-args-equals-args-expected.txt +++ b/test/results/verbose-long-args-equals-args-expected.txt @@ -14,6 +14,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -256,7 +257,7 @@ Total curl args: =========================== Response Headers =========================== <<< HTTP/1.1 200 OK Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:09:02 GMT +Date: Fri, 17 Mar 2023 11:27:02 GMT Connection: keep-alive Keep-Alive: timeout=5 Content-Length: 65 diff --git a/test/results/verbose-missing-curl-expected.txt b/test/results/verbose-missing-curl-expected.txt index c7865f2..f0547b5 100644 --- a/test/results/verbose-missing-curl-expected.txt +++ b/test/results/verbose-missing-curl-expected.txt @@ -15,6 +15,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -248,7 +249,7 @@ HTTP/1.1 200 OK Content-Length: 65 Connection: keep-alive Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:09:04 GMT +Date: Fri, 17 Mar 2023 11:27:04 GMT Keep-Alive: timeout=5 =========================== Response Binary =========================== <<< 00000000 08 01 12 1c 54 68 75 72 73 64 61 79 20 69 73 20 |....Thursday is | diff --git a/test/results/verbose-no-curl-expected.txt b/test/results/verbose-no-curl-expected.txt index 3667904..8b84923 100644 --- a/test/results/verbose-no-curl-expected.txt +++ b/test/results/verbose-no-curl-expected.txt @@ -14,6 +14,7 @@ Invoked with following default & parsed arguments: "OutTextType": "text", "DecodeRawResponse": false, "DisplayBinaryAndHttp": true, + "NoDefaultHeaders": false, "RequestHeaders": [ "Content-Type: application/x-protobuf" ], @@ -244,7 +245,7 @@ HTTP/1.1 200 OK Content-Length: 65 Connection: keep-alive Content-Type: application/x-protobuf -Date: Mon, 16 May 2022 22:09:02 GMT +Date: Fri, 17 Mar 2023 11:27:01 GMT Keep-Alive: timeout=5 =========================== Response Binary =========================== <<< 00000000 08 01 12 1c 54 68 75 72 73 64 61 79 20 69 73 20 |....Thursday is | diff --git a/test/suite/testcases.json b/test/suite/testcases.json index cbe9660..b354123 100644 --- a/test/suite/testcases.json +++ b/test/suite/testcases.json @@ -499,5 +499,29 @@ "filename": "version", "args": ["--version"], "runAgainWithArg": "--no-curl" + }, + { + "filename": "no-default-headers-with-no-additional-headers", + "args": [ + "-f happyday.proto -i happyday.HappyDayRequest -o happyday.HappyDayResponse -u http://localhost:8080/happy-day/verify", + "-d \"includeReason: true, date: { seconds: 1648044939, nanos: 152000000 }\" -v", + "-n --curl" + ] + }, + { + "filename": "no-default-headers-with-custom-content-type-header", + "args": [ + "-f happyday.proto -i happyday.HappyDayRequest -o happyday.HappyDayResponse -u http://localhost:8080/happy-day/verify", + "-d \"includeReason: true, date: { seconds: 1648044939, nanos: 152000000 }\" -v", + "--curl -n -H \"Content-Type: application/octet-stream\"" + ] + }, + { + "filename": "no-default-headers-with-no-curl-flag", + "args": [ + "-f happyday.proto -i happyday.HappyDayRequest -o happyday.HappyDayResponse -u http://localhost:8080/happy-day/verify", + "-d \"includeReason: true, date: { seconds: 1648044939, nanos: 152000000 }\" -v", + "-n --no-curl" + ] } ]