You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl-cvs@perl.apache.org by ri...@apache.org on 2003/03/03 19:38:47 UTC

cvs commit: embperl Changes.pod Embperl.pod EmbperlD.pod epmain.c test.pl

richter     2003/03/03 10:38:47

  Modified:    .        Changes.pod Embperl.pod EmbperlD.pod epmain.c
                        test.pl
  Log:
  set status code on redirect
  
  Revision  Changes    Path
  1.204     +2 -0      embperl/Changes.pod
  
  Index: Changes.pod
  ===================================================================
  RCS file: /home/cvs/embperl/Changes.pod,v
  retrieving revision 1.203
  retrieving revision 1.204
  diff -u -r1.203 -r1.204
  --- Changes.pod	27 Feb 2003 07:05:31 -0000	1.203
  +++ Changes.pod	3 Mar 2003 18:38:46 -0000	1.204
  @@ -69,6 +69,8 @@
      - Embperl compiles and tests now correctly if mod_perl installed
        under Apache2 namespace.
      - Added tests for epform and subreq.
  +   - Added patch from David Hull, which let you specify the status-code
  +     when doing a redirect via %http_headers_out.
   
   =head1 2.0b8  (BETA)  25. Juni 2002
   
  
  
  
  1.81      +9 -2      embperl/Embperl.pod
  
  Index: Embperl.pod
  ===================================================================
  RCS file: /home/cvs/embperl/Embperl.pod,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- Embperl.pod	22 Oct 2002 05:29:04 -0000	1.80
  +++ Embperl.pod	3 Mar 2003 18:38:46 -0000	1.81
  @@ -843,12 +843,19 @@
   
   =head2 %http_headers_out (only 1.2b10 and above)
   
  -You can put any http headers you want to send into this hash. If you set a location header,
  +You can put any http headers you want to send into this hash. 
  +
  +If you set a location header,
   Embperl will automaticly set the status to 301 (Redirect). Example:
   
     [- $http_headers_out{'Location'} = "http://www.ecos.de/embperl/" -]
   
  -Starting with version 1.3.2 all headers with the exception "Location" and 
  +however, it is possible to specify a two element array for Location, the second
  +element of which gives the desired HTTP status:
  +
  +  [- $http_headers_out{Location} = [ "http://www.ecos.de/embperl/", 303 ]; -]
  +
  +Starting with version 1.3.2 all headers with the exception of
   "Content-Type" can take multiple values.
   For instance, if you wanted to set two cookies, you can proceed as follows:
   
  
  
  
  1.53      +6 -1      embperl/EmbperlD.pod
  
  Index: EmbperlD.pod
  ===================================================================
  RCS file: /home/cvs/embperl/EmbperlD.pod,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- EmbperlD.pod	22 Oct 2002 05:29:04 -0000	1.52
  +++ EmbperlD.pod	3 Mar 2003 18:38:46 -0000	1.53
  @@ -812,12 +812,17 @@
   =head2 %http_headers_out (ab 1.2b10)
   
   Dieser Hash erm�glicht es HTTP Header anzugeben, die I<Embperl> vor dem Dokument senden soll.
  +
   Ist ein "Location" Header angegeben, setzt I<Embperl> den Status automatisch auf 301. Beispiel:
   
     [- $http_headers_out{'Location'} = "http://www.ecos.de/embperl/" -]
   
  +Wird ein Array als Location angeben, gibt das zweite Element den Status Code an:
  +
  +  [- $http_headers_out{Location} = [ "http://www.ecos.de/embperl/", 303 ]; -]
  +
   
  -Ab 1.3.2 k�nnen alle HTTP Header (au�er "Location" und "Content-Type") auch 
  +Ab 1.3.2 k�nnen alle HTTP Header (au�er "Content-Type") auch 
   mehrere Werte erhalten. Um z.B. mehrere Cookie zu setzen, kann man folgendes schreiben:
   
   
  
  
  
  1.122     +25 -7     embperl/epmain.c
  
  Index: epmain.c
  ===================================================================
  RCS file: /home/cvs/embperl/epmain.c,v
  retrieving revision 1.121
  retrieving revision 1.122
  diff -u -r1.121 -r1.122
  --- epmain.c	15 Feb 2003 20:46:31 -0000	1.121
  +++ epmain.c	3 Mar 2003 18:38:46 -0000	1.122
  @@ -837,8 +837,11 @@
   	/* loc = 0  =>  no location header found
   	 * loc = 1  =>  location header found
   	 * loc = 2  =>  location header + value found
  +         * loc = 3  =>  location header + value + status found
   	 */
    	I32	loc;
  +        I32 loc_status = 301;
  +
   
   	hv_iterinit (r -> pThread -> pHeaderHash) ;
   	while ((pEntry = hv_iternext (r -> pThread -> pHeaderHash)))
  @@ -877,14 +880,18 @@
    		    for (i = 0; i <= len; i++) 
    			{
    			svp = av_fetch(arr, i, 0);
  +                        if (loc == 2)
  +                             {
  +                             loc = 3;
  +                             loc_status = SvIV(*svp);
  +                             break;
  +                             }
  +
    			p = SvPV(*svp, ldummy);
    			apr_table_add( r->pApacheReq->headers_out, apr_pstrdup(r->pApacheReq->pool, pKey),
    				   apr_pstrdup(r->pApacheReq->pool, p ) );
    			if (loc == 1) 
  -			    {
   			    loc = 2;
  -			    break;
  - 			    }
   			}
    		    } 
    		else 
  @@ -894,7 +901,7 @@
   		    if (loc == 1) loc = 2;
   		    }
   
  -		if (loc == 2) r->pApacheReq->status = 301;
  +		if (loc >= 2) r->pApacheReq->status = loc_status;
   		}
   	    }
   
  @@ -936,6 +943,11 @@
   	I32    l ;
   	char * pContentType = "text/html";
           STRLEN ldummy ;
  +        /* loc = 0  =>  no location header found
  +        * loc = 1  =>  location header found
  +        */
  +        I32 loc;
  +
   
   	r -> Component.pOutput -> nMarker = 0 ; /* output directly */
   
  @@ -944,10 +956,14 @@
   	    {
   	    pKey     = hv_iterkey (pEntry, &l) ;
   	    pHeader  = hv_iterval (r -> pThread -> pHeaderHash, pEntry) ;
  +            loc = 0;
   
   	    if (pHeader && pKey)
   		{			    
  - 		if (SvROK(pHeader)  && SvTYPE(SvRV(pHeader)) == SVt_PVAV ) 
  + 		if (stricmp (pKey, "location") == 0)
  +                    loc = 1;
  +
  +                if (SvROK(pHeader)  && SvTYPE(SvRV(pHeader)) == SVt_PVAV ) 
    		    {
    		    AV * arr = (AV *)SvRV(pHeader);
    		    I32 len = av_len(arr);
  @@ -963,7 +979,9 @@
   			oputs (r, "\n") ;
   			if (r -> Component.Config.bDebug & dbgHeadersIn)
                   	    lprintf (r -> pApp,   "[%d]HDR:  %s: %s\n", r -> pThread -> nPid, pKey, p) ; 
  -			}
  +			if (loc == 1) 
  +                            break;
  +                        }
    		    } 
   		else
   		    {				    
  
  
  
  1.127     +2 -1      embperl/test.pl
  
  Index: test.pl
  ===================================================================
  RCS file: /home/cvs/embperl/test.pl,v
  retrieving revision 1.126
  retrieving revision 1.127
  diff -u -r1.126 -r1.127
  --- test.pl	27 Feb 2003 07:05:32 -0000	1.126
  +++ test.pl	3 Mar 2003 18:38:46 -0000	1.127
  @@ -984,6 +984,7 @@
           },
       'subreq.htm' => { 
           'version'    => 2,
  +        'modperl'    => 1,
           'condition'  => '$MP2',
           },
   ) ;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-cvs-help@perl.apache.org