當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。