@marcel91200 / caddy Mirror · read-only / commits / be3849c2
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

Remove markdown module

Matthew Holt committed Dec 23, 2019 at 12:55 UTC be3849c2671e74c461e1885d3a15e7e97b967895
2 files changed -89
modules/caddyhttp/markdown/markdown.go deleted
-88
@@ -1,88 +0,0 @@
1 -// Copyright 2015 Matthew Holt and The Caddy Authors
2 -//
3 -// Licensed under the Apache License, Version 2.0 (the "License");
4 -// you may not use this file except in compliance with the License.
5 -// You may obtain a copy of the License at
6 -//
7 -// http://www.apache.org/licenses/LICENSE-2.0
8 -//
9 -// Unless required by applicable law or agreed to in writing, software
10 -// distributed under the License is distributed on an "AS IS" BASIS,
11 -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 -// See the License for the specific language governing permissions and
13 -// limitations under the License.
14 -
15 -package markdown
16 -
17 -import (
18 - "bytes"
19 - "net/http"
20 - "strconv"
21 - "strings"
22 - "sync"
23 -
24 - "github.com/russross/blackfriday/v2"
25 -
26 - "github.com/caddyserver/caddy/v2"
27 - "github.com/caddyserver/caddy/v2/modules/caddyhttp"
28 -)
29 -
30 -func init() {
31 - caddy.RegisterModule(Markdown{})
32 -}
33 -
34 -// Markdown is a middleware for rendering a Markdown response body.
35 -type Markdown struct {
36 -}
37 -
38 -// CaddyModule returns the Caddy module information.
39 -func (Markdown) CaddyModule() caddy.ModuleInfo {
40 - return caddy.ModuleInfo{
41 - ID: "http.handlers.markdown",
42 - New: func() caddy.Module { return new(Markdown) },
43 - }
44 -}
45 -
46 -func (m Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
47 - buf := bufPool.Get().(*bytes.Buffer)
48 - buf.Reset()
49 - defer bufPool.Put(buf)
50 -
51 - shouldBuf := func(status int, header http.Header) bool {
52 - return strings.HasPrefix(header.Get("Content-Type"), "text/")
53 - }
54 -
55 - rec := caddyhttp.NewResponseRecorder(w, buf, shouldBuf)
56 -
57 - err := next.ServeHTTP(rec, r)
58 - if err != nil {
59 - return err
60 - }
61 - if !rec.Buffered() {
62 - return nil
63 - }
64 -
65 - caddyhttp.CopyHeader(w.Header(), rec.Header())
66 -
67 - output := blackfriday.Run(buf.Bytes())
68 -
69 - w.Header().Set("Content-Length", strconv.Itoa(len(output)))
70 - w.Header().Set("Content-Type", "text/html; charset=utf-8")
71 - w.Header().Del("Accept-Ranges") // we don't know ranges for dynamically-created content
72 - w.Header().Del("Etag") // don't know a way to quickly generate etag for dynamic content
73 - w.Header().Del("Last-Modified") // useless for dynamic content since it's always changing
74 -
75 - w.WriteHeader(rec.Status())
76 - w.Write(output)
77 -
78 - return nil
79 -}
80 -
81 -var bufPool = sync.Pool{
82 - New: func() interface{} {
83 - return new(bytes.Buffer)
84 - },
85 -}
86 -
87 -// Interface guard
88 -var _ caddyhttp.MiddlewareHandler = (*Markdown)(nil)
modules/caddyhttp/standard/imports.go
-1
@@ -11,7 +11,6 @@ import (
11 _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver"
12 _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/headers"
13 _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/httpcache"
14 - _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/markdown"
14 _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/requestbody"
15 _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy"
16 _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi"