fix(tied-hash + ssleay): each-after-delete + HTTPS via HTTP::Tiny#576
Merged
fix(tied-hash + ssleay): each-after-delete + HTTPS via HTTP::Tiny#576
Conversation
The tied-hash iterator was eagerly calling NEXTKEY at the end of next()
to cache the upcoming key. When user code mutated the tied hash between
each() calls (e.g. `delete $h{$k}` inside `while (my ($k) = each %h)`),
that cached key was already past the entry whose internal index just
shifted — so the affected key was silently skipped.
Real Perl calls FIRSTKEY/NEXTKEY exactly once per each() invocation.
Move the fetch into hasNext() so the call happens lazily, inside the
next each(), after any user-visible mutation has taken effect.
Fixes Tie::IxHash's t/each-delete.t (and unblocks Net::HTTPS::Any,
which depends on Tie::IxHash).
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
PerlOnJava ships no OpenSSL backend, but it does ship HTTP::Tiny — which
already speaks HTTPS via the JVM TLS stack. Map Net::SSLeay's high-level
HTTP helpers onto HTTP::Tiny so modules built on Net::SSLeay (e.g.
Net::HTTPS::Any) work out of the box.
Changes to src/main/perl/lib/Net/SSLeay.pm:
* Add the high-level HTTP/HTTPS helpers and utility subs to @EXPORT_OK
(get_https, post_https, do_https, make_headers, make_form, sslcat, …)
so `use Net::SSLeay qw(...)` with an explicit import list compiles.
* Replace the _not_implemented stubs for get_https / post_https /
do_https with a small shim:
- parses the make_headers-style header string back into a hash
- calls HTTP::Tiny->new->request(...)
- repackages the response as Net::SSLeay's
($page, "HTTP/1.1 200 OK", @flat_headers).
Variants that need raw OpenSSL semantics (sslcat, *_https3, *_https4,
*_httpx, dump_peer_certificate, …) still raise "not implemented".
Result: Net::HTTPS::Any's full test suite now passes 10/10, including
the live HTTPS GET/POST integration tests.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Investigated
jcpan -t Net::HTTPS::Anyand fixed two distinct bugs thattogether unblock the full test suite (10/10 passing, including the live
HTTPS GET/POST integration tests).
1. Tied-hash
eachskipped entries afterdeleteRuntimeTiedHashIteratorwas eagerly callingNEXTKEYat the end ofnext()to cache the upcoming key. When user code mutated the tiedhash between
eachcalls (e.g.delete $h{$k}insidewhile (my ($k) = each %h)), the cached key already pointed past theentry whose internal index had just shifted — so an entry was silently
skipped.
Real Perl calls
FIRSTKEY/NEXTKEYexactly once pereach()invocation. Moved the fetch into
hasNext()so it happens lazilyinside the next
each(), after any user-visible mutation.Fixes Tie::IxHash's
t/each-delete.t(which Net::HTTPS::Any depends onvia
tie my %hash, 'Tie::IxHash', ...for ordered query args).2.
Net::SSLeaycouldn't do HTTPSPerlOnJava ships no OpenSSL backend, but it does ship
HTTP::Tiny,which already speaks HTTPS via the JVM TLS stack. Wired
get_https/post_https/do_httpsto delegate toHTTP::Tiny:make_headers-style header string back into a hashHTTP::Tiny->new->request(...)($page, "HTTP/1.1 200 OK", @flat_headers)return shapeAlso added the high-level helpers (
get_https,post_https,make_headers,make_form,sslcat,do_https,print_errs, …) to@EXPORT_OKsouse Net::SSLeay qw(get_https post_https ...)compiles.Variants that need raw OpenSSL semantics (
sslcat,*_https3,*_https4,*_httpx,dump_peer_certificate, …) still raise"not implemented" — those would need a JSSE-backed socket layer.
Test plan
makepasses (full unit test suite green)Tie::IxHashtest suite: 29/29 pass (was 27/29)jcpan -t Net::HTTPS::Any: 10/10 pass, includingt/get-netssleay.t(live GET to www.fortify.net) andt/post-netssleay.t(live POST to accounts.google.com /www.google.com)
Net::SSLeay::get_https('example.com', 443, '/', ...)returns
HTTP/1.1 200 OKwith the expected body and headersGenerated with Devin