本文整理匯總了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;
}