feat: Allow to pass a custom User-Agent#99
Merged
teolemon merged 3 commits intoopenfoodfacts:mainfrom Sep 16, 2025
Merged
Conversation
teolemon
approved these changes
Jun 10, 2025
There was a problem hiding this comment.
Pull Request Overview
Adds support for a custom User-Agent header by centralizing HTTP requests and replacing direct URI.open calls.
- Introduce
http_getwrapper that readsOPENFOODFACTS_USER_AGENTfrom the environment - Replace all
URI.openinvocations withOpenfoodfacts.http_get - Bump Ruby version to 3.3.6 in .tool-versions
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/openfoodfacts.rb | Add http_get method with User-Agent header |
| lib/openfoodfacts/product.rb | Replace URI.open with http_get for get, search, and page parsing |
| lib/openfoodfacts/press.rb | Replace URI.open with http_get in items |
| lib/openfoodfacts/mission.rb | Replace URI.open with http_get in all and fetch |
| lib/openfoodfacts/locale.rb | Replace URI.open with http_get in all |
| lib/openfoodfacts/faq.rb | Replace URI.open with http_get in items |
| .tool-versions | Specify Ruby 3.3.6 |
Comments suppressed due to low confidence (3)
lib/openfoodfacts.rb:43
- The new
http_getmethod is not covered by tests. Please add unit or integration tests to verify both successful responses and custom User-Agent behavior.
def http_get(url)
lib/openfoodfacts.rb:43
- [nitpick] Document the
OPENFOODFACTS_USER_AGENTenvironment variable in the README or project docs so users know how to set a custom header.
def http_get(url)
lib/openfoodfacts.rb:44
- Missing
require 'open-uri'in this file: without requiring open-uri,URI.parse(url).openwill be undefined at runtime.
URI.parse(url).open("User-Agent" => ENV.fetch('OPENFOODFACTS_USER_AGENT', nil))
|
VictorGosse
approved these changes
Sep 16, 2025
Member
|
@clavat @VictorGosse ok to merge ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Give the possibility to pass a custom User-Agent to the API calls.
Resolving this issue #88