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


C# HttpResponseHeader类代码示例

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


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


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