• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# HttpResponseHeader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中HttpResponseHeader的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseHeader类的具体用法?C# HttpResponseHeader怎么用?C# HttpResponseHeader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpResponseHeader类属于命名空间,在下文中一共展示了HttpResponseHeader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ParseRequestKey

 /// <summary>
 /// URLからファイルのキーを取り出す。
 /// 形式としては、/wiki/FileKey/ や /bbs/FileKey/ のほかに、汎用の /FileKey/ に対応し、
 /// FileKeyの後ろにスラッシュが無くURLが終わっている場合は、最後にスラッシュを付与するようにリダイレクトさせる
 /// </summary>
 Key ParseRequestKey(IHttpRequest req, HttpResponseHeader res, out string tailurl)
 {
     tailurl = null;
     string str_key = req.Url.AbsolutePath.Substring (1);
     int pos = str_key.IndexOf ('/');
     if (pos > 0 && pos < 10) {
         // /wiki や /bbs を除去
         str_key = str_key.Substring (pos + 1);
         pos = str_key.IndexOf ('/');
     }
     if (pos < 0) {
         // キーの末尾の / が無いのでリダイレクト
         res[HttpHeaderNames.Location] = req.Url.AbsolutePath + "/";
         throw new HttpException (req.HttpVersion == HttpVersion.Http10 ? HttpStatusCode.Found : HttpStatusCode.SeeOther);
     } else {
         tailurl = str_key.Substring (pos + 1);
         str_key = str_key.Substring (0, pos);
     }
     try {
         if (str_key.Length == (DefaultAlgorithm.ECDomainBytes + 1) * 2)
             return Key.Parse (str_key);
         else if (str_key.Length == (DefaultAlgorithm.ECDomainBytes + 1) * 4 / 3)
             return Key.FromUriSafeBase64String (str_key);
         throw new HttpException (HttpStatusCode.NotFound);
     } catch {
         throw new HttpException (HttpStatusCode.NotFound);
     }
 }
开发者ID:kazuki,项目名称:p2pncs,代码行数:33,代码来源:WebAppFileCommon.cs


示例2: Render

        public object Render(IHttpRequest req, HttpResponseHeader res, XmlDocument doc, string xsl_path)
        {
            XslCache cache;
            _cacheLock.AcquireReaderLock (Timeout.Infinite);
            try {
                if (!_cache.TryGetValue (xsl_path, out cache)) {
                    cache = new XslCache (xsl_path);
                    LockCookie cookie = _cacheLock.UpgradeToWriterLock (Timeout.Infinite);
                    try {
                        _cache[xsl_path] = cache;
                    } finally {
                        _cacheLock.DowngradeFromWriterLock (ref cookie);
                    }
                }
            } finally {
                _cacheLock.ReleaseReaderLock ();
            }

            bool enable_xhtml = (req.Headers.ContainsKey (HttpHeaderNames.Accept) && req.Headers[HttpHeaderNames.Accept].Contains (MIME_XHTML));
            if (enable_xhtml) {
                res[HttpHeaderNames.ContentType] = MIME_XHTML + "; charset=utf-8";
            } else {
                res[HttpHeaderNames.ContentType] = MIME_HTML + "; charset=utf-8";
            }
            return cache.Transform (doc, !enable_xhtml);
        }
开发者ID:kazuki,项目名称:httpserver,代码行数:26,代码来源:XslTemplateEngine.cs


示例3: Process

        public object Process(IHttpServer server, IHttpRequest req, HttpResponseHeader header)
        {
            header[HttpHeaderNames.ContentType] = "text/plain; charset=UTF-8";
            header[HttpHeaderNames.Date] = DateTime.UtcNow.ToString ("R");

            byte[] raw = Encoding.UTF8.GetBytes ("Hello World");
            header[HttpHeaderNames.ContentLength] = raw.Length.ToString ();
            return raw;
        }
