mirror of
https://github.com/opensim/opensim.git
synced 2026-08-08 10:15:33 +08:00
add auxiliar httpresponse.Redirect(string url, [HttpStatusCode redirStatusCode = HttpStatusCode.Redirect])
This commit is contained in:
@@ -2031,8 +2031,7 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
if (responsecode == (int)HttpStatusCode.Moved)
|
||||
{
|
||||
response.AddHeader("Location:", (string)responsedata["str_redirect_location"]);
|
||||
response.StatusCode = responsecode;
|
||||
response.Redirect((string)responsedata["str_redirect_location"], HttpStatusCode.Moved);
|
||||
}
|
||||
|
||||
response.AddHeader("Content-Type", contentType);
|
||||
@@ -2430,15 +2429,12 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
if (httpRequest.QueryString.Count == 0)
|
||||
{
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
|
||||
httpResponse.AddHeader("Location", "http://opensimulator.org");
|
||||
httpResponse.Redirect("http://opensimulator.org");
|
||||
return;
|
||||
}
|
||||
if (httpRequest.QueryFlags.Contains("about"))
|
||||
{
|
||||
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
|
||||
httpResponse.AddHeader("Location", "http://opensimulator.org/wiki/0.9.2.1_Release");
|
||||
httpResponse.Redirect("http://opensimulator.org/wiki/0.9.2.1_Release");
|
||||
return;
|
||||
}
|
||||
if (!httpRequest.QueryAsDictionary.TryGetValue("method", out string methods) || string.IsNullOrWhiteSpace(methods))
|
||||
|
||||
@@ -119,6 +119,13 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
|
||||
double RequestTS { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Set response as a http redirect
|
||||
/// </summary>
|
||||
/// <param name="url">redirection target url</param>
|
||||
/// <param name="redirStatusCode">the response Status, must be Found, Redirect, Moved,MovedPermanently,RedirectKeepVerb, RedirectMethod, TemporaryRedirect. Defaults to Redirect</param>
|
||||
void Redirect(string url, HttpStatusCode redirStatusCode = HttpStatusCode.Redirect);
|
||||
|
||||
/// <summary>
|
||||
/// Add a header field and content to the response.
|
||||
/// </summary>
|
||||
|
||||
@@ -321,6 +321,16 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
_httpResponse = resp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set response as a http redirect
|
||||
/// </summary>
|
||||
/// <param name="url">redirection target url</param>
|
||||
/// <param name="redirStatusCode">the response Status, must be Found, Redirect, Moved,MovedPermanently,RedirectKeepVerb, RedirectMethod, TemporaryRedirect. Defaults to Redirect</param>
|
||||
public void Redirect(string url, HttpStatusCode redirStatusCode = HttpStatusCode.Redirect)
|
||||
{
|
||||
_httpResponse.Redirect(url, redirStatusCode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a header field and content to the response.
|
||||
/// </summary>
|
||||
|
||||
@@ -191,10 +191,24 @@ namespace OSHttpServer
|
||||
get { return m_cookies; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set response as a http redirect
|
||||
/// </summary>
|
||||
/// <param name="url">redirection target url</param>
|
||||
/// <param name="redirStatusCode">the response Status, must be Found, Redirect, Moved,MovedPermanently,RedirectKeepVerb, RedirectMethod, TemporaryRedirect. Defaults to Redirect</param>
|
||||
public void Redirect(string url, HttpStatusCode redirStatusCode = HttpStatusCode.Redirect)
|
||||
{
|
||||
if (HeadersSent)
|
||||
throw new InvalidOperationException("Headers have already been sent.");
|
||||
|
||||
m_headers["Location"] = url;
|
||||
Status = redirStatusCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add another header to the document.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the header, case sensitive, use lower cases.</param>
|
||||
/// <param name="name">Name of the header, case sensitive.</param>
|
||||
/// <param name="value">Header values can span over multiple lines as long as each line starts with a white space. New line chars should be \r\n</param>
|
||||
/// <exception cref="InvalidOperationException">If headers already been sent.</exception>
|
||||
/// <exception cref="ArgumentException">If value conditions have not been met.</exception>
|
||||
|
||||
@@ -112,6 +112,13 @@ namespace OSHttpServer
|
||||
/// </summary>
|
||||
ResponseCookies Cookies { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Set response as a http redirect
|
||||
/// </summary>
|
||||
/// <param name="url">redirection target url</param>
|
||||
/// <param name="redirStatusCode">the response Status, must be Found, Redirect, Moved,MovedPermanently,RedirectKeepVerb, RedirectMethod, TemporaryRedirect. Defaults to Redirect</param>
|
||||
void Redirect(string url, HttpStatusCode redirStatusCode = HttpStatusCode.Redirect);
|
||||
|
||||
/// <summary>
|
||||
/// Add another header to the document.
|
||||
/// </summary>
|
||||
|
||||
@@ -116,16 +116,17 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||
return;
|
||||
}
|
||||
|
||||
response.StatusCode = responsecode;
|
||||
if (responsecode == (int)HttpStatusCode.Moved)
|
||||
{
|
||||
response.AddHeader("Location", (string)responsedata["str_redirect_location"]);
|
||||
response.Redirect((string)responsedata["str_redirect_location"], HttpStatusCode.Moved);
|
||||
response.KeepAlive = false;
|
||||
PollServiceArgs.RequestsHandled++;
|
||||
response.Send();
|
||||
return;
|
||||
}
|
||||
|
||||
response.StatusCode = responsecode;
|
||||
|
||||
if (responsedata.ContainsKey("http_protocol_version"))
|
||||
response.ProtocolVersion = (string)responsedata["http_protocol_version"];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user