Hi,

I discovered a bug in my code for On Web Connection in 4D 2003. This bug accounts for the refresh problem reported by Robert Ernens, and perhaps the redirect problem reported by Steve Alex.

This is what On Web Connection should look like:

  `DB: On Web Connection
  `
  `Part of Active4D, the ultimate 4D web environment
  `Copyright © 2001-2005 Aparajita Fishman, All Rights Reserved
  `
  `$Id: On%20Web%20Connection.4d 412 2005-09-23 15:04:13Z aparajita $

C_TEXT($1;$2;$3;A4D_RemoteAddr;$4;$inHostAddr;$5;$6)

If (◊A4D_IsWebServer)
`Uncomment the next line and the End if at the end of this method to use the hook
      `If (A4D_PreOnWebConnectionHook ($1;$2;$3))

    A4D_RemoteAddr:=$3
    $inHostAddr:=$4

    MESSAGES OFF
    READ ONLY(*)

      `Always do this!
    C_LONGINT(A4D_Error)
    A4D_Error:=0
    ON ERR CALL("A4D_ErrorHandler")

    C_BLOB(A4D_Response)
    SET BLOB SIZE(A4D_Response;0)
    C_LONGINT($status)
    $status:=HTTP Status OK
    C_STRING(255;$contentType)
    $contentType:=""
    ARRAY TEXT(A4D_ResponseHeaderNames;0)
    ARRAY TEXT(A4D_ResponseHeaderValues;0)

    ARRAY TEXT($requestInfo;4)
    $requestInfo{A4D Request Remote Addr }:=A4D_RemoteAddr
    $requestInfo{A4D Request Host Addr }:=◊A4D_HostAddr

    C_BOOLEAN($secure)
    $secure:=Secured Web connection

    If ($secure)
        $requestInfo{A4D Request Host Port }:="443"
        $requestInfo{A4D Request Secure }:="1"
    Else
        $requestInfo{A4D Request Host Port }:=◊A4D_HostPort
        $requestInfo{A4D Request Secure }:="0"
    End if

    ARRAY TEXT($varNames;0)
    ARRAY TEXT($varValues;0)
    GET WEB FORM VARIABLES($varNames;$varValues)

$status:=A4D Execute 4D request ($2;$varNames;$varValues; $requestInfo;A4D_ResponseHeaderNames;A4D_ResponseHeaderValues;A4D_Respon se)

      `Critical that transactions are cleaned up
    If (In transaction)
        CANCEL TRANSACTION
    End if

    If (($status>0) | ($status=A4D License Timed Out ))
`Uncomment and join together the next two lines to use the post-execute hook
          `A4D_PostExecuteHook (->A4D_ResponseHeaderNames;
          `->A4D_ResponseHeaderValues;->A4D_Response)

        C_LONGINT($i)

`----------------------------------------------------------------------- ---
          `  4D 2003 code
          `
` In 4D 2004+, remove this section and uncomment the 4D 2004 section below `----------------------------------------------------------------------- ---

        $i:=Find in array(A4D_ResponseHeaderNames;"Content-Type")

        If ($i>0)
            $contentType:=A4D_ResponseHeaderValues{$i}
        Else
            $contentType:="text/html"
        End if

        C_TEXT($header)
$header:=A4D_ResponseHeaderValues{1}+" "+A4D_ResponseHeaderValues{2}+"\r\n"

          `Skip X-VERSION and X-STATUS
        For ($i;3;Size of array(A4D_ResponseHeaderNames))
$header:=$header+A4D_ResponseHeaderNames{$i}+": "+A4D_ResponseHeaderValues{$i}+"\r\n"
        End for

        SET HTTP HEADER($header)

        If ($contentType="text/html")
            A4D STRIP 4D TAGS (A4D_Response)
        End if

        SEND HTML BLOB(A4D_Response;$contentType;True)

`----------------------------------------------------------------------- ---
          ` End of 4D 2003 code
`----------------------------------------------------------------------- ---


`----------------------------------------------------------------------- ---
          `  4D 2004+ code
`----------------------------------------------------------------------- ---

          `C_BLOB($response)
`TEXT TO BLOB(A4D_ResponseHeaderValues{1}+" "+A4D_ResponseHeaderValues{2}+"\r\n";$response;Text without length )
          `
          ``Skip X-VERSION and X-STATUS
          `For ($i;3;Size of array(A4D_ResponseHeaderNames))
`TEXT TO BLOB(A4D_ResponseHeaderNames{$i}+": "+A4D_ResponseHeaderValues{$i}+"\r\n";$response;Text without length ;*)
          `End for
          `
` `Need an extra CRLF after the headers to separate them from the body
          `TEXT TO BLOB("\r\n";$response;Text without length ;*)
          `
`COPY BLOB(A4D_Response;$response;0;BLOB size ($response);BLOB size(A4D_Response))
          `SET BLOB SIZE(A4D_Response;0)
          `SEND HTTP RAW DATA($response)

`----------------------------------------------------------------------- ---
          ` End of 4D 2004+ code
`----------------------------------------------------------------------- ---
    End if

    ARRAY TEXT($varNames;0)
    ARRAY TEXT($varValues;0)
    ARRAY TEXT(A4D_ResponseHeaderNames;0)
    ARRAY TEXT(A4D_ResponseHeaderValues;0)
    SET BLOB SIZE(A4D_Response;0)

      `Uncomment the next line to use PreOnWebConnectionHook
      `End if
End if


Hope this clears up the problems.

Regards,

   Aparajita
   www.aparajitaworld.com

   "If you dare to fail, you are bound to succeed."
   - Sri Chinmoy   |   www.srichinmoylibrary.com


_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Reply via email to