httpx icon indicating copy to clipboard operation
httpx copied to clipboard

Add An Importable `default_user_agent` Function

Open MichaelYochpaz opened this issue 1 year ago • 0 comments
trafficstars

Summary

This PR adds a default_user_agent function (corresponding to requests.utils.default_user_agent) and allows it to be imported using from httpx import default_user_agent to allow different projects to check what user-agent should be expected by default from the clients they're using (for unit-tests, for example).

This value existed as a constant variable named USER_AGENT (accessible only using httpx._client.USER_AGENT) which I didn't necessarily have to convert to a function, but I thought it would be better as a function both because it will be implemented similarly to requests, and because it will allow more flexibility in the future, in case it will need to be dynamically calculated (changing it to a function from a variable if needed in the future will break backwards compatibility).

Don't think this change requires any unit-tests or docs to be updated (didn't find any matching section), but if you think it does, let me know and I'll try to add those.

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [ ] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [ ] I've updated the documentation accordingly.

MichaelYochpaz avatar Jun 20 '24 18:06 MichaelYochpaz