gshutler / useragent

HTTP User Agent parser
MIT License
179 stars 159 forks source link

Permit changing default user agent #37

Open allspiritseve opened 8 years ago

gshutler commented 8 years ago

What is the use case for this change?

allspiritseve commented 8 years ago

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.

gshutler commented 8 years ago

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.

allspiritseve commented 8 years ago

@gshutler sounds good to me!