开发者ID:kazuki,项目名称:httpserver,代码行数:9,代码来源:Program.cs


示例4: CometInfo

 public CometInfo(WaitHandle waitHandle, IHttpRequest req, HttpResponseHeader res, object ctx, DateTime timeout, CometHandler handler)
 {
     _waitHandle = waitHandle;
     _connection = null;
     _req = req;
     _res = res;
     _ctx = ctx;
     _timeout = timeout;
     _handler = handler;
 }
开发者ID:kazuki,项目名称:httpserver,代码行数:10,代码来源:CometInfo.cs


示例5: Process

 public object Process(IHttpServer server, IHttpRequest req, HttpResponseHeader res)
 {
     switch (req.Url.AbsolutePath) {
     case "/alm_create":
         return ProcessCreateGroup(server, req, res);
     case "/alm_join":
         return ProcessJoinGroup(server, req, res);
     case "/alm_cand":
         return ProcessCandidatePeer(server, req, res);
     }
     return ProcessStaticFile (server, req, res);
 }
开发者ID:716es,项目名称:webrtc_alm,代码行数:12,代码来源:WebRTCALMTestApp.cs


示例6: ProcessNetExitPage

 object ProcessNetExitPage(IHttpRequest req, HttpResponseHeader res)
 {
     XmlDocument doc = XmlHelper.CreateEmptyDocument ();
     if (req.HttpMethod == HttpMethod.POST) {
         doc.DocumentElement.SetAttribute ("exit", "exit");
         ThreadPool.QueueUserWorkItem (delegate (object o) {
             Thread.Sleep (500);
             _exitWaitHandle.Set ();
         });
     }
     return _xslTemplate.Render (req, res, doc, Path.Combine (DefaultTemplatePath, "net_exit.xsl"));
 }
开发者ID:kazuki,项目名称:p2pncs,代码行数:12,代码来源:WebAppNet.cs


示例7: ProcessManageFile

        object ProcessManageFile(IHttpRequest req, HttpResponseHeader res)
        {
            string str_key = req.Url.AbsolutePath.Substring (8);
            Key key;
            try {
                if (str_key.Length == (DefaultAlgorithm.ECDomainBytes + 1) * 2)
                    key = Key.Parse (str_key);
                else if (str_key.Length == (DefaultAlgorithm.ECDomainBytes + 1) * 4 / 3)
                    key = Key.FromUriSafeBase64String (str_key);
                else
                    throw new HttpException (HttpStatusCode.NotFound);
            } catch {
                throw new HttpException (HttpStatusCode.NotFound);
            }

            MergeableFileHeader header;
            IMergeableFileWebUIHelper header_helper = null;
            if (req.HttpMethod == HttpMethod.POST && req.HasContentBody ()) {
                header = _node.MMLC.GetMergeableFileHeader (key);
                if (header == null)
                    throw new HttpException (HttpStatusCode.NotFound);
                header_helper = (header.Content as IMergeableFile).WebUIHelper;
                NameValueCollection c = HttpUtility.ParseUrlEncodedStringToNameValueCollection (Encoding.ASCII.GetString (req.GetContentBody (MaxRequestBodySize)), Encoding.UTF8);
                AuthServerInfo[] auth_servers = AuthServerInfo.ParseArray (c["auth"]);
                List<Key> list = new List<Key> ();
                string[] keep_array = c.GetValues ("record");
                if (keep_array != null) {
                    for (int i = 0; i < keep_array.Length; i++) {
                        list.Add (Key.FromUriSafeBase64String (keep_array[i]));
                    }
                }
                IHashComputable new_header_content = header_helper.CreateHeaderContent (c);
                string title = c["title"];
                if (title == null || title.Length == 0 || title.Length > 64)
                    throw new HttpException (HttpStatusCode.InternalServerError);
                MergeableFileHeader new_header = new MergeableFileHeader (key, title, header.Flags, header.CreatedTime, new_header_content, auth_servers);
                _node.MMLC.Manage (new_header, list.ToArray (), null);

                res[HttpHeaderNames.Location] = header_helper.ViewUrl + key.ToUriSafeBase64String ();
                throw new HttpException (req.HttpVersion == HttpVersion.Http10 ? HttpStatusCode.Found : HttpStatusCode.SeeOther);
            }

            List<MergeableFileRecord> records = _node.MMLC.GetRecords (key, out header);
            if (header == null || records == null)
                throw new HttpException (HttpStatusCode.NotFound);
            header_helper = (header.Content as IMergeableFile).WebUIHelper;

            XmlDocument doc = XmlHelper.CreateEmptyDocument ();
            doc.DocumentElement.AppendChild (XmlHelper.CreateMergeableFileElement (doc, header, records.ToArray ()));

            return _xslTemplate.Render (req, res, doc, Path.Combine (DefaultTemplatePath, header_helper.ManagePageXslFileName));
        }
