<%
Function BuildRequestOrigin()
    Dim protocol

    protocol = "http://"
    If LCase(Request.ServerVariables("HTTPS")) = "on" Then
        protocol = "https://"
    End If

    BuildRequestOrigin = protocol & Request.ServerVariables("HTTP_HOST")
End Function

Function GetProductionBaseUrl()
    Dim configuredUrl

    configuredUrl = GetAppSetting("ProductionAppBaseUrl")
    If configuredUrl = "nothing" Or Len(Trim(configuredUrl)) = 0 Then
        GetProductionBaseUrl = BuildRequestOrigin() & "/"
    Else
        If Right(configuredUrl, 1) <> "/" Then
            configuredUrl = configuredUrl & "/"
        End If
        GetProductionBaseUrl = configuredUrl
    End If
End Function

Function FetchPage(path)
    Dim http, result, targetUrl

    targetUrl = GetProductionBaseUrl()
    If Left(path, 1) = "/" Then
        path = Mid(path, 2)
    End If
    targetUrl = targetUrl & path

    Set http = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
    http.Open "GET", targetUrl, False
    http.Send

    Set result = Server.CreateObject("Scripting.Dictionary")
    result.Add "url", targetUrl
    result.Add "status", http.Status
    result.Add "body", http.responseText

    Set FetchPage = result
    Set http = Nothing
End Function
%>
