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


C# IRequest.CreateResponse方法代码示例

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


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

示例1: OnRequest

        /// <summary>
        /// We've received a HTTP request.
        /// </summary>
        /// <param name="request">HTTP request</param>
        public override void OnRequest(IRequest request)
        {
            var response = request.CreateResponse(HttpStatusCode.OK, "Welcome");
            if (request.Uri.AbsolutePath.Contains("secret"))
            {
                SecretPage(request, response);
                return;
            }

            if (request.Uri.AbsolutePath.EndsWith("MrEinstein.png"))
            {
                response.Body =
                    Assembly.GetExecutingAssembly().GetManifestResourceStream(GetType().Namespace + ".einstein.png");
                response.ContentType = "image/png";
            }
            else
            {
                response.Body = new MemoryStream();
                response.ContentType = "text/html";
                var buffer = Encoding.UTF8.GetBytes(@"<html><head><title>Totally awesome</title></head><body><h1>Hello world</h1><img src=""MrEinstein.png"" /></body></html>");
                response.Body.Write(buffer, 0, buffer.Length);
                response.Body.Position = 0;
            }

            Send(response);
        }
开发者ID:2594636985,项目名称:griffin.networking,代码行数:30,代码来源:MyHttpService.cs

示例2: OnRequest

            public override void OnRequest(IRequest request)
            {
                var response = request.CreateResponse(HttpStatusCode.OK, "Welcome");

                response.Body = new MemoryStream();
                response.ContentType = "text/plain";
                var buffer = Encoding.UTF8.GetBytes(request.RemoteEndPoint.Address.ToString());
                response.Body.Write(buffer, 0, buffer.Length);
                response.Body.Position = 0;

                Send(response);
            }
开发者ID:2594636985,项目名称:griffin.networking,代码行数:12,代码来源:ExampleServerTests.cs

示例3: WeatherRequestAsync

        private async Task WeatherRequestAsync(IRequest request)
        {
            if (request.Message == "Hello")
            {
                IResponse response = request.CreateResponse();

                response.Message = "Hello";
                response.Targets = new[] { request.User.Host.Nick };
                response.Format = request.Format;
                response.Broadcast = request.Broadcast;

                await request.SendResponseAsync(response);
            }
        }
开发者ID:pjmagee,项目名称:NazureBot,代码行数:14,代码来源:WeatherModule.cs

示例4: OnRequest

        public override void OnRequest(IRequest request)
        {
            var response = request.CreateResponse(HttpStatusCode.OK, "Welcome");
            response.KeepAlive = false;

            response.Body = new MemoryStream();
            response.ContentType = "text/plain";
            var buffer = HandleRequest(request.Uri.Query);
            response.Body.Write(buffer, 0, buffer.Length);
            response.Body.Position = 0;

            Send(response);

            dvb.addLog("Sent " + buffer.Length + " Bytes");
        }
开发者ID:bennir,项目名称:DVBControllerServer,代码行数:15,代码来源:DVBService.cs

示例5: OnRequest

        /// <summary>
        /// We've received a HTTP request.
        /// </summary>
        /// <param name="request">HTTP request</param>
        /// <exception cref="System.ArgumentNullException">message</exception>
        public override void OnRequest(IRequest request)
        {
            var context = new WebServer.HttpContext
                {
                    Application = _configuration.Application,
                    Items = new MemoryItemStorage(),
                    Request = request,
                    Response = request.CreateResponse(HttpStatusCode.OK, "Okey dokie")
                };

            context.Response.AddHeader("X-Powered-By",
                                       "Griffin.Networking (http://github.com/jgauffin/griffin.networking)");


            _configuration.ModuleManager.InvokeAsync(context, SendResponse);
        }
开发者ID:namezis,项目名称:Griffin.WebServer,代码行数:21,代码来源:HttpServerWorker.cs

示例6: HandleRangeRequest

        private void HandleRangeRequest(IRequest request)
        {
            var rangeHeader = request.Headers["Range"];
            var response = request.CreateResponse(HttpStatusCode.PartialContent, "Welcome");

            response.ContentType = "application/octet-stream";
            response.AddHeader("Accept-Ranges", "bytes");
            response.AddHeader("Content-Disposition", @"attachment;filename=""ReallyBigFile.Txt""");

            //var fileStream = new FileStream(Environment.CurrentDirectory + @"\Ranges\ReallyBigFile.Txt", FileMode.Open,
            //                                FileAccess.Read, FileShare.ReadWrite);
            var fileStream = new FileStream(@"C:\Users\jgauffin\Downloads\AspNetMVC3ToolsUpdateSetup.exe", FileMode.Open,
                                                FileAccess.Read, FileShare.ReadWrite);
            var ranges = new RangeCollection();
            ranges.Parse(rangeHeader.Value, (int)fileStream.Length);

            response.AddHeader("Content-Range", ranges.ToHtmlHeaderValue((int)fileStream.Length));
            response.Body = new ByteRangeStream(ranges, fileStream);
            Send(response);
        }
