本文整理汇总了C#中IHttpContext.WriteHeaders方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.WriteHeaders方法的具体用法?C# IHttpContext.WriteHeaders怎么用?C# IHttpContext.WriteHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.WriteHeaders方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Respond
public override void Respond(IHttpContext context)
{
var match = urlMatcher.Match(context.GetRequestUrl());
var filename = match.Groups[1].Value;
var etag = context.GetEtag();
switch (context.Request.HttpMethod)
{
case "GET":
Database.TransactionalStorage.Batch(_=> // have to keep the session open for reading of the attachment stream
{
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteHeaders(attachmentAndHeaders.Metadata, attachmentAndHeaders.Etag);
using (var stream = attachmentAndHeaders.Data())
{
stream.CopyTo(context.Response.OutputStream);
}
});
break;
case "HEAD":
Database.TransactionalStorage.Batch(_ => // have to keep the session open for reading of the attachment stream
{
var attachmentAndHeaders = Database.GetStatic(filename);
if (attachmentAndHeaders == null)
{
context.SetStatusToNotFound();
return;
}
if (context.MatchEtag(attachmentAndHeaders.Etag))
{
context.SetStatusToNotModified();
return;
}
context.WriteHeaders(attachmentAndHeaders.Metadata, attachmentAndHeaders.Etag);
context.Response.ContentLength64 = attachmentAndHeaders.Size;
});
break;
case "PUT":
var newEtag = Database.PutStatic(filename, context.GetEtag(), context.Request.InputStream,
context.Request.Headers.FilterHeaders(isServerDocument:false));
context.WriteETag(newEtag);
context.SetStatusToCreated("/static/" + filename);
break;
case "DELETE":
Database.DeleteStatic(filename, etag);
context.SetStatusToDeleted();
break;
}
}
示例2: Respond
public override void Respond(IHttpContext context)
{
if (EnsureSystemDatabase(context) == false)
return;
// This responder is NOT secured, and anyone can access it.
// Because of that, we need to provide explicit security here.
// Anonymous Access - All / Get / Admin
// Show all dbs
// Anonymous Access - None
// Show only the db that you have access to (read / read-write / admin)
// If admin, show all dbs
List<string> approvedDatabases = null;
var databases = Database.GetDocumentsWithIdStartingWith("Raven/Databases/", null, null, context.GetStart(),
context.GetPageSize(Database.Configuration.MaxPageSize),
CancellationToken.None);
var data = databases
.Select(x => x.Value<RavenJObject>("@metadata").Value<string>("@id").Replace("Raven/Databases/", string.Empty))
.ToArray();
if (server.SystemConfiguration.AnonymousUserAccessMode == AnonymousUserAccessMode.None)
{
var user = server.RequestAuthorizer.GetUser(context);
if(user == null)
{
return;
}
if (user.IsAdministrator(server.SystemConfiguration.AnonymousUserAccessMode) == false)
{
approvedDatabases = server.RequestAuthorizer.GetApprovedDatabases(user, context, data);
}
}
Etag lastDocEtag = Etag.Empty;
Database.TransactionalStorage.Batch(accessor =>
{
lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
});
if (context.MatchEtag(lastDocEtag))
{
context.SetStatusToNotModified();
}
else
{
context.WriteHeaders(new RavenJObject(), lastDocEtag);
if(approvedDatabases != null)
{
data = data.Where(s => approvedDatabases.Contains(s)).ToArray();
}
context.WriteJson(data);
}
}
示例3: Respond
public override void Respond(IHttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
long documentsCount = 0;
Etag lastDocEtag = Etag.Empty;
Database.TransactionalStorage.Batch(accessor =>
{
lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
documentsCount = accessor.Documents.GetDocumentsCount();
});
lastDocEtag = lastDocEtag.HashWith(BitConverter.GetBytes(documentsCount));
if (context.MatchEtag(lastDocEtag))
{
context.SetStatusToNotModified();
}
else
{
context.WriteHeaders(new RavenJObject(), lastDocEtag);
using (var cts = new CancellationTokenSource())
{
cts.TimeoutAfter(Settings.DatbaseOperationTimeout);
var startsWith = context.Request.QueryString["startsWith"];
if (string.IsNullOrEmpty(startsWith))
context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString(), cts.Token));
else
context.WriteJson(Database.GetDocumentsWithIdStartingWith(
startsWith,
context.Request.QueryString["matches"],
context.Request.QueryString["exclude"],
context.GetStart(),
context.GetPageSize(Database.Configuration.MaxPageSize),
cts.Token));
}
}
break;
case "POST":
var json = context.ReadJson();
var id = Database.Put(null, Etag.Empty, json,
context.Request.Headers.FilterHeaders(),
GetRequestTransaction(context));
context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
context.WriteJson(id);
break;
}
}
示例4: Respond
public override void Respond(IHttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
long documentsCount = 0;
Guid lastDocEtag = Guid.Empty;
Database.TransactionalStorage.Batch(accessor =>
{
lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
documentsCount = accessor.Documents.GetDocumentsCount();
});
var array = lastDocEtag.ToByteArray().Concat(BitConverter.GetBytes(documentsCount)).ToArray();
using (var md5 = MD5.Create())
{
var hashed = md5.ComputeHash(array);
lastDocEtag = new Guid(hashed);
}
if (context.MatchEtag(lastDocEtag))
{
context.SetStatusToNotModified();
}
else
{
context.WriteHeaders(new RavenJObject(), lastDocEtag);
var startsWith = context.Request.QueryString["startsWith"];
if (string.IsNullOrEmpty(startsWith))
context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString()));
else
context.WriteJson(Database.GetDocumentsWithIdStartingWith(
startsWith,
context.Request.QueryString["matches"],
context.GetStart(),
context.GetPageSize(Database.Configuration.MaxPageSize)));
}
break;
case "POST":
var json = context.ReadJson();
var id = Database.Put(null, Guid.Empty, json,
context.Request.Headers.FilterHeaders(),
GetRequestTransaction(context));
context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
context.WriteJson(id);
break;
}
}
示例5: Respond
public override void Respond(IHttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
Guid lastDocEtag = Guid.Empty;
Database.TransactionalStorage.Batch(accessor =>
{
lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
});
if (context.MatchEtag(lastDocEtag))
{
context.SetStatusToNotModified();
}
else
{
context.WriteHeaders(new RavenJObject(), lastDocEtag);
var startsWith = context.Request.QueryString["startsWith"];
if (string.IsNullOrEmpty(startsWith))
context.WriteJson(Database.GetDocuments(context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize), context.GetEtagFromQueryString()));
else
context.WriteJson(Database.GetDocumentsWithIdStartingWith(
startsWith,
context.Request.QueryString["matches"],
context.GetStart(),
context.GetPageSize(Database.Configuration.MaxPageSize)));
}
break;
case "POST":
var json = context.ReadJson();
var id = Database.Put(null, Guid.Empty, json,
context.Request.Headers.FilterHeaders(),
GetRequestTransaction(context));
context.SetStatusToCreated("/docs/" + Uri.EscapeUriString(id.Key));
context.WriteJson(id);
break;
}
}
示例6: Respond
public override void Respond(IHttpContext context)
{
switch (context.Request.HttpMethod)
{
case "GET":
Guid lastDocEtag = Guid.Empty;
Database.TransactionalStorage.Batch(accessor =>
{
lastDocEtag = accessor.Staleness.GetMostRecentDocumentEtag();
});
if (context.MatchEtag(lastDocEtag))
{
context.SetStatusToNotModified();
}
else
{
context.WriteHeaders(new RavenJObject(), lastDocEtag);
context.WriteJson(Database.GetDocumentsWithIdStartingWith("Raven/Databases/", null, context.GetStart(), context.GetPageSize(Database.Configuration.MaxPageSize)));
}
break;
}
}
示例7: Head
private void Head(IHttpContext context, string docId)
{
context.Response.AddHeader("Content-Type", "application/json; charset=utf-8");
var transactionInformation = GetRequestTransaction(context);
var documentMetadata = Database.GetDocumentMetadata(docId, transactionInformation);
if (documentMetadata == null)
{
context.SetStatusToNotFound();
return;
}
Debug.Assert(documentMetadata.Etag != null);
if (context.MatchEtag(documentMetadata.Etag.Value))
{
context.SetStatusToNotModified();
return;
}
if (documentMetadata.NonAuthoritiveInformation != null && documentMetadata.NonAuthoritiveInformation.Value)
{
context.SetStatusToNonAuthoritiveInformation();
}
context.WriteHeaders(documentMetadata.Metadata, documentMetadata.Etag.Value);
}
示例8: Head
private void Head(IHttpContext context, string docId)
{
context.Response.AddHeader("Content-Type", "application/json; charset=utf-8");
var transactionInformation = GetRequestTransaction(context);
var documentMetadata = Database.GetDocumentMetadata(docId, transactionInformation);
if (documentMetadata == null)
{
context.SetStatusToNotFound();
return;
}
Debug.Assert(documentMetadata.Etag != null);
if (context.MatchEtag(documentMetadata.Etag.Value) && documentMetadata.NonAuthoritativeInformation == false)
{
context.SetStatusToNotModified();
return;
}
if (documentMetadata.NonAuthoritativeInformation != null && documentMetadata.NonAuthoritativeInformation.Value)
{
context.SetStatusToNonAuthoritativeInformation();
}
documentMetadata.Metadata[Constants.LastModified] = documentMetadata.LastModified; //HACK ? to get the document's last modified value into the response headers
context.WriteHeaders(documentMetadata.Metadata, documentMetadata.Etag.Value);
}