本文整理汇总了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");
}
}
示例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;
}
示例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;
};
}
示例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;
}