Skip to content

Allow Faraday 2.x #91

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

Merged
merged 3 commits into from
Apr 19, 2022
Merged

Allow Faraday 2.x #91

merged 3 commits into from
Apr 19, 2022

Conversation

jrochkind
Copy link
Collaborator

@jrochkind jrochkind commented Apr 4, 2022

Closes #89

Allow Faraday 2.x, by switching from faraday-middleware to the new faraday_follow-redirects gem

By switching from faraday-middleware to the new faraday_follow-redirects gem

The new gem is compatible with both faraday 1 and 2, while faraday-middleware (which included a redirect middleware) has a gemspec that does not allow faraday 2.

I manually tested on faraday 1 by editing Gemfile locally -- it passes. I'm not sure if we want to regularly/automated test on both faraday 1 and 2? Right now we have no automated CI at all, see #87

Strip invalid chars without raising encoding exception regardless of encoding

On upgrade to faraday 2, HTTP responses can come back in specific encodings per the content-type of response. This effected one of our tests, that is using a live query to google.com (probably not a great idea), that comes back ISO-8859-1. But it actually would have failed if UTF-8 too, because we're trying to gsub some intentionally illegal bytes. I am not sure if the approach to encoding is totally sound in this gem in general -- XML does have to be Unicode legally, but can be UTF-8 or -16, this strip routine may be assuming UTF8? But not actually properly making it with the ruby UTF8 encoding?

But this is just an attempt to change as little as possible leaving as backward compat as possible while passing tests in faraday 2; and resolving the specific problem of the strip_invalid_utf_8_chars failing when response comes back with ruby encoding tag from faraday 2.

…raday_follow-redirects gem

The new gem is compatible with both faraday 1 and 2, while faraday-middleware (which included a redirect middleware) has a gemspec that does not allow faraday 2.
…encoding

On upgrade to faraday 2, HTTP responses can come back in specific encodings per the content-type of response. This effected one of our tests, that is using a live query to google.com (probably not a great idea), that comes back ISO-8859-1. But it actually would have failed if UTF-8 too, because we're trying to gsub some intentionally illegal bytes.   I am not sure if the approach to encoding is totally sound in this gem in general -- XML does have to be Unicode legally, but can be UTF-8 or -16, this strip routine may be assuming UTF8? But not actually properly making it with the ruby UTF8 encoding?

But this is just an attempt to change as little as possible leaving as backward compat as possible while passing tests in faraday 2; and resolving the specific problem of the strip_invalid_utf_8_chars failing when response comes back with ruby encoding tag from faraday 2.
@jrochkind
Copy link
Collaborator Author

@mcritchlow and @orangewolf anyone interested in reviewing? If I don't hear from anyone, I may do a merge myself.

@@ -330,14 +331,27 @@ def parse_date(value)
# Regex is from WebCollab:
# http://webcollab.sourceforge.net/unicode.html
def strip_invalid_utf_8_chars(xml)
xml && xml.gsub(/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]
return xml unless xml
Copy link
Collaborator

Choose a reason for hiding this comment

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

return xml if xml ? this seems like it only ever returns nil

Copy link
Collaborator Author

@jrochkind jrochkind Apr 13, 2022

Choose a reason for hiding this comment

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

correct, it exits the method early to return nil unless xml is present. Similar to what the xml && did in the one-liner version previously. Do you think it would read better return nil unless xml? Or other?

Copy link
Collaborator

Choose a reason for hiding this comment

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

that reads more intentional and direct to me, but its a small quibble as long as this is doing what is intended.

@jrochkind
Copy link
Collaborator Author

Thanks @orangewolf!

@jrochkind jrochkind merged commit 3c83e43 into master Apr 19, 2022
@jrochkind jrochkind deleted the allow_faraday_2 branch April 19, 2022 19:53
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.

Allow faraday 2
2 participants