本文整理汇总了C#中WhiteCore.Framework.Servers.HttpServer.Implementation.OSHttpResponse.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# OSHttpResponse.AddHeader方法的具体用法?C# OSHttpResponse.AddHeader怎么用?C# OSHttpResponse.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WhiteCore.Framework.Servers.HttpServer.Implementation.OSHttpResponse
的用法示例。
在下文中一共展示了OSHttpResponse.AddHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteTextureData
byte [] WriteTextureData (OSHttpRequest request, OSHttpResponse response, AssetBase texture, string format)
{
string range = request.Headers.GetOne ("Range");
//MainConsole.Instance.DebugFormat("[GETTEXTURE]: Range {0}", 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;
return MainServer.BlankResponse;
} else {
// Handle the case where portions of the range are missing.
if (start == -1)
start = 0;
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;
//MainConsole.Instance.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID);
if (len < texture.Data.Length)
response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent;
else
response.StatusCode = (int)System.Net.HttpStatusCode.OK;
response.ContentType = texture.TypeString;
response.AddHeader ("Content-Range",
string.Format ("bytes {0}-{1}/{2}", start, end, texture.Data.Length));
byte [] array = new byte [len];
Array.Copy (texture.Data, start, array, 0, len);
return array;
}
}
MainConsole.Instance.Warn ("[AssetCAPS]: Malformed Range header: " + range);
response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
return MainServer.BlankResponse;
}
// Full content request
response.StatusCode = (int)System.Net.HttpStatusCode.OK;
response.ContentType = texture.TypeString;
if (format == DefaultFormat)
response.ContentType = texture.TypeString;
else
response.ContentType = "image/" + format;
return texture.Data;
}
示例2: GetContentType
protected string GetContentType(string filename, OSHttpResponse response)
{
switch (Path.GetExtension(filename))
{
case ".jpeg":
case ".jpg":
response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString());
return "image/jpeg";
case ".gif":
response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString());
return "image/gif";
case ".png":
response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString());
return "image/png";
case ".tiff":
response.AddHeader("Cache-Control", "Public;max-age=" + CLIENT_CACHE_TIME.ToString());
return "image/tiff";
case ".html":
case ".htm":
case ".xsl":
response.AddHeader("Cache-Control", "no-cache");
return "text/html";
case ".css":
//response.AddHeader("Cache-Control", "max-age=" + CLIENT_CACHE_TIME.ToString() + ", public");
response.AddHeader("Cache-Control", "no-cache");
return "text/css";
case ".js":
//response.AddHeader("Cache-Control", "max-age=" + CLIENT_CACHE_TIME.ToString() + ", public");
return "application/javascript";
}
return "text/plain";
}
示例3: GetHTML404
public byte[] GetHTML404(OSHttpResponse response)
{
// I know this statuscode is dumb, but the client doesn't respond to 404s and 500s
response.StatusCode = 404;
response.AddHeader("Content-type", "text/html");
string responseString = GetHTTP404();
byte[] buffer = Encoding.UTF8.GetBytes(responseString);
response.SendChunked = false;
response.ContentEncoding = Encoding.UTF8;
return buffer;
}
示例4: Redirect
internal void Redirect(OSHttpResponse httpResponse, string url)
{
httpResponse.StatusCode = (int) HttpStatusCode.Redirect;
httpResponse.AddHeader("Location", url);
httpResponse.KeepAlive = false;
}
示例5: GetContentType
protected string GetContentType (string filename, OSHttpResponse response)
{
var setCache = true; // default is to cache
var mimeType = "";
var ext = Path.GetExtension (filename);
switch (ext) {
case ".jpeg":
case ".jpg":
mimeType = "image/jpeg";
break;
case ".gif":
mimeType = "image/gif";
break;
case ".png":
mimeType = "image/png";
break;
case ".tiff":
mimeType = "image/tiff";
break;
case ".woff":
mimeType = "application/font-woff";
break;
case ".woff2":
mimeType = "application/font-woff2";
break;
case ".ttf":
mimeType = "application/font-ttf";
break;
case ".css":
setCache = !filename.StartsWith ("styles", StringComparison.Ordinal);
mimeType = "text/css";
break;
case ".html":
case ".htm":
case ".xsl":
setCache = false;
mimeType = "text/html";
break;
case ".js":
setCache = !filename.Contains ("menu"); // must not cache menu generation
mimeType = "application/javascript";
break;
default:
mimeType = "text/plain";
break;
}
if (setCache)
response.AddHeader ("Cache-Control", "public, max-age=" + CLIENT_CACHE_TIME);
else
response.AddHeader ("Cache-Control", "no-cache");
return mimeType;
}