Index: trunk/morty.go
===================================================================
--- trunk/morty.go	(revision 8)
+++ trunk/morty.go	(revision 9)
@@ -241,5 +241,5 @@
 }
 
-func sanitizeCSS(rc *RequestConfig, ctx *fasthttp.RequestCtx, css []byte) {
+func sanitizeCSS(rc *RequestConfig, out io.Writer, css []byte) {
 	// TODO
 
@@ -247,5 +247,5 @@
 
 	if urlSlices == nil {
-		ctx.Write(css)
+		out.Write(css)
 		return
 	}
@@ -258,6 +258,6 @@
 
 		if uri, err := proxifyURI(rc, string(css[urlStart:urlEnd])); err == nil {
-			ctx.Write(css[startIndex:urlStart])
-			ctx.Write([]byte(uri))
+			out.Write(css[startIndex:urlStart])
+			out.Write([]byte(uri))
 			startIndex = urlEnd
 		} else {
@@ -266,9 +266,9 @@
 	}
 	if startIndex < len(css) {
-		ctx.Write(css[startIndex:len(css)])
-	}
-}
-
-func sanitizeHTML(rc *RequestConfig, ctx *fasthttp.RequestCtx, htmlDoc []byte) {
+		out.Write(css[startIndex:len(css)])
+	}
+}
+
+func sanitizeHTML(rc *RequestConfig, out io.Writer, htmlDoc []byte) {
 	r := bytes.NewReader(htmlDoc)
 	decoder := html.NewTokenizer(r)
@@ -307,5 +307,5 @@
 				}
 				var attrs [][][]byte
-				fmt.Fprintf(ctx, "<%s", tag)
+				fmt.Fprintf(out, "<%s", tag)
 				if hasAttrs {
 					for {
@@ -317,13 +317,13 @@
 					}
 					if bytes.Equal(tag, []byte("meta")) {
-						sanitizeMetaAttrs(rc, ctx, attrs)
+						sanitizeMetaAttrs(rc, out, attrs)
 					} else {
-						sanitizeAttrs(rc, ctx, attrs)
+						sanitizeAttrs(rc, out, attrs)
 					}
 				}
 				if token == html.SelfClosingTagToken {
-					fmt.Fprintf(ctx, " />")
+					fmt.Fprintf(out, " />")
 				} else {
-					fmt.Fprintf(ctx, ">")
+					fmt.Fprintf(out, ">")
 					if bytes.Equal(tag, []byte("style")) {
 						state = STATE_IN_STYLE
@@ -347,5 +347,5 @@
 						key = hash(urlStr, rc.Key)
 					}
-					fmt.Fprintf(ctx, HTML_FORM_EXTENSION, urlStr, key)
+					fmt.Fprintf(out, HTML_FORM_EXTENSION, urlStr, key)
 
 				}
@@ -356,5 +356,5 @@
 				switch string(tag) {
 				case "body":
-					fmt.Fprintf(ctx, HTML_BODY_EXTENSION, rc.baseURL.String())
+					fmt.Fprintf(out, HTML_BODY_EXTENSION, rc.baseURL.String())
 				case "style":
 					state = STATE_DEFAULT
@@ -365,5 +365,5 @@
 				// skip noscript tags - only the tag, not the content, because javascript is sanitized
 				if writeEndTag {
-					fmt.Fprintf(ctx, "</%s>", tag)
+					fmt.Fprintf(out, "</%s>", tag)
 				}
 
@@ -371,13 +371,13 @@
 				switch state {
 				case STATE_DEFAULT:
-					fmt.Fprintf(ctx, "%s", decoder.Raw())
+					fmt.Fprintf(out, "%s", decoder.Raw())
 				case STATE_IN_STYLE:
-					sanitizeCSS(rc, ctx, decoder.Raw())
+					sanitizeCSS(rc, out, decoder.Raw())
 				case STATE_IN_NOSCRIPT:
-					sanitizeHTML(rc, ctx, decoder.Raw())
+					sanitizeHTML(rc, out, decoder.Raw())
 				}
 
 			case html.DoctypeToken, html.CommentToken:
-				ctx.Write(decoder.Raw())
+				out.Write(decoder.Raw())
 			}
 		} else {
@@ -399,5 +399,5 @@
 }
 
-func sanitizeMetaAttrs(rc *RequestConfig, ctx *fasthttp.RequestCtx, attrs [][][]byte) {
+func sanitizeMetaAttrs(rc *RequestConfig, out io.Writer, attrs [][][]byte) {
 	var http_equiv []byte
 	var content []byte
@@ -417,21 +417,21 @@
 		parts := bytes.SplitN(content, []byte(";url="), 2)
 		if uri, err := proxifyURI(rc, string(parts[1])); err == nil {
-			fmt.Fprintf(ctx, ` http-equiv="refresh" content="%s;%s"`, parts[0], uri)
+			fmt.Fprintf(out, ` http-equiv="refresh" content="%s;%s"`, parts[0], uri)
 		}
 	} else {
-		sanitizeAttrs(rc, ctx, attrs)
-	}
-
-}
-
-func sanitizeAttrs(rc *RequestConfig, ctx *fasthttp.RequestCtx, attrs [][][]byte) {
+		sanitizeAttrs(rc, out, attrs)
+	}
+
+}
+
+func sanitizeAttrs(rc *RequestConfig, out io.Writer, attrs [][][]byte) {
 	for _, attr := range attrs {
-		sanitizeAttr(rc, ctx, attr[0], attr[1])
-	}
-}
-
-func sanitizeAttr(rc *RequestConfig, ctx *fasthttp.RequestCtx, attrName, attrValue []byte) {
+		sanitizeAttr(rc, out, attr[0], attr[1])
+	}
+}
+
+func sanitizeAttr(rc *RequestConfig, out io.Writer, attrName, attrValue []byte) {
 	if inArray(attrName, SAFE_ATTRIBUTES) {
-		fmt.Fprintf(ctx, " %s=\"%s\"", attrName, attrValue)
+		fmt.Fprintf(out, " %s=\"%s\"", attrName, attrValue)
 		return
 	}
@@ -439,12 +439,12 @@
 	case "src", "href", "action":
 		if uri, err := proxifyURI(rc, string(attrValue)); err == nil {
-			fmt.Fprintf(ctx, " %s=\"%s\"", attrName, uri)
+			fmt.Fprintf(out, " %s=\"%s\"", attrName, uri)
 		} else {
 			log.Println("cannot proxify uri:", attrValue)
 		}
 	case "style":
-		fmt.Fprintf(ctx, " %s=\"", attrName)
-		sanitizeCSS(rc, ctx, attrValue)
-		ctx.Write([]byte("\""))
+		fmt.Fprintf(out, " %s=\"", attrName)
+		sanitizeCSS(rc, out, attrValue)
+		out.Write([]byte("\""))
 	}
 }
