-
Notifications
You must be signed in to change notification settings - Fork 49
/
SassAndCoffeeHandler.cs
53 lines (46 loc) · 1.44 KB
/
SassAndCoffeeHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Net;
using System.Text;
using SassAndCoffee.Core;
using System.Web;
namespace RequestReduce.SassLessCoffee
{
public abstract class SassAndCoffeeHandler : IHttpHandler
{
private readonly IContentPipeline pipeline;
protected SassAndCoffeeHandler(IContentPipeline pipeline)
{
this.pipeline = pipeline;
}
public void ProcessRequest(HttpContext context)
{
ProcessRequest(new HttpContextWrapper(context));
}
public void ProcessRequest(HttpContextBase context)
{
var request = context.Request;
var response = context.Response;
try
{
var result = pipeline.ProcessRequest(request.PhysicalPath);
if (result == null)
{
response.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
response.ContentEncoding = Encoding.UTF8;
response.ContentType = result.MimeType;
response.Write(result.Content);
}
catch (Exception ex)
{
response.StatusCode = 500;
response.Write("/* Error in compiling: " + ex + " */");
}
}
public bool IsReusable
{
get { return true; }
}
}
}