当前位置: 首页>>代码示例>>C#>>正文


C# OSHttpResponse.AddHeader方法代码示例

本文整理汇总了C#中Universe.Framework.Servers.HttpServer.Implementation.OSHttpResponse.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# OSHttpResponse.AddHeader方法的具体用法?C# OSHttpResponse.AddHeader怎么用?C# OSHttpResponse.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Universe.Framework.Servers.HttpServer.Implementation.OSHttpResponse的用法示例。


在下文中一共展示了OSHttpResponse.AddHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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", "no-cache");
             return "text/css";
         case ".js":
             return "application/javascript";
     }
     return "text/plain";
 }
开发者ID:emperorstarfinder,项目名称:Virtual-Universe,代码行数:30,代码来源:WebInterface.cs

示例2: WriteTextureData

        byte[] WriteTextureData(OSHttpRequest request, OSHttpResponse response, AssetBase texture, string format)
        {
            string range = request.Headers.GetOne("Range");
            //MainConsole.Instance.DebugFormat("[GET TEXTURE]: 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("[GET TEXTURE]: 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;
        }
开发者ID:emperorstarfinder,项目名称:Virtual-Universe,代码行数:60,代码来源:AssetCAPS.cs

示例3: Redirect

 internal void Redirect(OSHttpResponse httpResponse, string url)
 {
     httpResponse.StatusCode = (int) HttpStatusCode.Redirect;
     httpResponse.AddHeader("Location", url);
     httpResponse.KeepAlive = false;
 }
开发者ID:emperorstarfinder,项目名称:Virtual-Universe,代码行数:6,代码来源:WebInterface.cs

示例4: 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;
        }
开发者ID:VirtualReality,项目名称:Universe,代码行数:14,代码来源:BaseHttpServer.cs


注:本文中的Universe.Framework.Servers.HttpServer.Implementation.OSHttpResponse.AddHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。