开发者ID:kazuki,项目名称:p2pncs,代码行数:52,代码来源:WebAppManage.cs


示例8: ProcessFileList

        object ProcessFileList(IHttpRequest req, HttpResponseHeader res)
        {
            XmlDocument doc = XmlHelper.CreateEmptyDocument ();
            XmlElement rootNode = doc.DocumentElement;
            MergeableFileHeader[] headers = _node.MMLC.GetHeaderList ();

            bool include_empty = req.QueryData.ContainsKey ("empty");
            foreach (MergeableFileHeader header in headers) {
                if (header.RecordsetHash.IsZero () && !include_empty)
                    continue;
                rootNode.AppendChild (XmlHelper.CreateMergeableFileElement (doc, header));
            }
            return _xslTemplate.Render (req, res, doc, Path.Combine (DefaultTemplatePath, "list.xsl"));
        }
开发者ID:kazuki,项目名称:p2pncs,代码行数:14,代码来源:WebAppFileCommon.cs


示例9: TryGetHeader

        /// <summary>
        /// Retrieves a standard HTTP response header from a REST response, if available.
        /// </summary>
        /// <param name="response">The REST response.</param>
        /// <param name="header">The header to retrieve.</param>
        /// <param name="value">Returns the value for <paramref name="header"/>.</param>
        /// <returns><c>true</c> if the specified header is contained in <paramref name="response"/>, otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="response"/> is <c>null</c>.</exception>
        public static bool TryGetHeader(this Response response, HttpResponseHeader header, out string value)
        {
            if (response == null)
                throw new ArgumentNullException("response");

            if (response.Headers == null)
            {
                value = null;
                return false;
            }

            WebHeaderCollection collection = new RestWebHeaderCollection(response.Headers);
            value = collection[header];
            return value != null;
        }
开发者ID:rajeshXYZ,项目名称:openstack.net,代码行数:23,代码来源:ResponseExtensions.cs


