mirror of
https://github.com/opensim/opensim.git
synced 2026-08-08 18:25:33 +08:00
add auxiliar httpresponse.Redirect(string url, [HttpStatusCode redirStatusCode = HttpStatusCode.Redirect])
This commit is contained in:
@@ -136,9 +136,8 @@ namespace OpenSim.Capabilities.Handlers
|
||||
if(!String.IsNullOrEmpty(m_RedirectURL))
|
||||
{
|
||||
string textureUrl = m_RedirectURL + "?texture_id=" + textureID.ToString();
|
||||
httpResponse.Redirect(textureUrl, HttpStatusCode.Moved);
|
||||
m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl);
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.Moved;
|
||||
httpResponse.AddHeader("Location:", textureUrl);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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"];
|
||||
|
||||
|
||||
@@ -122,8 +122,7 @@ namespace OpenSim.Region.ClientStack.LindenCaps
|
||||
|
||||
private void ProcessServerReleaseNotes(IOSHttpResponse httpResponse)
|
||||
{
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.Moved;
|
||||
httpResponse.AddHeader("Location", m_ServerReleaseNotesURL);
|
||||
httpResponse.Redirect(m_ServerReleaseNotesURL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,13 +102,11 @@ namespace OpenSim.Server.Handlers.Asset
|
||||
|
||||
if (metadata != null)
|
||||
{
|
||||
XmlSerializer xs =
|
||||
new XmlSerializer(typeof(AssetMetadata));
|
||||
XmlSerializer xs = new XmlSerializer(typeof(AssetMetadata));
|
||||
result = ServerUtils.SerializeResult(xs, metadata);
|
||||
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.OK;
|
||||
httpResponse.ContentType =
|
||||
SLUtil.SLAssetTypeToContentType(metadata.Type);
|
||||
httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(metadata.Type);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -138,8 +136,7 @@ namespace OpenSim.Server.Handlers.Asset
|
||||
result = ServerUtils.SerializeResult(xs, asset);
|
||||
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.OK;
|
||||
httpResponse.ContentType =
|
||||
SLUtil.SLAssetTypeToContentType(asset.Type);
|
||||
httpResponse.ContentType = SLUtil.SLAssetTypeToContentType(asset.Type);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -158,12 +155,11 @@ namespace OpenSim.Server.Handlers.Asset
|
||||
|
||||
if (httpResponse.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(m_RedirectURL) && !string.IsNullOrEmpty(id))
|
||||
{
|
||||
httpResponse.StatusCode = (int)HttpStatusCode.Redirect;
|
||||
string rurl = m_RedirectURL;
|
||||
if (!path.StartsWith("/"))
|
||||
rurl += "/";
|
||||
rurl += path;
|
||||
httpResponse.AddHeader("Location", rurl);
|
||||
httpResponse.Redirect(rurl);
|
||||
m_log.DebugFormat("[ASSET GET HANDLER]: Asset not found, redirecting to {0} ({1})", rurl, httpResponse.StatusCode);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using OpenSim.Framework.Servers.HttpServer;
|
||||
|
||||
namespace OpenSim.Tests.Common
|
||||
@@ -119,6 +119,12 @@ namespace OpenSim.Tests.Common
|
||||
|
||||
public 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 Redirect, Moved,MovedPermanently,RedirectKeepVerb, RedirectMethod, TemporaryRedirect. Defaults to Redirect</param>
|
||||
public void Redirect(string url, HttpStatusCode redirStatusCode = HttpStatusCode.Redirect) { throw new NotImplementedException(); }
|
||||
/// <summary>
|
||||
/// Add a header field and content to the response.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user