Skip to content

Commit

Permalink
not-found-body: replace \r\n in meta string
Browse files Browse the repository at this point in the history
  • Loading branch information
ninedraft committed Feb 11, 2022
1 parent 601d6d1 commit 2575909
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gemax/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"strings"
"sync"

"github.com/ninedraft/gemax/gemax/internal/bufwriter"
Expand Down Expand Up @@ -36,6 +37,7 @@ func (rw *responseWriter) WriteStatus(code status.Code, meta string) {
if code == status.Success && meta == "" {
meta = MIMEGemtext
}
meta = metaSanitizer.Replace(meta)
_, _ = fmt.Fprintf(rw.writer, "%d %s\r\n", code, meta)
rw.status = code
rw.statusWritten = true
Expand All @@ -44,6 +46,12 @@ func (rw *responseWriter) WriteStatus(code status.Code, meta string) {
}
}

var metaSanitizer = strings.NewReplacer(
"\r\n", "\t",
"\n", "\t",
"\r", "\t",
)

func (rw *responseWriter) Write(data []byte) (int, error) {
if rw.isClosed {
return 0, io.ErrNoProgress
Expand Down

0 comments on commit 2575909

Please sign in to comment.