示例10: Process

        public object Process(IHttpServer server, IHttpRequest req, HttpResponseHeader header)
        {
            string accept_encodings;
            if (!req.Headers.TryGetValue (HttpHeaderNames.AcceptEncoding, out accept_encodings))
                accept_encodings = "";
            bool enableGzip = accept_encodings.Contains ("gzip");
            bool enableDeflate = accept_encodings.Contains ("deflate");
            if (enableDeflate) enableGzip = false;
            if (enableGzip) enableDeflate = false;

            object result = _app.Process (server, req, header);
            if (header.Status != HttpStatusCode.OK || !(enableGzip || enableDeflate) || header.ContainsKey (HttpHeaderNames.ContentEncoding)) {
                return result;
            } else {
                byte[] ret;
                int original_size = -1;
                using (MemoryStream ms = new MemoryStream ())
                using (Stream strm = (enableGzip ? (Stream)new GZipStream (ms, CompressionMode.Compress) : (Stream)new DeflateStream (ms, CompressionMode.Compress))) {
                    if (result is string) {
                        byte[] raw = header.Encoding.GetBytes ((string)result);
                        original_size = raw.Length;
                        strm.Write (raw, 0, raw.Length);
                    } else if (result is byte[]) {
                        byte[] raw = (byte[])result;
                        original_size = raw.Length;
                        strm.Write (raw, 0, raw.Length);
                    } else {
                        return result;
                    }
                    strm.Flush ();
                    strm.Close ();
                    ms.Close ();
                    ret = ms.ToArray ();
                }

                if (ret.Length >= original_size) {
                    _logger.Trace ("Bypass compress middleware ({0} is larger than {1})", ret.Length, original_size);
                    return result;
                }

                header[HttpHeaderNames.ContentLength] = ret.Length.ToString ();
                header[HttpHeaderNames.ContentEncoding] = enableGzip ? "gzip" : "deflate";
                _logger.Trace ("Enable {0} compression, size is {1} to {2}",
                    header[HttpHeaderNames.ContentEncoding], original_size, ret.Length);

                return ret;
            }
        }
开发者ID:kazuki,项目名称:httpserver,代码行数:48,代码来源:CompressMiddleware.cs


示例11: InvalidOperationException

 public string this[HttpResponseHeader header]
 {
     get
     {
         if (!AllowHttpResponseHeader)
         {
             throw new InvalidOperationException(SR.net_headers_rsp);
         }
         return this[header.GetName()];
     }
     set
     {
         if (!AllowHttpResponseHeader)
         {
             throw new InvalidOperationException(SR.net_headers_rsp);
         }
         this[header.GetName()] = value;
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:19,代码来源:WebHeaderCollection.cs


示例12: Set

		public void Set (HttpResponseHeader header, string value)
		{
			Set (ResponseHeaderToString (header), value);
		}
开发者ID:carrie901,项目名称:mono,代码行数:4,代码来源:WebHeaderCollection.cs


示例13: Add

		public void Add (HttpResponseHeader header, string value)
		{
			Add (ResponseHeaderToString (header), value);
		}
开发者ID:carrie901,项目名称:mono,代码行数:4,代码来源:WebHeaderCollection.cs


示例14: Remove

		public void Remove (HttpResponseHeader header)
		{
			Remove (ResponseHeaderToString (header));
		}
开发者ID:carrie901,项目名称:mono,代码行数:4,代码来源:WebHeaderCollection.cs


示例15: SetInternal

 internal void SetInternal(HttpResponseHeader header, string value) {
     if (!AllowHttpResponseHeader) {
         throw new InvalidOperationException(SR.GetString(SR.net_headers_rsp));
     }
     if (m_Type==WebHeaderCollectionType.HttpListenerResponse) {
         if (value!=null && value.Length>ushort.MaxValue) {
             throw new ArgumentOutOfRangeException("value", value, SR.GetString(SR.net_headers_toolong, ushort.MaxValue));
         }
     }
     this.SetInternal(UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header), value);
 }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:11,代码来源:WebHeaderCollection.cs


示例16: Remove

 public void Remove(HttpResponseHeader header) {
     if (!AllowHttpResponseHeader) {
         throw new InvalidOperationException(SR.GetString(SR.net_headers_rsp));
     }
     this.Remove(UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header));
 }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:6,代码来源:WebHeaderCollection.cs


