home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / nastroje / d3456 / KBMWABD.ZIP / WABD_HTMLResponse.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-09  |  3KB  |  86 lines

  1. unit WABD_HTMLResponse;
  2.  
  3. interface
  4.  
  5. uses SysUtils,WABD_Request,WABD_Response,WABD_Cookies,WABD_Utils,ISAPI2;
  6.  
  7. type
  8.    TWABD_CustomHTMLResponse = class(TWABD_CustomResponse)
  9.    protected
  10.       function FormatResponse:string; override;
  11.    end;
  12.  
  13. implementation
  14.  
  15. function TWABD_CustomHTMLResponse.FormatResponse:string;
  16. var
  17.    i:integer;
  18.    fn:string;
  19.    cookiestr:string;
  20.    cookie:TWABD_Cookie;
  21.    s:string;
  22. const
  23.    CR = #13#10;
  24. begin
  25.      // Check if to redirect to another location.
  26.      if (Status=WABD_STATUS_OK) and (Location<>'') then Status:=WABD_STATUS_REDIRECT;
  27.      if (Status=WABD_STATUS_REDIRECT) and (Location='') then Status:=WABD_STATUS_OK;
  28.  
  29.      // Build cookie list.
  30.      cookiestr:='';
  31.      if Assigned(Cookies) then
  32.         for i:=0 to Cookies.count-1 do
  33.         begin
  34.              cookie:=TWABD_Cookie(Cookies.Items[i]);
  35.              if Length(Trim(cookie.Name))>0 then
  36.                     cookiestr:=cookiestr+'Set-Cookie: '+cookie.HeaderValue+';'+CR;
  37.         end;
  38.  
  39.      // Format HTTP.
  40.      case Status of
  41.         WABD_STATUS_OK:
  42.                  begin
  43.                     if ContentDesc<>'' then
  44.                         fn:='Content-Disposition: attachment;filename='+ContentDesc+CR
  45.                     else
  46.                         fn:='';
  47.                     s:=Response.Text;
  48.                     Result:='HTTP/1.0 200 OK'+CR+
  49.                             cookiestr+
  50.                             fn+
  51.                             'Content-Type: '+ContentType+CR+
  52.                             'Content-Length: '+inttostr(length(s))+CR+
  53.                             Header.Text+
  54.                             'Content:'+CR+CR+s;
  55.                  end;
  56.         WABD_STATUS_AUTH:
  57.                  begin
  58.                     Result:='HTTP/1.0 401 Unauthorized'+CR+
  59.                             'WWW-authenticate: Basic realm="'+ContentDesc+'"'+CR+
  60.                             cookiestr+
  61.                             'Content-type: text/plain'+CR+
  62.                             'Content-Length: 14'+CR+
  63.                             Header.Text+
  64.                             'Content:'+CR+CR+'Access denied.';
  65.                  end;
  66.         WABD_STATUS_REDIRECT:
  67.                  begin
  68.                     if ContentDesc<>'' then
  69.                         fn:='Content-Disposition: attachment;filename="'+ContentDesc+'"'+CR
  70.                     else
  71.                         fn:='';
  72.                     Result:='HTTP/1.0 302 Moved temporarily'+CR+
  73.                             cookiestr+
  74.                             'Location: '+Location+CR+
  75. //                            'Content-Type: '+ContentType+CR+
  76. //                            'Content-Length: '+inttostr(length(Data))+CR+
  77. //                            fn+
  78. //                            'Content:'+CR+CR+Data;
  79.                             Header.Text+
  80.                             CR+CR;
  81.                  end;
  82.      end;
  83. end;
  84.  
  85. end.
  86.