Skip to content

Use stateful CookieJar in Redirector - #613

Merged
ixti merged 1 commit into
httprb:4-x-stablefrom
Kache:redirect-jar
Sep 22, 2020
Merged

ixti merged 1 commit into
httprb:4-x-stablefrom
Kache:redirect-jar

Conversation

@Kache

@Kache Kache commented Jun 15, 2020

Copy link
Copy Markdown

As mentioned in #264, CookieJar
implements cookie domain scoping rules, which is useful when issuing
redirects across domains.

Resolves: #264

@Kache
Kache force-pushed the redirect-jar branch 2 times, most recently from 02183ad to b03076a Compare June 15, 2020 09:34

@Kache Kache left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves an SSO authentication redirect problem I have, and I'd prefer not to use curb. (I actually still have to use curb anyway for one endpoint b/c libcurl implements SPNEGO via GSS-API to authenticate /w Kerberos, and I don't yet know how to do the same in http.rb)

I saw #306, and although HTTP::Session is supposed to do something similar, I can't tell what HTTP::Redirector's relationship with HTTP::Session is intended to be.

I'm getting test #<OpenSSL::SSL::SSLError: SSL_read: sslv3 alert unsupported certificate> errors when running locally and in TravisCI, even on master and v4.4.1. Is there someone that can help with that? I still need to add new tests.

Comment thread lib/http/redirector.rb
def initialize(opts = {}) # rubocop:disable Style/OptionHash
@strict = opts.fetch(:strict, true)
@max_hops = opts.fetch(:max_hops, 5).to_i
@jar = opts.fetch(:jar, CookieJar.new)

@Kache Kache Jun 15, 2020 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use an existing cookiejar from disk:

persisted_jar = HTTP::CookieJar.new.load(from_disk_path, format: :cookiestxt)
response = HTTP.follow(jar: persisted_jar).get(endpoint)
persisted_jar.save(to_disk_path, format: :cookiestxt) # if you'd like

I suppose putting the persistent cookie jar option in HTTP.follow might not be considered intuitive. Also, Redirector is somewhat similar to Session, as they are both external to Client and hold longer-lived state.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in fact I was thinking that we should completely refactor redirector. And provide some sort of Session object that will "mimic" the browser behaviour. So I think it's OK-ish for now.

Comment thread lib/http/request.rb

# Returns new Request with updated uri
def redirect(uri, verb = @verb)
def redirect(uri, verb = @verb, cookies_raw: nil)

@Kache Kache Jun 15, 2020 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would've liked to inline redirect -- I think it's more fitting to have the higher level controller, Redirector, do it rather than asking Request to redirect itself.

It'd also avoid having to cookies_raw: nil just to protect against api change.

thoughts?

@Kache
Kache marked this pull request as ready for review June 15, 2020 10:59
@Kache
Kache force-pushed the redirect-jar branch 2 times, most recently from 525aad7 to c894167 Compare June 18, 2020 04:43
As [mentioned](..httprb/issues/264#issuecomment-157070867) in httprb#264, CookieJar
implements cookie domain scoping rules, which is useful when issuing
redirects across domains.

Resolves: httprb#264
@ixti
ixti self-requested a review July 3, 2020 14:09
@tycooon

tycooon commented Sep 2, 2020

Copy link
Copy Markdown

Hey guys, what's up with this PR?

@tarcieri

tarcieri commented Sep 2, 2020 •

Copy link
Copy Markdown
Member

I'd agree with @ixti it looks OK-ish for now.

I think it'd really be better to extract an HTTP::Session type out of client which deals with request state i.e. CookieJars, but otherwise this PR does address some longstanding requests.

@ixti

ixti commented Sep 4, 2020

Copy link
Copy Markdown
Member

Sorry it took me some time to get back in line but I will try to work on PRs this weekend.

ixti added a commit that referenced this pull request Sep 22, 2020
Client shoud not know about CookieJar, it's just a client not a browser
or session. Also, I've decided to keep `Request#redirect` as it was
before #613 and deprecate it instead (will be removed in 5.0.0).

Redirected request builing moved into redirector itself.
@ixti
ixti merged commit fef377b into httprb:4-x-stable Sep 22, 2020
@ixti

ixti commented Sep 22, 2020

Copy link
Copy Markdown
Member

I've merged this PR with some changes:

  1. reverted changes to the HTTP::Client as they were irrelevant to the scope of this PR
  2. marked Request#redirect as deprecated and reverted changes to its API
  3. moved redirected request builder into redirector.

Notice that most likely branch will fail CI. We need to upgrade test tooling. And some tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants