-
Notifications
You must be signed in to change notification settings - Fork 964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expose .peer_cert on Response #634
Conversation
My last commit messed this up for everything... my first commit was working on half of the Ruby versions (the more recent ones)... seems there may be some issues with the way WebMock works on older rubies. Would appreciate any ideas / advice from anyone who's had to fight this kind of stuff in the past. |
Closes jnunemaker#633 There are use cases for accessing the X509 certificate used by the server; this commit exposes this certificate via Response#peer_cert, which uses the same method name as peer_cert on the Net::HTTP class: https://ruby-doc.org/stdlib-2.4.2/libdoc/net/http/rdoc/Net/HTTP.html#method-i-peer_cert
414aca2
to
434bbba
Compare
OK I think I got it! I'm already using this branch in our codebase to monitor/report certificates that are expiring within a month and it works great. |
@jnunemaker This is ready for review when you have a second :) |
@TheSmartnik do you have a second to take a look at this? We've using it to great effect for a few months now. |
@machty Hi! Thank you for contributing to httparty. I'm sorry it took so long to review your pr. I feel like exposure of However, you're right that we need some way to access |
@TheSmartnik exposing the connection object seems fine to me. One weird thing about that (which is true of my PR as well) is with following redirects: if we expose I guess for my use case, I'd want to know if any of the peer_certs in a series of redirects is expiring soon, so I guess I'd want access to all the connections involved. It just feels perhaps a bit heavy to stash an array of |
@machty thanks for suggestions.
Run a few tests. Difference turned out to be insignificant. However, it appears that it wouldn't work anyway. Due to implementation of The only other solution I can think of is to rename So retrievement of
The only problem with this is that passing a block to httparty makes it to stream response. On the other hand it will allow much greater flexibility. You can check whether it's a redirect and save multiple certificates etc. |
@TheSmartnik I'm not familiar enough with the internals to know if something like this exists, but it seems like it'd be nice and less disruptive (relative to requiring stream/block form) if a Response body included an array of all the intermediate redirects/requests that were part of a Response, and whatever this "mini-Request" objects were would provide the Alternatively, I just realized it might be a nice use case to be able to do additional validation on the certificate before allowing the download / request to continue; I don't know if this is possible at the Net::HTTP level, but it might be nice if you could provide HTTParty an What do you think? |
Thanks. Idea is generally good, but I don't think it fits nicely here.
HTTParty already has lots of little known and used options. I don't think we need any more, to be honest. Sorry 😞 |
Thanks for the feedback.
I'm looking at this code and unless I'm misunderstanding, I think you'd want to omit the So, to modify your example:
Maybe I'm wrong. Either way, I'm OK with your proposed API of exposing the connection object when using block mode. Would you be OK if I made these changes to my PR? |
Basically, the
Would be awesome, thanks! Also, could you please add an example to examples as well. |
This provides access to the connection object, which in turn exposes properties like `.peer_cert` for performing additional validation against x509 certificates. Closes jnunemaker#633, Follow-up to jnunemaker#634
Closing in favor of #648 |
This provides access to the connection object, which in turn exposes properties like `.peer_cert` for performing additional validation against x509 certificates. Closes jnunemaker#633, Follow-up to jnunemaker#634
This provides access to the connection object, which in turn exposes properties like `.peer_cert` for performing additional validation against x509 certificates. Closes jnunemaker#633, Follow-up to jnunemaker#634
This provides access to the connection object, which in turn exposes properties like `.peer_cert` for performing additional validation against x509 certificates. Closes jnunemaker#633, Follow-up to jnunemaker#634
This provides access to the connection object, which in turn exposes properties like `.peer_cert` for performing additional validation against x509 certificates. Closes jnunemaker#633, Follow-up to jnunemaker#634
Closes #633
There are use cases for accessing the X509
certificate used by the server; this commit
exposes this certificate via Response#peer_cert,
which uses the same method name as peer_cert
on the Net::HTTP class:
https://ruby-doc.org/stdlib-2.4.2/libdoc/net/http/rdoc/Net/HTTP.html#method-i-peer_cert