matomo-org / device-detector

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
http://devicedetector.net
GNU Lesser General Public License v3.0
2.96k stars 476 forks source link

Error thrown when UserAgent is null #7916

Open angelofan opened 1 week ago

angelofan commented 1 week ago

From RFC7231 User-Agent :

A user agent SHOULD send a User-Agent field in each request unless specifically configured not to do so.

From Microsoft Dotnet Api :

The UserAgent is null when there is no User-Agent header in the request.


The header is a web standard, but we can not guarantee that is present. For example if the call is made with cURL, HttpClient, low level component, ...

The code must be "null-safe", it should not generate an exception if UserAgent is null.

angelofan commented 1 week ago

Although it is possible to avoid passing null in with some pre-judgment, it is easy to forget. For example, every time I use this package for a new project, this problem will occur again when I forget to write some pre-judgment.