Headers in mod_rewrite vs Java

Oh, the strange things mod_rewrite does!

Headers in mod_rewrite vs Java

Postby Vinod Murthy » Thu Dec 04, 2008 12:01 am

Hi folks,

I have a small java program (excerpted below) which sends a couple of headers along with an HTTP GET request.

Code: Select all
import java.net.*;
import java.io.*;
public class HTTPGetTest
{
  public static void main(String args[]) throws Exception
  {
    int i = -1;
    URL url = new URL("http://myserver.mydomain.com/cgi-bin/printenv");
    HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
    urlConn.setRequestMethod("GET");

    urlConn.setRequestProperty("userid", "myuser");
    urlConn.setRequestProperty("password", "mypassword");

    urlConn.connect();

    if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
        BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

        while ((i = in.read()) != -1)
            System.out.print((char) i);
    }
  }
}


However, the constraint I have is that the actual java program will not have the two lines to set the headers. Can I achieve the exact same effect of these lines using mod_rewrite? I have so far tried -

Code: Select all
RewriteRule /cgi-bin/printenv - [env=userid:myuser,env=password:mypassword,L]


and

Code: Select all
RewriteRule /cgi-bin/printenv - [env=HTTP_userid:myuser,env=HTTP_password:mypassword,L]


But there seems to be a nuance I'm missing - both of these do not seem to set the header the way the the java code does.

I would greatly appreciate any pointers you could give me.

Thanks,
Vinod
Vinod Murthy
 
Posts: 2
Joined: Wed Dec 03, 2008 9:33 pm

Postby richardk » Thu Dec 04, 2008 9:19 am

Is REDIRECT_variable_name being set instead?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Vinod Murthy » Thu Dec 04, 2008 11:40 am

Hi Richard,

Thanks for the reply.

I don't think it is setting REDIRECT_variable_name.

The resource I am accessing is the standard perl-based script which prints a dump of all the variables. Code below -

Code: Select all
#!/usr/bin/perl
print "Content-type: text/plain; charset=iso-8859-1\n\n";
foreach $var (sort(keys(%ENV))) {
    $val = $ENV{$var};
    $val =~ s|\n|\\n|g;
    $val =~ s|"|\\"|g;
    print "${var}=\"${val}\"\n";
}


From this, when I use java to set the variables, the resulting page shows, among other things,


HTTP_PASSWORD="myuser"
HTTP_USERID="mypassword"


With the [env=HTTP_userid:myuser,env=HTTP_password:mypassword,L] rule, I get


HTTP_password="mypassword"
HTTP_userid="myuser"


and with [env=userid:myuser,env=password:mypassword,L] the page shows -


password="mypassword"
userid="myuser"


The problem is coming in because the request is processed by a third party SSO module which accepts the credentials, among other places via header variables. With the java program setting the headers, this is working too. However, with the mod_rewrite approach, the credentials are not found by the SSO module which responds with the form challenge as a result. Only if I pass the credentials some other way am I let in to see that mod_rewrite does seem to set the headers but not in the way that the java code does.

-Vinod
Vinod Murthy
 
Posts: 2
Joined: Wed Dec 03, 2008 9:33 pm

Postby richardk » Thu Dec 04, 2008 2:11 pm

Is the case important?

You might need the PT flag
Code: Select all
RewriteRule /cgi-bin/printenv - [E=HTTP_USERID:myuser,E=HTTP_PASSWORD:mypassword,PT,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 15 guests

cron