Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UWeb.WebResponse


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
/*=============================================================================
    WebResponse is used by WebApplication to handle most aspects of sending
    http information to the client. It serves as a bridge between WebApplication
    and WebConnection.
=============================================================================*/

class WebResponse extends Object
    native
    noexport;

var private native const TMultiMap ReplacementMap;  // C++ placeholder.
var const config string         IncludePath;
var localized string            CharSet;
var WebConnection               Connection;
var bool                        bSentText; // used to warn headers already sent
var bool                        bSentResponse;

native final function           Subst(string Variable, coerce string Value, optional bool bClear);
native final function           ClearSubst();
native final function           IncludeUHTM(string Filename);
native final function           IncludeBinaryFile(string Filename);
native final function string    LoadParsedUHTM(string Filename); // For templated web items, uses Subst too
native final function string    GetHTTPExpiration(optional int OffsetSeconds);

native final function Dump(); // only works in dev mode

event SendText(string Text, optional bool bNoCRLF)
{
    if(!bSentText)
    {
        SendStandardHeaders();
        bSentText = True;
    }

    if(bNoCRLF)
        Connection.SendText(Text);
    else
        Connection.SendText(Text$Chr(13)$Chr(10));
}

event SendBinary(int Count, byte B[255])
{
    Connection.SendBinary(Count, B);
}

function SendCachedFile(string Filename, optional string ContentType)
{
    if(!bSentText)
    {
        SendStandardHeaders(ContentType, true);
        bSentText = True;
    }
    IncludeUHTM(Filename);
}

function FailAuthentication(string Realm)
{
    HTTPError(401, Realm);
}

function HTTPResponse(string Header)
{
    HTTPHeader(Header);
    bSentResponse = True;
}

function HTTPHeader(string Header)
{
    if(bSentText)
        Log("Can't send headers - already called SendText()");

    Connection.SendText(Header$Chr(13)$Chr(10));
}

function HTTPError(int ErrorNum, optional string Data)
{
    switch(ErrorNum)
    {
    case 400:
        HTTPResponse("HTTP/1.1 400 Bad Request");
        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.");
        break;
    case 401:
        HTTPResponse("HTTP/1.1 401 Unauthorized");
        HTTPHeader("WWW-authenticate: basic realm=\""$Data$"\"");
        SendText("<TITLE>401 Unauthorized</TITLE><H1>401 Unauthorized</H1>");
        break;
    case 404:
        HTTPResponse("HTTP/1.1 404 Object Not Found");
        SendText("<TITLE>404 File Not Found</TITLE><H1>404 File Not Found</H1>The URL you requested was not found.");
        break;
    default:
        break;
    }
}

function SendStandardHeaders( optional string ContentType, optional bool bCache )
{
    if(ContentType == "")
        ContentType = "text/html";
    if(!bSentResponse)
        HTTPResponse("HTTP/1.1 200 OK");
    HTTPHeader("Server: UnrealEngine UWeb Web Server Build "$Connection.Level.EngineVersion);
    HTTPHeader("Content-Type: "$ContentType);
    if (bCache)
    {
        HTTPHeader("Cache-Control: max-age="$Connection.WebServer.ExpirationSeconds);
        // Need to compute an Expires: tag .... arrgggghhh
        HTTPHeader("Expires:"@GetHTTPExpiration(Connection.WebServer.ExpirationSeconds));
    }
    HTTPHeader("Connection: Close");
    HTTPHeader("");
}

function Redirect(string URL)
{
    HTTPResponse("HTTP/1.1 302 Document Moved");
    HTTPHeader("Location: "$URL);
    SendText("<head><title>Document Moved</title></head>");
    SendText("<body><h1>Object Moved</h1>This document may be found <a HREF=\""$URL$"\">here</a>.");
}

defaultproperties
{
     IncludePath="/Web"
     CharSet="iso-8859-1"
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Fr 30.3.2007 08:43:38.000 - Creation time: Mo 16.4.2007 11:20:57.531 - Created with UnCodeX