Forum Moderators: phranque
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!
Perhaps Apache's BrowserMatch [httpd.apache.org] directive will help?
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?
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;