Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created November 20, 2013 19:51
Show Gist options
  • Save thecodejunkie/7569861 to your computer and use it in GitHub Desktop.
Save thecodejunkie/7569861 to your computer and use it in GitHub Desktop.
Sample IResponseProcessor that enables you to return an ordinary response for text/html requests, using the Negotiator.WithMediaRangeModel method
public class ResponseResponseProcessor : IResponseProcessor
{
public IEnumerable<Tuple<string, MediaRange>> ExtensionMappings
{
get
{
return Enumerable.Empty<Tuple<string, MediaRange>>();
}
}
public ProcessorMatch CanProcess(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
return new ProcessorMatch
{
ModelResult = (model is Response) ? MatchResult.ExactMatch : MatchResult.NoMatch,
RequestedContentTypeResult = (requestedMediaRange == "text/html") ? MatchResult.ExactMatch : MatchResult.NoMatch
};
}
public Response Process(MediaRange requestedMediaRange, dynamic model, NancyContext context)
{
return (Response)model;
}
}
return Negotiator.WithMediaRangeModel("text/html", Response.Redirect("/"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment