/// <summary> /// Processes a HEAD operation /// </summary> /// <param name="context">HTTP Context</param> public override void ProcessHead(IHttpContext context) { //Work out the Graph URI we want to get Uri graphUri = this.ResolveGraphUri(context); try { bool exists = this.HasGraph(graphUri); if (exists) { //Send the Content Type we'd select based on the Accept header to the user String ctype; IRdfWriter writer = MimeTypesHelper.GetWriter(HandlerHelper.GetAcceptTypes(context), out ctype); context.Response.ContentType = ctype; } else { context.Response.StatusCode = (int)HttpStatusCode.NotFound; } } catch (RdfQueryException) { //If the GetGraph() method errors this implies that the Store does not contain the Graph //In such a case we should return a 404 context.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } }
/// <summary> /// Sends the given Graph to the Client via the HTTP Response /// </summary> /// <param name="context">HTTP Context</param> /// <param name="g">Graph to send</param> protected void SendResultsToClient(HttpContext context, IGraph g) { IRdfWriter writer; String ctype; //Look up the MIME Type Definition - if none use GetWriter instead MimeTypeDefinition definition = MimeTypesHelper.GetDefinitions(HandlerHelper.GetAcceptTypes(context)).FirstOrDefault(d => d.CanWriteRdf); if (definition != null) { writer = definition.GetRdfWriter(); ctype = definition.CanonicalMimeType; } else { writer = MimeTypesHelper.GetWriter(HandlerHelper.GetAcceptTypes(context), out ctype); } //Set up the Writer if (writer is ICompressingWriter) { ((ICompressingWriter)writer).CompressionLevel = Options.DefaultCompressionLevel; } //Send Content to Client context.Response.ContentType = ctype; if (definition != null) { context.Response.ContentEncoding = definition.Encoding; writer.Save(g, new StreamWriter(context.Response.OutputStream, definition.Encoding)); } else { writer.Save(g, new StreamWriter(context.Response.OutputStream)); } }