views:

73

answers:

2

I'm writing a small content server as a web service. There are 2 units - one authenticates the application requesting content and when authentication succeeds, the request is forwarded to the other unit that serves the content.

  • [1] If I want to do this using CGI scripts, is there any equivalent of jsp:forward in CGI?
  • [2] Suppose if forwarding is not possible, the client application shouldn't be able to request the second unit directly. What is the proper way to do this?
A: 

The concept you might be looking for is called HTTP redirect, where the server sends a response to browser's request, telling the browser to fetch a new page from another URL.

CGI can do HTTP redirects just fine just like jsp:forward. You need just to output the right HTTP headers.

You need to return a 302 response code in HTTP headers, and provide location URL where browser should go next. Have your CGI script output these kind of headers:

HTTP/1.1 302 Redirect
Location: http://www.example.org/

These headers tell browser to fetch a page from URL http://www.example.org/ .

Juha Syrjälä
No I'm not looking for redirect. In the case of jsp:forward, the request is internally forwarded within the server, the client is never aware of it. The URL also does not change in the client.
sriramptr
+2  A: 

Another attempt, since you are not after HTTP redirect...

The short answer is: Yes, it is possible.

However, it is highly dependent on the tools you are using. What web server and CGI scripting language you are using?

CGI scripts can do practically anything they want to do, for example they could execute code from other CGI scripts. Thus, they can provide the behavior you are looking for.

CGI (Common Gateway Interface) just describes how a web server starts a CGI script and gives the script input data via environment variables. CGI also describes how the script returns data to web server. That's all.

So if your authorization script wants to delegate some operation to other some script, it is up to that authorization script to implement it somehow. The CGI protocol does not help here.

Juha Syrjälä
+1 for noting that CGI just describes how a script communicates with the server.
R. Bemrose
@Juha+1 Thanks for the clarification
sriramptr