GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — simplehttpserver/pkg/httpserver/pythonliststyle.go at main · projectdiscovery/simplehttpserver Expand file tree/ Copy pathpythonliststyle.goMore file actions 97 lines (85 loc) · 2.14 KB / Copy pathpythonliststyle.goFile metadata and controls97 lines (85 loc) · 2.14 KB 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 package httpserver import ( "bytes" "fmt" "io" "net/http" "os" "path/filepath" ) const ( preTag = "<pre>" preTagClose = "</pre>" aTag = "<a" htmlHeader = `<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Directory listing for %s</title> </head> <body> ` htmlFooter = `<hr> </body> </html> ` ) type pythonStyleHandler struct { origWriter http.ResponseWriter root http.Dir } func (h *pythonStyleHandler) Header() http.Header { return h.origWriter.Header() } func (h *pythonStyleHandler) writeListItem(b []byte, written *int) { var i int i, _ = fmt.Fprint(h.origWriter, "<li>") *written += i i, _ = h.origWriter.Write(bytes.Trim(b, "\r\n")) *written += i i, _ = fmt.Fprint(h.origWriter, "</li>\n") *written += i } func (h *pythonStyleHandler) Write(b []byte) (int, error) { var i int written := 0 if bytes.HasPrefix(b, []byte(preTag)) { _, _ = io.Discard.Write(b) i, _ = fmt.Fprintln(h.origWriter, "<ul>") written += i return written, nil } if bytes.HasPrefix(b, []byte(preTagClose)) { _, _ = io.Discard.Write(b) i, _ = fmt.Fprintln(h.origWriter, "</ul>") written += i return written, nil } if bytes.HasPrefix(b, []byte(aTag)) { h.writeListItem(b, &written) } return i, nil } func (h *pythonStyleHandler) WriteHeader(statusCode int) { h.origWriter.WriteHeader(statusCode) } func (h *pythonStyleHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { target := filepath.Join(string(h.root), filepath.Clean(request.URL.Path)) file, err := os.Stat(target) if err != nil || !file.IsDir() { http.ServeFile(writer, request, target) return } else { _, _ = fmt.Fprintf(writer, htmlHeader, request.URL.Path) _, _ = fmt.Fprintf(writer, "<h1>Directory listing for %s</h1>\n<hr>\n", request.URL.Path) h.origWriter = writer http.ServeFile(h, request, target) _, _ = fmt.Fprint(writer, htmlFooter) } } func PythonStyle(root http.Dir) http.Handler { return &pythonStyleHandler{ root: root, } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |