本文整理汇总了C#中IOSHttpResponse.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# IOSHttpResponse.AddHeader方法的具体用法?C# IOSHttpResponse.AddHeader怎么用?C# IOSHttpResponse.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOSHttpResponse
的用法示例。
在下文中一共展示了IOSHttpResponse.AddHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OKResponse
private byte[] OKResponse(IOSHttpResponse httpResponse)
{
m_log.Debug("[HELO]: hi, GET was called");
httpResponse.AddHeader("X-Handlers-Provided", m_HandlersType);
httpResponse.StatusCode = (int)HttpStatusCode.OK;
httpResponse.StatusDescription = "OK";
return new byte[0];
}
示例2: WriteTextureData
private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format)
{
string range = request.Headers.GetOne("Range");
if (!String.IsNullOrEmpty(range)) // JP2's only
{
// Range request
int start, end;
if (TryParseRange(range, out start, out end))
{
// Before clamping start make sure we can satisfy it in order to avoid
// sending back the last byte instead of an error status
if (start >= texture.Data.Length)
{
response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable;
}
else
{
end = Utils.Clamp(end, 0, texture.Data.Length - 1);
start = Utils.Clamp(start, 0, end);
int len = end - start + 1;
//m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
// Always return PartialContent, even if the range covered the entire data length
// We were accidentally sending back 404 before in this situation
// https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the
// entire range is requested, and viewer 3.2.2 (and very probably earlier) seems fine with this.
response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
response.ContentLength = len;
response.ContentType = texture.Metadata.ContentType;
response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length));
response.Body.Write(texture.Data, start, len);
}
}
else
{
m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range);
response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
}
}
else // JP2's or other formats
{
// Full content request
response.StatusCode = (int)System.Net.HttpStatusCode.OK;
response.ContentLength = texture.Data.Length;
if (format == DefaultFormat)
response.ContentType = texture.Metadata.ContentType;
else
response.ContentType = "image/" + format;
response.Body.Write(texture.Data, 0, texture.Data.Length);
}
// if (response.StatusCode < 200 || response.StatusCode > 299)
// m_log.WarnFormat(
// "[GETTEXTURE]: For texture {0} requested range {1} responded {2} with content length {3} (actual {4})",
// texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length);
// else
// m_log.DebugFormat(
// "[GETTEXTURE]: For texture {0} requested range {1} responded {2} with content length {3} (actual {4})",
// texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length);
}
示例3: WriteTextureData
private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format)
{
string range = request.Headers.GetOne("Range");
if (!String.IsNullOrEmpty(range)) // JP2's only
{
// Range request
int start, end;
if (TryParseRange(range, out start, out end))
{
// Before clamping start make sure we can satisfy it in order to avoid
// sending back the last byte instead of an error status
if (start >= texture.Data.Length)
{
// m_log.DebugFormat(
// "[GETTEXTURE]: Client requested range for texture {0} starting at {1} but texture has end of {2}",
// texture.ID, start, texture.Data.Length);
// Stricly speaking, as per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, we should be sending back
// Requested Range Not Satisfiable (416) here. However, it appears that at least recent implementations
// of the Linden Lab viewer (3.2.1 and 3.3.4 and probably earlier), a viewer that has previously
// received a very small texture may attempt to fetch bytes from the server past the
// range of data that it received originally. Whether this happens appears to depend on whether
// the viewer's estimation of how large a request it needs to make for certain discard levels
// (http://wiki.secondlife.com/wiki/Image_System#Discard_Level_and_Mip_Mapping), chiefly discard
// level 2. If this estimate is greater than the total texture size, returning a RequestedRangeNotSatisfiable
// here will cause the viewer to treat the texture as bad and never display the full resolution
// However, if we return PartialContent (or OK) instead, the viewer will display that resolution.
// response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable;
// response.AddHeader("Content-Range", String.Format("bytes */{0}", texture.Data.Length));
// response.StatusCode = (int)System.Net.HttpStatusCode.OK;
response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
response.ContentType = texture.Metadata.ContentType;
}
else
{
// Handle the case where no second range value was given. This is equivalent to requesting
// the rest of the entity.
if (end == -1)
end = int.MaxValue;
end = Utils.Clamp(end, 0, texture.Data.Length - 1);
start = Utils.Clamp(start, 0, end);
int len = end - start + 1;
// m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
// Always return PartialContent, even if the range covered the entire data length
// We were accidentally sending back 404 before in this situation
// https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the
// entire range is requested, and viewer 3.2.2 (and very probably earlier) seems fine with this.
//
// We also do not want to send back OK even if the whole range was satisfiable since this causes
// HTTP textures on at least Imprudence 1.4.0-beta2 to never display the final texture quality.
// if (end > maxEnd)
// response.StatusCode = (int)System.Net.HttpStatusCode.OK;
// else
response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
response.ContentLength = len;
response.ContentType = texture.Metadata.ContentType;
response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length));
response.Body.Write(texture.Data, start, len);
}
}
else
{
m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range);
response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
}
}
else // JP2's or other formats
{
// Full content request
response.StatusCode = (int)System.Net.HttpStatusCode.OK;
response.ContentLength = texture.Data.Length;
if (format == DefaultFormat)
response.ContentType = texture.Metadata.ContentType;
else
response.ContentType = "image/" + format;
response.Body.Write(texture.Data, 0, texture.Data.Length);
}
// if (response.StatusCode < 200 || response.StatusCode > 299)
// m_log.WarnFormat(
// "[GETTEXTURE]: For texture {0} requested range {1} responded {2} with content length {3} (actual {4})",
// texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length);
// else
// m_log.DebugFormat(
// "[GETTEXTURE]: For texture {0} requested range {1} responded {2} with content length {3} (actual {4})",
// texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length);
}
示例4: ProcessRequest
protected override byte[] ProcessRequest(string path, Stream request,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
byte[] result = new byte[0];
string[] p = SplitParams(path);
if (p.Length == 0)
return result;
string id = string.Empty;
if (p.Length > 1)
{
id = p[0];
string cmd = p[1];
if (cmd == "data")
{
result = m_AssetService.GetData(id);
if (result == null)
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
httpResponse.ContentType = "text/plain";
result = new byte[0];
}
else
{
httpResponse.StatusCode = (int)HttpStatusCode.OK;
httpResponse.ContentType = "application/octet-stream";
}
}
else if (cmd == "metadata")
{
AssetMetadata metadata = m_AssetService.GetMetadata(id);
if (metadata != null)
{
XmlSerializer xs =
new XmlSerializer(typeof(AssetMetadata));
result = ServerUtils.SerializeResult(xs, metadata);
httpResponse.StatusCode = (int)HttpStatusCode.OK;
httpResponse.ContentType =
SLUtil.SLAssetTypeToContentType(metadata.Type);
}
else
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
httpResponse.ContentType = "text/plain";
result = new byte[0];
}
}
else
{
// Unknown request
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
httpResponse.ContentType = "text/plain";
result = new byte[0];
}
}
else if (p.Length == 1)
{
// Get the entire asset (metadata + data)
id = p[0];
AssetBase asset = m_AssetService.Get(id);
if (asset != null)
{
XmlSerializer xs = new XmlSerializer(typeof(AssetBase));
result = ServerUtils.SerializeResult(xs, asset);
httpResponse.StatusCode = (int)HttpStatusCode.OK;
httpResponse.ContentType =
SLUtil.SLAssetTypeToContentType(asset.Type);
}
else
{
httpResponse.StatusCode = (int)HttpStatusCode.NotFound;
httpResponse.ContentType = "text/plain";
result = new byte[0];
}
}
else
{
// Unknown request
httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
httpResponse.ContentType = "text/plain";
result = new byte[0];
}
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);
}
//.........这里部分代码省略.........
示例5: WriteMeshData
private void WriteMeshData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture)
{
string range = request.Headers.GetOne("Range");
if (!String.IsNullOrEmpty(range))
{
// Range request
int start, end;
if (TryParseRange(range, out start, out end))
{
// Before clamping start make sure we can satisfy it in order to avoid
// sending back the last byte instead of an error status
if (start >= texture.Data.Length)
{
response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
response.AddHeader("Content-Range", String.Format("bytes */{0}", texture.Data.Length));
response.ContentType = texture.Metadata.ContentType;
}
else
{
// Handle the case where no second range value was given. This is equivalent to requesting
// the rest of the entity.
if (end == -1)
end = int.MaxValue;
end = Utils.Clamp(end, 0, texture.Data.Length - 1);
start = Utils.Clamp(start, 0, end);
int len = end - start + 1;
if (0 == start && len == texture.Data.Length)
{
response.StatusCode = (int)System.Net.HttpStatusCode.OK;
}
else
{
response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length));
}
response.ContentLength = len;
response.ContentType = "application/vnd.ll.mesh";
response.Body.Write(texture.Data, start, len);
}
}
else
{
m_log.Warn("[GETMESH]: Malformed Range header: " + range);
response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
}
}
else
{
// Full content request
response.StatusCode = (int)System.Net.HttpStatusCode.OK;
response.ContentLength = texture.Data.Length;
response.ContentType = "application/vnd.ll.mesh";
response.Body.Write(texture.Data, 0, texture.Data.Length);
}
}
示例6: RestGetMumbleServerInfo
/// <summary>
/// Returns information about a mumble server via a REST Request
/// </summary>
/// <param name="request"></param>
/// <param name="path"></param>
/// <param name="param">A string representing the sim's UUID</param>
/// <param name="httpRequest">HTTP request header object</param>
/// <param name="httpResponse">HTTP response header object</param>
/// <returns>Information about the mumble server in http response headers</returns>
public string RestGetMumbleServerInfo(Scene scene, string request, string path, string param,
IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
{
if (m_murmurd_host == null)
{
httpResponse.StatusCode = 404;
httpResponse.StatusDescription = "Not Found";
string message = "[MurmurVoice]: Server info request from " + httpRequest.RemoteIPEndPoint.Address + ". Cannot send response, module is not configured properly.";
m_log.Warn(message);
return "Mumble server info is not available.";
}
if (httpRequest.Headers.GetValues("avatar_uuid") == null)
{
httpResponse.StatusCode = 400;
httpResponse.StatusDescription = "Bad Request";
string message = "[MurmurVoice]: Invalid server info request from " + httpRequest.RemoteIPEndPoint.Address + "";
m_log.Warn(message);
return "avatar_uuid header is missing";
}
string avatar_uuid = httpRequest.Headers.GetValues("avatar_uuid")[0];
string responseBody = String.Empty;
UUID avatarId;
if (UUID.TryParse(avatar_uuid, out avatarId))
{
if (scene == null) throw new Exception("[MurmurVoice] Invalid scene.");
ServerManager manager = GetServerManager(scene);
Agent agent = manager.Agent.GetOrCreate(avatarId, scene);
string channel_uri;
ScenePresence avatar = scene.GetScenePresence(avatarId);
// get channel_uri: check first whether estate
// settings allow voice, then whether parcel allows
// voice, if all do retrieve or obtain the parcel
// voice channel
LandData land = scene.GetLandData(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
if (null == land)
throw new Exception(String.Format("region \"{0}\": avatar \"{1}\": land data not yet available",
scene.RegionInfo.RegionName, avatar.Name));
m_log.DebugFormat("[MurmurVoice] region \"{0}\": Parcel \"{1}\" ({2}): avatar \"{3}\": request: {4}, path: {5}, param: {6}",
scene.RegionInfo.RegionName, land.Name, land.LocalID, avatar.Name, request, path, param);
if (((land.Flags & (uint)ParcelFlags.AllowVoiceChat) > 0) && scene.RegionInfo.EstateSettings.AllowVoice)
{
agent.channel = manager.Channel.GetOrCreate(ChannelName(scene, land));
// Host/port pair for voice server
channel_uri = String.Format("{0}:{1}", m_murmurd_host, m_murmurd_port);
if (agent.session > 0)
{
Murmur.User state = manager.Server.getState(agent.session);
GetServerCallback(scene).AddUserToChan(state, agent.channel);
}
m_log.InfoFormat("[MurmurVoice] channel_uri {0}", channel_uri);
}
else
{
m_log.DebugFormat("[MurmurVoice] Voice not enabled.");
channel_uri = "";
}
string m_context = "Mumble voice system";
httpResponse.AddHeader("Mumble-Server", m_murmurd_host);
httpResponse.AddHeader("Mumble-Version", m_server_version);
httpResponse.AddHeader("Mumble-Channel", channel_uri);
httpResponse.AddHeader("Mumble-User", avatar_uuid);
httpResponse.AddHeader("Mumble-Password", agent.pass);
httpResponse.AddHeader("Mumble-Avatar-Id", avatar_uuid);
httpResponse.AddHeader("Mumble-Context-Id", m_context);
responseBody += "Mumble-Server: " + m_murmurd_host + "\n";
responseBody += "Mumble-Version: " + m_server_version + "\n";
responseBody += "Mumble-Channel: " + channel_uri + "\n";
responseBody += "Mumble-User: " + avatar_uuid + "\n";
responseBody += "Mumble-Password: " + agent.pass + "\n";
responseBody += "Mumble-Avatar-Id: " + avatar_uuid + "\n";
responseBody += "Mumble-Context-Id: " + m_context + "\n";
string log_message = "[MurmurVoice]: Server info request handled for " + httpRequest.RemoteIPEndPoint.Address + "";
m_log.Info(log_message);
}
else
//.........这里部分代码省略.........