curl_headers: Handle POST requests
`Livecheck::Strategy.page_headers` uses `Utils::Curl.curl_headers` but the method only handles `HEAD` and `GET` requests. I recently added `POST` support to livecheck but forgot to update `curl_headers` in the process, so `livecheck` blocks using the `HeaderMatch` strategy along with `post_form` or `post_json` will fail because curl doesn't allow both `--head` and `--data`/`--json` arguments. This addresses the issue by updating `curl_headers` to handle `POST` requests and skip the `GET` retry logic.
This commit is contained in:
parent
a2d0aae9a1
commit
9096a111d7
@ -277,15 +277,20 @@ module Utils
|
|||||||
).returns(T::Hash[Symbol, T.untyped])
|
).returns(T::Hash[Symbol, T.untyped])
|
||||||
}
|
}
|
||||||
def curl_headers(*args, wanted_headers: [], **options)
|
def curl_headers(*args, wanted_headers: [], **options)
|
||||||
get_retry_args = ["--request", "GET"]
|
base_args = ["--fail", "--location", "--silent"]
|
||||||
|
get_retry_args = []
|
||||||
|
if (is_post_request = args.include?("POST"))
|
||||||
|
base_args << "--dump-header" << "-"
|
||||||
|
else
|
||||||
|
base_args << "--head"
|
||||||
|
get_retry_args << "--request" << "GET"
|
||||||
|
end
|
||||||
|
|
||||||
# This is a workaround for https://github.com/Homebrew/brew/issues/18213
|
# This is a workaround for https://github.com/Homebrew/brew/issues/18213
|
||||||
get_retry_args << "--http1.1" if curl_version >= Version.new("8.7") && curl_version < Version.new("8.10")
|
get_retry_args << "--http1.1" if curl_version >= Version.new("8.7") && curl_version < Version.new("8.10")
|
||||||
|
|
||||||
[[], get_retry_args].each do |request_args|
|
[[], get_retry_args].each do |request_args|
|
||||||
result = curl_output(
|
result = curl_output(*base_args, *request_args, *args, **options)
|
||||||
"--fail", "--location", "--silent", "--head", *request_args, *args,
|
|
||||||
**options
|
|
||||||
)
|
|
||||||
|
|
||||||
# We still receive usable headers with certain non-successful exit
|
# We still receive usable headers with certain non-successful exit
|
||||||
# statuses, so we special case them below.
|
# statuses, so we special case them below.
|
||||||
@ -295,6 +300,7 @@ module Utils
|
|||||||
CURL_RECV_ERROR_EXIT_CODE,
|
CURL_RECV_ERROR_EXIT_CODE,
|
||||||
].include?(result.exit_status)
|
].include?(result.exit_status)
|
||||||
parsed_output = parse_curl_output(result.stdout)
|
parsed_output = parse_curl_output(result.stdout)
|
||||||
|
return parsed_output if is_post_request
|
||||||
|
|
||||||
if request_args.empty?
|
if request_args.empty?
|
||||||
# If we didn't get any wanted header yet, retry using `GET`.
|
# If we didn't get any wanted header yet, retry using `GET`.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user