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


C# Response.WithHeader方法代码示例

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


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

示例1: UpdateResponseHeaders

 private static void UpdateResponseHeaders(Request request, Response response, CorsConfiguration corsConfiguration)
 {
     if (!request.Headers.Keys.Contains("Origin")) return;
     response.WithHeader("Access-Control-Allow-Origin", corsConfiguration.AllowOrigin);
     if (request.Method.Equals("OPTIONS"))
     {
         response
             .WithHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS")
             .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type");
     }
 }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:11,代码来源:CorsPipelinesExtension.cs

示例2: AddObject

        private Response AddObject(string bucket, string key, Stream stream)
        {
            if (Request.Url.Query == "?acl")
              {
            return new Response { StatusCode = HttpStatusCode.OK };
              }

              var content = stream.Copy(configuration.MaxBytesPerSecond);

              var s3Object = new S3Object
              {
            Bucket = bucket,
            Key = key,
            ContentType = Request.Headers.ContentType,
            CreationDate = DateTime.UtcNow,
            Content = () => content,
            ContentMD5 = content.GenerateMD5CheckSum(),
            Size = content.Length
              };

              storage.AddObject(s3Object);

              var response = new Response { StatusCode = HttpStatusCode.OK };
              response.WithHeader("ETag", string.Format("\"{0}\"", s3Object.ContentMD5));
              return response;
        }
开发者ID:yadazula,项目名称:S3Emulator,代码行数:26,代码来源:S3ObjectModule.cs

示例3: HelloModule

        public HelloModule()
        {
            Get["/"] = parameters => "Hello World";

            Get["/text/stop_code={stop_code}"] = parameters => "Your stop code is " + parameters.stop_code;

            Get["/stop_code={stop_code}"] = parameters =>
            {
                BusStopCreator busStopCreator = new BusStopCreator();

                //Create busstop
                BusStop busStop = busStopCreator.CreateBusStop(parameters.stop_code.ToString());

                string str = JsonConvert.SerializeObject(busStop.BusStopInstance);
                var jsonBytes = Encoding.UTF8.GetBytes(str);
                return new Response
                {
                    ContentType = "application/json",
                    Contents = s => s.Write(jsonBytes, 0, jsonBytes.Length)
                };

            };
            Get["/bus_stops"] = _ =>
            {
                List<SimpleBusStop> busStopList = new List<SimpleBusStop>();
                StopList stopList = new StopList();

                var allstops = stopList.AllStops;

                foreach (var stop in allstops)
                {
                    var busstop = new SimpleBusStop(stop.stop_code, stop.stop_id, stop.stop_lat.ToString(), stop.stop_lon.ToString());
                    busStopList.Add(busstop);
                }

                string str = JsonConvert.SerializeObject(busStopList);
                var jsonBytes = Encoding.UTF8.GetBytes(str);
                var resp = new Response();
                resp.ContentType = "application/json";
                resp.Contents = s => s.Write(jsonBytes, 0, jsonBytes.Length);
                resp.WithHeader("Access-Control-Allow-Origin", "*");
                return resp;
            };
        }
开发者ID:AaronYeoh,项目名称:Hack1337s,代码行数:44,代码来源:Main.cs

示例4: GetObject

        private Response GetObject(string bucket, string key)
        {
            var s3Object = storage.GetObject(bucket, key);
              if (s3Object == null)
              {
            return new Response { StatusCode = HttpStatusCode.NotFound };
              }

              var stream = s3Object.Content();

              var response = new Response { StatusCode = HttpStatusCode.OK, ContentType = s3Object.ContentType };
              response.WithHeader("ETag", string.Format("\"{0}\"", s3Object.ContentMD5));
              response.WithHeader("Accept-Ranges", "bytes");
              response.Contents = x =>
              {
            var throttledStream = new ThrottledStream(stream, configuration.MaxBytesPerSecond);
            throttledStream.CopyTo(x);
              };

              return response;
        }
开发者ID:yadazula,项目名称:S3Emulator,代码行数:21,代码来源:S3ObjectModule.cs


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