Replace `--no-verify` flag with `--verify` #1140
<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->
Merging this PR will not alter performance
✅ 17 untouched benchmarks ⏩ 7 skipped benchmarks[^skipped]
---
<sub>Comparing <code>AleksaMCode:fix/cli-no-verify-flag</code> (6c6f0b1) with <code>main</code> (71ae23b)</sub>
<a href="https://app.codspeed.io/pydantic/httpx2/branches/AleksaMCode%3Afix%2Fcli-no-verify-flag?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>
[^skipped]: 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
<!-- cubic:review-summary:start -->
No issues found across 1 file
<!-- cubic:review-summary:end -->
<sub>Re-trigger cubic</sub>
<!-- cubic:review-post:ai_pr_review_1786906026799_36cca624-fc40-4043-ad89-bf862e8c193a:ad56ae1a37815395f9eb3cd7850f8cc60de0d734:ce3bb44e-509c-47b8-9e82-14bfc56d20b9 -->
Thanks for catching this error!
~$ httpx2 --no-verify https://expired.badssl.com/
ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1082)
It's a click behavior change in 8.3.0! Up to 8.2.1, Option.__init__ contained flag_value = not self.default, so is_flag=True, default=True gave you flag_value=False.
That line was removed in pallets/click#3030 in favour of self.flag_value = True, so --no-verify now sets verify=True and silently does nothing. But with your PR, on click 8.3, the default will be to not verify SSL, that's a problem!! (and then on 8.4 it would work again)
So I think we'd best make it fully explicit:
@click.option(
"--no-verify",
"no_verify",
is_flag=True,
default=False,
help="Disable SSL verification.",
)
@mbeijen Totally agree this alternative may read clearer and better expresses the intent of the flag. That said, I don’t think Click 8.3 compatibility is a practical issue here, since this project explicitly requires click>=8.4.2 in src/httpx2/pyproject.toml for the current httpx2 version.
@mbeijen Totally agree this alternative may read clearer and better expresses the intent of the flag. That said, I don’t think Click 8.3 compatibility is a practical issue here, since this project explicitly requiresclick>=8.4.2insrc/httpx2/pyproject.tomlfor the currenthttpx2version.
Ah, you're right, it got upped in 2cb02fe1c and later again a time. I was looking at an old checkout, I'm sorry.
But indeed, explicit is better than implicit, this code is the best solution for the problem.
@Kludex please consider this PR
Approved these changes.
Can't we replace this with --verify instead?
@Kludex we can, I just wanted to preserve already existing flag. I'll push the changes.
But I think the flag is preserved, because it's a boolean. 🤔
@Kludex I meant I wanted to keep --no-verify without changing it to --verify and introducing "breaking change." For me using --no-verify was "simpler":
# Default SSL verification ON
httpx2 https://example.com/
# Disable SSL verification
httpx2 --no-verify https://example.com/
Compared to this new version:
# Default SSL verification ON
httpx2 https://example.com
# Explicit SSL verification
httpx2 --verify true https://example.com
# Disable SSL verification
httpx2 --verify false https://example.com
@Kludex I've pushed the new changes, could you take a look?
Approved these changes.
Thanks. :)
mbeijen
AleksaMCode
Summary
Fixes the CLI
--no-verifyflag so it actually disables TLS certificate verification when used.Edit:
After some discussion, the flag was changed from
--no-verifyto--verify.Checklist
<!-- This is an auto-generated description by cubic. -->
<a href="https://cubic.dev/pr/pydantic/httpx2/pull/1140?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->