[AWS] cookie
David Marceau
davidmarceau@sympatico.ca
Thu, 21 Nov 2002 16:21:10 -0500
> Michal Morawski wrote:
>
> I have the following problem:
>
> Other server sent a cookie to client, then redirects cliebt to
> AWS. Then AWS should read the value of this cookie and behave
> properly.
>
> Can I do it in simply?
>
> Micha? Morawski
>
>
First off AWS has an internal cookie handling facility provide via the
Session Handling see Section 3.3 of the AWS documentation.
I found this at:
http://www.le-berre.com/nsapi/nsapi.htm
That said you are talking about maybe communicating an apache or
netscape web server which redirects a client along with a special
cookie.
HTTP Redirection
How to redirect ?
/*IE 4.0 could have problem with HTTP 302 answer which
contains a body. Corrected in NES 3.6 */
param_free( pblock_remove( "Location", rq->srvhdrs ) );
pblock_nvinsert( "Location", pszTo, rq->srvhdrs );
protocol_status( sn, rq, PROTOCOL_REDIRECT, NULL );
protocol_start_response( sn, rq ); return REQ_ABORTED;
**************
How to redirect with a cookie ?
pblock_nvinsert( "Set-cookie", "Cook1=ROAD_RUNNER;
path=/; domain=.hp.com", rq->srvhdrs );
param_free( pblock_remove( "Location", rq->srvhdrs ) );
pblock_nvinsert( "Location", pszTo, rq->srvhdrs );
protocol_status( sn, rq, PROTOCOL_REDIRECT, NULL );
protocol_start_response( sn, rq );
return REQ_ABORTED;
How to show to user the URL that I am redirecting the browser to
?
/* This tells the browser (well, NS Navigator at least)
to tell the user where
he's been redirected to, but without him having to
click a link */
protocol_status(sn,rq,PROTOCOL_REDIRECT,NULL);
/* We know where we're going, so we can force the type,
etc. */
param_free(pblock_remove("content-type", rq->srvhdrs));
pblock_nvinsert("content-type", "text/html",
rq->srvhdrs);
param_free(pblock_remove("path", rq->vars));
pblock_nvinsert("path", "/path/to/redirect.html",
rq->vars);
/* This allows the user to know where he went instead
of what he wanted */
param_free(pblock_remove("Location", rq->srvhdrs));
pblock_nvinsert("Location",
"http://myserver/redirect.html", rq->srvhdrs);
How to redirect on a POST?
/* This function redirects POSTs to the script
"spam.cgi" to the
other function "echo.cgi". It doesn't tell the client
it's doing so, though. */
NSAPI_PUBLIC int cgi_redirect(pblock *pb,Session
*sn,Request *rq) {
FuncPtr F;
char *old = pblock_findval("uri",rq->reqpb);
char *find;
find = strstr(old,"spam.cgi");
if (find != NULL) {
param_free(pblock_remove("path",rq->vars));
pblock_nvinsert("path","/serverpath/cgi-bin/echo.cgi",rq->vars);
F = func_find("send-cgi");
return (F) (pb,sn,rq);
} else {
return REQ_NOACTION;
}
}
How to redirect with SSL?
/*In some case (IE) redirection with SSL on could
failed,
to avoid this Set the content-length header*/
NSAPI_PUBLIC int cgi_redirect(pblock *pb,Session
*sn,Request *rq) {
pblock_nvinsert ("set-cookie", auth_cookie,
rq->srvhdrs);
pblock_nvinsert ("Location", redirect_url,
rq->srvhdrs);
pblock_nvinsert ("Content-Length", "221",
rq->srvhdrs);
protocol_status (sn, rq, PROTOCOL_REDIRECT, "Moved
Temporarily");
protocol_start_response (sn, rq);
return REQ_ABORTED;}
Samples
NTrans by Josh Andrews, jrandrew@pepperdine.edu