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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass omit_default_port from request to response #809

Merged
merged 1 commit into from Jan 18, 2023

Conversation

mburumaxwell
Copy link
Contributor

@mburumaxwell mburumaxwell commented Jan 18, 2023

Similar to #803, this PR passes the omit_default_port attribute to the response.

Why?
When subscribed via ActiveNotifications, the Url formed for the request is not similar to the one for the response. The later includes the port. E.g. https://contoso.com:443/my-path

The URLs are generated using Excon::Utils.request_uri(...)

The code:

ActiveSupport::Notifications.subscribe(/excon/) do |*args|
   name = args.first
   $network_trace_count += 1 if name == "excon.request"

   payload = args.last
   if name == "excon.request" || name == "excon.response"
     puts "馃實 #{name == 'excon.response' ? "<-- #{payload[:status]}" : "--> #{payload[:method].upcase}"}" \
          " #{Excon::Utils.request_uri(payload)}"
   end
 end

The logs

馃實 --> GET https://dev.azure.com/tingle/dependabot/_apis/git/repositories/repro-366
馃實 <-- 200 https://dev.azure.com:443/tingle/dependabot/_apis/git/repositories/repro-366
馃實 --> GET https://dev.azure.com/tingle/dependabot/_apis/git/repositories/repro-366/stats/branches?name=main
馃實 <-- 200 https://dev.azure.com:443/tingle/dependabot/_apis/git/repositories/repro-366/stats/branches?name=main
馃實 --> GET https://dev.azure.com/tingle/dependabot/_apis/git/repositories/repro-366/items?path=.github/dependabot.yml&versionDescriptor.versionType=commit&versionDescriptor.version=484e0dccc2d7b6a3bbb886a01c1da23544de8c36
馃實 <-- 200 https://dev.azure.com:443/tingle/dependabot/_apis/git/repositories/repro-366/items?path=.github/dependabot.yml&versionDescriptor.versionType=commit&versionDescriptor.version=484e0dccc2d7b6a3bbb886a01c1da23544de8c36

Related to dependabot/dependabot-core#6459

I also fixed indentation for additions in #803

Copy link
Contributor

@geemus geemus left a comment

Choose a reason for hiding this comment

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

Thanks, I think that all makes sense. Just to make sure I'm getting it though, is it accurate to say that the logs you show here are the pre-patch behavior? ie I would think if I understand the change correctly that after the patch the request/response values should actually match up (with either both or neither containing the port, depending on the omit_default_port setting). Is that accurate?

.gitignore Outdated Show resolved Hide resolved
@mburumaxwell
Copy link
Contributor Author

Thanks, I think that all makes sense. Just to make sure I'm getting it though, is it accurate to say that the logs you show here are the pre-patch behavior? ie I would think if I understand the change correctly that after the patch the request/response values should actually match up (with either both or neither containing the port, depending on the omit_default_port setting). Is that accurate?

Yes this is correct.

Copy link
Contributor

@geemus geemus left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@geemus geemus merged commit a72c2d9 into excon:master Jan 18, 2023
@mburumaxwell mburumaxwell deleted the pass-along-omit_default_port branch January 19, 2023 06:59
@geemus
Copy link
Contributor

geemus commented Jan 20, 2023

@mburumaxwell did you need a release with this change?

@mburumaxwell
Copy link
Contributor Author

@geemus it would be great to get a release. A patch maybe?

@geemus
Copy link
Contributor

geemus commented Jan 20, 2023

Released in v0.97.2.

@mburumaxwell Random thought, I wonder if we might eventually want to move toward something like a request_params key for the response data and group everything there, instead of having it mix request/response related stuff at the top level. This might also allow us to future-proof by pushing everything into that from request, instead of needing to cherry pick. That said, we now have released this and have things that might be depending on it, so it would be a breaking change (and therefore probably need some double writing and backwards compatibility stuff to transition). Does that make sense? What do you think? No immediate action needed here, just thinking aloud and hoping to get some feedback on whether we might want to head that way in the future.

@mburumaxwell
Copy link
Contributor Author

Released in v0.97.2.

@mburumaxwell Random thought, I wonder if we might eventually want to move toward something like a request_params key for the response data and group everything there, instead of having it mix request/response related stuff at the top level. This might also allow us to future-proof by pushing everything into that from request, instead of needing to cherry pick. That said, we now have released this and have things that might be depending on it, so it would be a breaking change (and therefore probably need some double writing and backwards compatibility stuff to transition). Does that make sense? What do you think? No immediate action needed here, just thinking aloud and hoping to get some feedback on whether we might want to head that way in the future.

That would actually make things a lot easier because the information required for logging/instrumentation or other work would always be available. It makes a lot of sense.

@geemus
Copy link
Contributor

geemus commented Jan 24, 2023

@mburumaxwell - thanks for confirming. It seemed like it could in the long term make things much simpler and would allow any other changes to request to "just work". The in between parts seem like they could be a bit trickier though. I'll have to think a bit more on the specifics, but it's good to have a general idea of direction at least.

@mburumaxwell
Copy link
Contributor Author

I have a random, possible not so-good, idea:

  1. Migrate to a request_params key in the response data.
  2. Add middleware (or configuration) that would add all the details in the request_params into the current params. Adding this middleware or enabling the configuration would result in the current behaviour.

Problem is it would break the functionality but maybe the reverse would work i.e. opt-in the new behaviour.

Also, thinking out-loud.

@geemus
Copy link
Contributor

geemus commented Jan 26, 2023

@mburumaxwell - I created a new issue with more details of this idea #811 so that we can discuss (and hopefully not forget) as needed. No action for now, just wanted to keep you in the loop.

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.

None yet

2 participants