Forum Moderators: phranque

Message Too Old, No Replies

determining browser type at apache source level

         

steebu

4:46 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



Hiya,

I'm trying to determine the client type during the URL processing stage of the Apache source code (2.2). According to what I read, HTTP_USER_AGENT doesn't "become" an environment variable until some later time so that CGI and PHP scripts can pick it up.

So ... in $APACHE_SOURCE/server/util.c there's a function ap_unescape_url(). Somewhere in this function I need to determine the browser type, but attempting the usual

foo = getenv( "HTTP_USER_AGENT" );

returns NULL. I guess that's because that environment variable hasn't been set at this stage of the processing? In fact, I know it hasn't - it returns NULL every time. So how does one determine the browser type at this point of the processing?

Thanks!

coopster

4:58 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, steebu.

Perhaps Apache's BrowserMatch [httpd.apache.org] directive will help?

steebu

5:34 pm on Mar 13, 2006 (gmt 0)

10+ Year Member



Hmm. It doesn't seem to be working. Here's what I've tried:

1. in httpd.conf I've added

BrowserMatch ^Mozilla MOZILLA_ACCESS=TRUE

(I did the requisite things for setenvif after reading the apache documentation and rebuilt httpd).

2. in util.c I added the lines

p = getenv( "MOZILLA_ACCESS" );
fprintf( fp, "value is %s\n", p );

3. I then accessed URLs using firefox thusly:

[myserver.com...]

so that the block that contains the above code would execute. When I look at the file pointed to by fp it just says

value is (null)

So it looks like the environment variable isn't getting set. I peeked at the acces_log and sure enough, the log says that the client is

"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.7.12) Gecko/20050915 Firefox/1.0.7"

What am I missing?

steebu

9:10 pm on Mar 13, 2006 (gmt 0)

10+ Year Member



OK, I realized 2 things. The server directives mentioned above don't work at the source code/URI processing level.

So ... gritting my teeth, I dug into the code and modified util.c so that it got a pointer to the request_rec structure and did the following:

char *p;

p = apr_table_get(r->headers_in, "User-Agent" );

if( strcmp( p, "MyClient" == 0 )
return OK;
else
return HTTP_NOT_FOUND;