Skip to content
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

Adding Support for chrome extension 'scheme' #2465

Closed
wants to merge 7 commits into from

Conversation

leandrocruz
Copy link

ZIO Http fails to handle requests from chrome extensions, when the origin header is chrome-extension://EXTENSION_ID.

@CLAassistant
Copy link

CLAassistant commented Sep 30, 2023

CLA assistant check
All committers have signed the CLA.

@@ -3039,8 +3039,8 @@ object Header {
if (value == "null") Right(Null)
else
URL.decode(value) match {
case Left(_) => Left("Invalid Origin header")
case Right(url) if url.host.isEmpty || url.scheme.isEmpty => Left("Invalid Origin header")
case Left(_) => Left(s"Invalid Origin header '$value'")
Copy link
Author

Choose a reason for hiding this comment

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

Better error message for clarity

case 3 => Scheme.WSS
case 2 => Scheme.WS
case _ => null
else {
Copy link
Author

Choose a reason for hiding this comment

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

Decided for clarity over "speed"

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (f5c67c3) 64.76% compared to head (32a59d9) 64.76%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2465   +/-   ##
=======================================
  Coverage   64.76%   64.76%           
=======================================
  Files         136      136           
  Lines        7197     7201    +4     
  Branches     1296     1276   -20     
=======================================
+ Hits         4661     4664    +3     
- Misses       2536     2537    +1     
Files Coverage Δ
zio-http/src/main/scala/zio/http/Header.scala 63.46% <100.00%> (ø)
zio-http/src/main/scala/zio/http/URL.scala 84.74% <100.00%> (+0.13%) ⬆️
zio-http/src/main/scala/zio/http/ZClient.scala 47.44% <ø> (ø)
zio-http/src/main/scala/zio/http/Scheme.scala 69.23% <70.58%> (-0.34%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leandrocruz leandrocruz force-pushed the chrome-extension-scheme branch from c6c11f9 to c7aabbb Compare October 3, 2023 18:45
case Scheme.HTTPS => "https"
case Scheme.WS => "ws"
case Scheme.WSS => "wss"
case Scheme.ChromeExtension => "chrome-extension"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, that having this explicitly is a good idea. Maybe we should have a Custom case, like for http method?
@vigoo @jdegoes

Copy link
Author

Choose a reason for hiding this comment

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

Not sure if this is the right solution also, but, as it is today, zio http fails to accept requests from chrome extensions

@987Nabil
Copy link
Contributor

I think #2489 confirms my hinch. We should have a custom type that stores non predefined schema values.

@FabioPinheiro
Copy link
Contributor

I'm just concerned about efficiency.
Is there benchmark that I can run on #2490?

@987Nabil
Copy link
Contributor

987Nabil commented Oct 19, 2023

What kind of efficiency are we talking about?
I mean we can match against the ones that have a fixed type and return the fixed type. For all others, we would have 2 options I guess.

  • just put the string as is in a custom wrapper
  • validate via regex the validity and only if valid put it in the wrapper

So, where do you see an issue?

@vigoo
Copy link
Contributor

vigoo commented Nov 23, 2023

I agree to have a Custom(String) case instead

@987Nabil
Copy link
Contributor

@vigoo there is #2490 which is already further in development.
@leandrocruz I am closing this PR in favor of the other.

@987Nabil 987Nabil closed this Nov 23, 2023
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.

6 participants