You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by mx...@apache.org on 2014/12/18 00:02:52 UTC

svn commit: r1646361 - in /tcl/rivet/trunk: ChangeLog rivet/rivet-tcl/redirect.tcl src/experimental/rivetCore.c

Author: mxmanghi
Date: Wed Dec 17 23:02:52 2014
New Revision: 1646361

URL: http://svn.apache.org/r1646361
Log:
    * src/experimental/rivetCore.c: new 'headers sent' introspection command to
    understand whether headers have been sent already
    * rivet/rivet-tcl/redirect.tcl: command didn't fail with a meaningful message
    if headers had been sent already because of ::rivet::no_body that blocks output
    to the socket. The procedure now returns an error if ::rivet::headers sent 
    returns 1


Modified:
    tcl/rivet/trunk/ChangeLog
    tcl/rivet/trunk/rivet/rivet-tcl/redirect.tcl
    tcl/rivet/trunk/src/experimental/rivetCore.c

Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1646361&r1=1646360&r2=1646361&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Wed Dec 17 23:02:52 2014
@@ -1,3 +1,11 @@
+2014-12-17 Massimo Manghi <mx...@apache.org>
+    * src/experimental/rivetCore.c: new 'headers sent' introspection command to
+    understand whether headers have been sent already
+    * rivet/rivet-tcl/redirect.tcl: command didn't fail with a meaningful message
+    if headers had been sent already because of ::rivet::no_body that blocks output
+    to the socket. The procedure now returns an error if ::rivet::headers sent 
+    returns 1
+
 2014-12-16 Massimo Manghi <mx...@apache.org>
     * configure.ac: bumping version number to 2.3.0
     * rivet/init.tcl: recreated by automake

Modified: tcl/rivet/trunk/rivet/rivet-tcl/redirect.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/rivet/rivet-tcl/redirect.tcl?rev=1646361&r1=1646360&r2=1646361&view=diff
==============================================================================
--- tcl/rivet/trunk/rivet/rivet-tcl/redirect.tcl (original)
+++ tcl/rivet/trunk/rivet/rivet-tcl/redirect.tcl Wed Dec 17 23:02:52 2014
@@ -15,11 +15,19 @@ namespace eval ::rivet {
 
     proc ::rivet::redirect {url {permanent 0}} {
 
+        if {[::rivet::headers sent]} {
+
+            return  -code error \
+                    -errorcode headers_already_sent \
+                    -errorinfo "Impossible to redirect: headers already sent"
+        }
+
         ::rivet::no_body ; ## don’t output anything on a redirect
         ::rivet::headers set Location $url
         ::rivet::headers numeric [expr {$permanent ? "301" : "302"}]
         ::rivet::abort_page ; ## stop any further processing
 
+        return -error ok 
     }
 
 }

Modified: tcl/rivet/trunk/src/experimental/rivetCore.c
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/src/experimental/rivetCore.c?rev=1646361&r1=1646360&r2=1646361&view=diff
==============================================================================
--- tcl/rivet/trunk/src/experimental/rivetCore.c (original)
+++ tcl/rivet/trunk/src/experimental/rivetCore.c Wed Dec 17 23:02:52 2014
@@ -361,6 +361,17 @@ TCL_CMD_HEADER( Rivet_Headers )
         Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");
         return TCL_ERROR;
     }
+
+    opt = Tcl_GetStringFromObj(objv[1], NULL);
+
+    /* Basic introspection returning the values of the headers_printed flag */
+
+    if (!strcmp("sent",opt))
+    {
+        Tcl_SetObjResult(interp, Tcl_NewIntObj(globals->req->headers_printed));
+        return TCL_OK;
+    }
+
     if (globals->req->headers_printed != 0)
     {
         Tcl_AddObjErrorInfo(interp,



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