Forum Discussion

Kimihito's avatar
Kimihito
Icon for Employee rankEmployee
May 26, 2014

Linerate : HTTP API request.headers User-Agent property

Hello,

I am trying to parse HTTP client request header and match 'User-Agent', 'Host' etc. I can not access User-Agent while I can access Host and Accept header. Pls see below.

// Play with request headers
var myheaders = servReq.headers;
console.log('This request has those headers');
console.log(myheaders);
// Access each properties
console.log(myheaders.UserAgent);       // This results undefined
console.log(myheaders.User_Agent);      // This results undefined
console.log(myheaders.Useragent);       // This results undefined
console.log(myheaders.useragent);       // This results undefined
console.log(myheaders.Accept);      // This works
console.log(myheaders.Host);        // This works

tail -f /var/log/controller-messages May 26 09:41:17 LROS: This request has those headers May 26 09:41:17 LROS: { 'User-Agent': 'curl/7.26.0', May 26 09:41:17 LROS: Accept: '/', May 26 09:41:17 LROS: Host: '172.16.0.1' } May 26 09:41:17 LROS: undefined May 26 09:41:17 LROS:last message repeated 3 times May 26 09:41:17 LROS: / May 26 09:41:17 LROS: 172.16.0.1

How can I access User-Agent to match ?

What I noticed with the console.log is that the property name appears with '' only for User-Agent. Accept and Host do not have ''.

The LROS version is 2.3.1 as below.

myLinerate show version F5 Networks LROS Version 2.3.1 Copyright (c) 2009-2014 F5 Networks, Inc.

RELEASE IMAGE (7fa1f91/4879ceb/b35a310) Built Mon May 05 15:25:08 MDT 2014 by builder@bahamas:/build/bahamas/jenkins/workspace/2.3.1/lrs_release Node API compatibility version: 0.8.3 LineRate Scripting engine version: 0.2.0

myLinerate uptime is 4 days, 3 hours, 49 minutes

BR Kimihito.

2 Replies

  • Ashok_Mudukutor's avatar
    Ashok_Mudukutor
    Historic F5 Account

    Note that header keys in the server-request object are lower-case. To view the 'User-Agent' header, you could do something like: console.log(servReq.headers['user-agent']);

     

    • Kimihito's avatar
      Kimihito
      Icon for Employee rankEmployee
      Thanks Ashok. It is working now. B.R Kimihito