示例17: InvalidOperationException

 public string this[HttpResponseHeader header]
 {
     get
     {
         if (!AllowHttpResponseHeader)
         {
             throw new InvalidOperationException(SR.net_headers_rsp);
         }
         return this[header.GetName()];
     }
     set
     {
         if (!AllowHttpResponseHeader)
         {
             throw new InvalidOperationException(SR.net_headers_rsp);
         }
         if (_type == WebHeaderCollectionType.HttpListenerResponse)
         {
             if (value != null && value.Length > ushort.MaxValue)
             {
                 throw new ArgumentOutOfRangeException("value", value, SR.Format(SR.net_headers_toolong, ushort.MaxValue));
             }
         }
         this[header.GetName()] = value;
     }
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:26,代码来源:WebHeaderCollection.cs


示例18: InvalidOperationException

        public string this[HttpResponseHeader header] {
            get {
                if (!AllowHttpResponseHeader) {
                    throw new InvalidOperationException(SR.GetString(SR.net_headers_rsp));
                }

                // Some of these can be mapped to Common Headers.  Other cases can be added as needed for perf.
                if (m_CommonHeaders != null)
                {
                    switch (header)
                    {
                        case HttpResponseHeader.ProxyAuthenticate:
                            return m_CommonHeaders[c_ProxyAuthenticate];

                        case HttpResponseHeader.WwwAuthenticate:
                            return m_CommonHeaders[c_WwwAuthenticate];
                    }
                }

                return this[UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header)];
            }
            set {
                if (!AllowHttpResponseHeader) {
                    throw new InvalidOperationException(SR.GetString(SR.net_headers_rsp));
                }
                if (m_Type==WebHeaderCollectionType.HttpListenerResponse) {
                    if (value!=null && value.Length>ushort.MaxValue) {
                        throw new ArgumentOutOfRangeException("value", value, SR.GetString(SR.net_headers_toolong, ushort.MaxValue));
                    }
                }
                this[UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.ToString((int)header)] = value;
            }
        }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:33,代码来源:WebHeaderCollection.cs


示例19: ProcessStaticFile

        object ProcessStaticFile(IHttpRequest req, HttpResponseHeader res)
        {
            string path = req.Url.AbsolutePath;
            if (path.Contains ("/../"))
                throw new HttpException (HttpStatusCode.BadRequest);
            path = path.Replace ('/', Path.DirectorySeparatorChar).Substring (1);
            path = Path.Combine (DefaultStaticFilePath, path);
            if (!File.Exists (path))
                throw new HttpException (HttpStatusCode.NotFound);
            DateTime lastModified = File.GetLastWriteTimeUtc (path);
            string etag = lastModified.Ticks.ToString ("x");
            res[HttpHeaderNames.ETag] = etag;
            res[HttpHeaderNames.LastModified] = lastModified.ToString ("r");
            if (req.Headers.ContainsKey (HttpHeaderNames.IfNoneMatch) && req.Headers[HttpHeaderNames.IfNoneMatch] == etag)
                throw new HttpException (HttpStatusCode.NotModified);

            res[HttpHeaderNames.ContentType] = MIMEDatabase.GetMIMEType (Path.GetExtension (path));
            bool supportGzip = req.Headers.ContainsKey (HttpHeaderNames.AcceptEncoding) && req.Headers[HttpHeaderNames.AcceptEncoding].Contains("gzip");
            string gzip_path = path + ".gz";
            if (supportGzip && File.Exists (gzip_path) && File.GetLastWriteTimeUtc (gzip_path) >= lastModified) {
                path = gzip_path;
                res[HttpHeaderNames.ContentEncoding] = "gzip";
            }
            using (FileStream strm = new FileStream (path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                byte[] raw = new byte[strm.Length];
                strm.Read (raw, 0, raw.Length);
                return raw;
            }
        }
开发者ID:kazuki,项目名称:p2pncs,代码行数:29,代码来源:WebApp.cs


示例20: Get

		public string this[HttpResponseHeader hrh]
		{
			get
			{
				return Get (ResponseHeaderToString (hrh));
			}

			set
			{
				Add (ResponseHeaderToString (hrh), value);
			}
		}
开发者ID:runefs,项目名称:Marvin,代码行数:12,代码来源:WebHeaderCollection.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# HttpResponseMessage类代码示例发布时间:2022-05-24
下一篇:
C# HttpResponse类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap