home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / UWeb / Classes / WebResponse.uc < prev    next >
Text File  |  2003-10-22  |  3KB  |  99 lines

  1. class WebResponse extends Object
  2.     native
  3.     noexport;
  4.  
  5. var private native const int ReplacementMap[5];    // TMap<FString, FString>!
  6. var const config string IncludePath;
  7. var WebConnection Connection;
  8. var bool bSentText; // used to warn headers already sent
  9. var bool bSentResponse;
  10.  
  11. // uhtm including
  12. native final function Subst(string Variable, string Value, optional bool bClear);
  13. native final function ClearSubst();
  14. native final function IncludeUHTM(string Filename);
  15. native final function IncludeBinaryFile(string Filename);
  16.  
  17. event SendText(string Text, optional bool bNoCRLF)
  18. {
  19.     if(!bSentText)
  20.     {
  21.         SendStandardHeaders();
  22.         bSentText = True;
  23.     }    
  24.  
  25.     if(bNoCRLF)
  26.         Connection.SendText(Text);
  27.     else
  28.         Connection.SendText(Text$Chr(13)$Chr(10));
  29. }
  30.  
  31. event SendBinary(int Count, byte B[255])
  32. {
  33.     Connection.SendBinary(Count, B);
  34. }
  35.  
  36. function FailAuthentication(string Realm)
  37. {
  38.     HTTPError(401, Realm);
  39. }
  40.  
  41. function HTTPResponse(string Header)
  42. {
  43.     HTTPHeader(Header);
  44.     bSentResponse = True;
  45. }
  46.  
  47. function HTTPHeader(string Header)
  48. {
  49.     if(bSentText)
  50.         Log("Can't send headers - already called SendText()");
  51.  
  52.     Connection.SendText(Header$Chr(13)$Chr(10));
  53. }
  54.  
  55. function HTTPError(int ErrorNum, optional string Data)
  56. {
  57.     switch(ErrorNum)
  58.     {
  59.     case 400:
  60.         HTTPResponse("HTTP/1.1 400 Bad Request");
  61.         SendText("<TITLE>400 Bad Request</TITLE><H1>400 Bad Request</H1>If you got this error from a standard web browser, please mail jack@epicgames.com and submit a bug report.");
  62.         break;
  63.     case 401:
  64.         HTTPResponse("HTTP/1.1 401 Unauthorized");
  65.         HTTPHeader("WWW-authenticate: basic realm=\""$Data$"\"");
  66.         SendText("<TITLE>401 Unauthorized</TITLE><H1>401 Unauthorized</H1>");
  67.         break;
  68.     case 404:
  69.         HTTPResponse("HTTP/1.1 404 Object Not Found");
  70.         SendText("<TITLE>404 File Not Found</TITLE><H1>404 File Not Found</H1>The URL you requested was not found.");
  71.         break;
  72.     default:
  73.         break;
  74.     }
  75. }
  76.  
  77. function SendStandardHeaders( optional string ContentType )
  78. {
  79.     if(ContentType == "")
  80.         ContentType = "text/html";
  81.     if(!bSentResponse)
  82.         HTTPResponse("HTTP/1.1 200 OK");
  83.     HTTPHeader("Server: UnrealEngine UWeb Web Server Build "$Connection.Level.EngineVersion);
  84.     HTTPHeader("Content-Type: "$ContentType);
  85.     HTTPHeader("");
  86. }
  87.  
  88. function Redirect(string URL)
  89. {
  90.     HTTPResponse("HTTP/1.1 302 Document Moved");
  91.     HTTPHeader("Location: "$URL);
  92.     SendText("<head><title>Document Moved</title></head>");
  93.     SendText("<body><h1>Object Moved</h1>This document may be found <a HREF=\""$URL$"\">here</a>.");
  94. }
  95.  
  96. defaultproperties
  97. {
  98.     IncludePath="../Web"
  99. }