File: n_cst_httpheader.sru
Size: 3402
Date: Sat, 08 Dec 2007 15:38:25 +0100
$PBExportHeader$n_cst_httpheader.sru
$PBExportComments$HTTP Header
forward
global type n_cst_httpheader from nonvisualobject
end type
end forward

global type n_cst_httpheader from nonvisualobject
end type
global n_cst_httpheader n_cst_httpheader

type variables
string is_contenttype = "text/html;charset=iso-8859-1"
string is_headerfield[]
string is_headervalue[]
string is_cookiename[]
string is_cookievalue[]
string is_path[]
string is_redirectlocation
long il_httpreturncode

boolean ib_IsIIS=false
end variables

forward prototypes
public function string of_gethttpheader ()
public subroutine of_setredirect (string as_location)
public subroutine of_addheader (string as_field, string as_value)
public function long of_setcookie (string as_cookiename, string as_cookievalue)
public function boolean of_isredirected ()
public subroutine of_setcontenttype (string as_contenttype)
end prototypes

public function string of_gethttpheader ();
string ls_httpheader = ""
long ll_i
long ll_ub

if of_isredirected( )  then
   if ib_isIIS then
      ls_httpheader = "HTTP/1.0 302 Redirect~r~nLocation: " + "http://" + cgienv.of_getenv( 'SERVER_NAME')  + is_redirectlocation + "~r~n"
   else
      ls_httpheader = "Status: 302 Moved Permanently~r~nLocation: " + is_redirectlocation + "~r~n"
   end if
else
   if Upperbound ( is_headerfield ) > 0 then
   
      ll_ub = Upperbound ( is_headerfield )
      
      for ll_i = 1 to ll_ub
         if Len ( is_headerfield [ll_i] ) > 0 then
            if Len ( is_headervalue [ll_i] ) > 0 then 
               ls_httpheader += is_headerfield [ll_i] +": " + is_headervalue[ll_i] + "~r~n" 
            else
               ls_httpheader += is_headerfield [ll_i] +": ~r~n" 
            end if
         end if
            
      next

   end if
end if

if Upperbound ( is_cookiename ) > 0 then
   ll_ub = Upperbound ( is_cookiename )
   
   for ll_i = 1 to ll_ub 
      if Len ( is_cookiename [ll_i] ) > 0 and Len ( is_cookievalue [ll_i] ) > 0 then &
         ls_httpheader += "Set-Cookie: " + is_cookiename[ll_i] + "=" + is_cookievalue[ll_i] + "; path=/;~r~n" 
   next
end if

if Len ( is_contenttype ) > 0 and not of_isredirected( ) then ls_httpheader += "Content-Type: " + is_contenttype 

ls_httpheader += "~r~n~r~n"
   
return ls_httpheader

end function

public subroutine of_setredirect (string as_location);is_redirectlocation = as_location
return
end subroutine

public subroutine of_addheader (string as_field, string as_value);
long ll_new
ll_new = Upperbound ( is_headerfield []) + 1
is_headerfield [ll_new] = as_field
is_headervalue [ll_new] = as_value

return
end subroutine

public function long of_setcookie (string as_cookiename, string as_cookievalue);
long ll_new

if Len ( as_cookiename ) > 0 and Len ( as_cookievalue ) > 0 then
   ll_new = UpperBound ( This.is_cookiename[] ) + 1
   This.is_cookiename[ll_new] = as_cookiename
   This.is_cookievalue[ll_new]   = as_cookievalue
   return 1
else
   return 0
end if   
end function

public function boolean of_isredirected ();
if len ( is_redirectlocation ) > 0 then return TRUE

return FALSE 

end function

public subroutine of_setcontenttype (string as_contenttype); is_contenttype = as_contenttype
return 
end subroutine

on n_cst_httpheader.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_cst_httpheader.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on