Quick Question About (Working) Request Header Parser Microservice

My request header microservice is working, but I am sort of worried that the way I’m parsing the header is not great. Here’s the relevant bit of code:

  let ipaddress = req.headers['x-forwarded-for']
    , language = req.headers['accept-language'].split(',')[0]
    , software = req.headers['user-agent'].split(/[()]+/)[1]

Not worried about the IP address, but for language and software I’m just splitting strings to isolate the bit I want and I’m worried that there are circumstances where that strategy will break. Can anyone confirm that it will or won’t?

Yes, there is a potential problem with your strategy. Hint: What happens if you don’t receive a string value from req.headers[‘user-agent’]? Try creating an object, accessing a property that does’nt exist and splitting that value.

To be honest, I’m doing pretty much the same thing and I guess that bit isn’t really making or breaking that project. Reggie has a point, that it might be a good idea to have default values for when (for some weird reason) you don’t receive the correct data in the request. Additionally, you could incorporate some npm packages that offer exactly that functionality if you wanted it that badly. But in my opinion your solution is fine and dandy.