开发者ID:samuraitruong,项目名称:comitdownloader,代码行数:20,代码来源:MyHttpService.cs

示例7: Process

        public bool Process(IRequest request, IServerTransaction transaction)
        {
            //12.2.2 UAS Behavior

            //   Requests sent within a dialog, as any other requests, are atomic.  If
            //   a particular request is accepted by the UAS, all the state changes
            //   associated with it are performed.  If the request is rejected, none
            //   of the state changes are performed.

            //      Note that some requests, such as INVITEs, affect several pieces of
            //      state.

            //   The UAS will receive the request from the transaction layer.  If the
            //   request has a tag in the To header field, the UAS core computes the
            //   dialog identifier corresponding to the request and compares it with
            //   existing dialogs.  If there is a match, this is a mid-dialog request.
            //   In that case, the UAS first applies the same processing rules for
            //   requests outside of a dialog, discussed in Section 8.2.

            //   If the request has a tag in the To header field, but the dialog
            //   identifier does not match any existing dialogs, the UAS may have
            //   crashed and restarted, or it may have received a request for a
            //   different (possibly failed) UAS (the UASs can construct the To tags
            //   so that a UAS can identify that the tag was for a UAS for which it is
            //   providing recovery).  Another possibility is that the incoming
            //   request has been simply misrouted.  Based on the To tag, the UAS MAY
            //   either accept or reject the request.  Accepting the request for
            //   acceptable To tags provides robustness, so that dialogs can persist
            //   even through crashes.  UAs wishing to support this capability must
            //   take into consideration some issues such as choosing monotonically
            //   increasing CSeq sequence numbers even across reboots, reconstructing
            //   the route set, and accepting out-of-range RTP timestamps and sequence
            //   numbers.

            string callId = request.CallId;
            string localTag = request.To.Parameters["tag"];
            string remoteTag = request.From.Parameters["tag"];
            if (callId != null && localTag != null && remoteTag != null)
            {
                string dialogId = callId + "-" + localTag + "-" + remoteTag;
                Dialog dialog;
                lock (_dialogs)
                {
                    if (_dialogs.TryGetValue(dialogId, out dialog))
                        return dialog.Process(request);
                }
            }

            if (localTag != null)
            {
                // If the UAS wishes to reject the request because it does not wish to
                // recreate the dialog, it MUST respond to the request with a 481
                // (Call/Transaction Does Not Exist) status code and pass that to the
                // server transaction.
                IResponse response = request.CreateResponse(StatusCode.CallOrTransactionDoesNotExist,
                                                            "Dialog was not found");
                _logger.Warning("Failed to find dialog with to tag: " + localTag);
                transaction.Send(response);
            }
            return false;
        }
开发者ID:jgauffin,项目名称:SipSharp,代码行数:61,代码来源:DialogManager.cs

示例8: Handler

        /// <summary>
        /// The handler.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        private async Task Handler(IRequest request)
        {
            IResponse response = request.CreateResponse();

            if (request.Message.Equals("ping"))
            {
                response.Broadcast = MessageBroadcast.Public;
                response.Format = MessageFormat.Message;
                response.Message = "pong";

                if (request.Broadcast == MessageBroadcast.Public)
                {
                    response.Targets = new[] { request.Channel.Name };
                }

                if (request.Broadcast == MessageBroadcast.Private)
                {
                    response.Targets = new[] { request.User.Host.Nick };
                }
                
                await request.SendResponseAsync(response);
            }
        }
开发者ID:pjmagee,项目名称:NazureBot,代码行数:32,代码来源:PongModule.cs

示例9: ListenerCallback

 private IResponse ListenerCallback(IRequest request)
 {
     var response = request.CreateResponse(System.Net.HttpStatusCode.OK, "OK");
     response.Body = new MemoryStream();
     if (Request == null)
     {
         response.ContentType = "text/plain";
         var writer = new StreamWriter(response.Body);
         writer.WriteLine("No request handler is registered with this HttpServer instance. Set HttpServer.Request to a RequestHandler delegate.");
         writer.Flush();
     }
     else
     {
         try
         {
             if (request.Method == "POST" && !string.IsNullOrEmpty(request.ContentType))
             {
                 var decoder = new CompositeBodyDecoder();
                 decoder.Decode(request);
             }
             if (LogRequests)
                 Log(request);
             Request(request, response);
             if (LogRequests)
                 Log(response);
         }
         catch (Exception e)
         {
             HandleException(e, response);
             if (LogRequests)
                 Console.Write(e);
         }
     }
     response.Body.Position = 0;
     return response;
 }
开发者ID:headdetect,项目名称:WebSharp,代码行数:36,代码来源:HttpServer.cs


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