useragent icon indicating copy to clipboard operation
useragent copied to clipboard

Permit changing default user agent

Open allspiritseve opened this issue 9 years ago • 4 comments

allspiritseve avatar Jun 06 '16 17:06 allspiritseve

What is the use case for this change?

gshutler avatar Sep 05 '16 09:09 gshutler

It can be useful in some situations to know when a user agent can't be parsed correctly. My preference is to return an empty string instead of Mozilla/4.0 (compatible). As not everyone has this preference, it makes sense to allow a configurable default rather than having to monkeypatch UserAgent::DEFAULT_USER_AGENT.

allspiritseve avatar Sep 05 '16 16:09 allspiritseve

I can see something along those lines being useful. For example, if returning nil for a user agent that couldn't be detected you could do something like:

if ua = UserAgent.parse(user_agent)
  # Something based on known UA
else
  # Fallback for unknown UA
end

I could also see a parse! variant that raised an error if the UA was unknown being useful for similar patterns.

WDYT? Yours is a non-breaking change but I'm already considering a major version for #40 so I could include a breaking change along these lines with that into a major version.

gshutler avatar Sep 05 '16 20:09 gshutler

@gshutler sounds good to me!

allspiritseve avatar Sep 07 '16 18:09 allspiritseve