1
0
Fork 0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-06-08 08:16:10 +02:00

Rename (*ResponseWriter).SetMimetype to SetMediaType

This commit is contained in:
Adnan Maolood 2020-11-09 13:44:42 -05:00
parent 9338681256
commit 85f8e84bd5
2 changed files with 10 additions and 10 deletions

4
fs.go
View File

@ -33,7 +33,7 @@ func (fsh fsHandler) Respond(w *ResponseWriter, r *Request) {
// Detect mimetype
ext := path.Ext(p)
mimetype := mime.TypeByExtension(ext)
w.SetMimetype(mimetype)
w.SetMediaType(mimetype)
// Copy file to response writer
io.Copy(w, f)
}
@ -72,7 +72,7 @@ func ServeFile(w *ResponseWriter, fs FS, name string) {
// Detect mimetype
ext := path.Ext(name)
mimetype := mime.TypeByExtension(ext)
w.SetMimetype(mimetype)
w.SetMediaType(mimetype)
// Copy file to response writer
io.Copy(w, f)
}

View File

@ -262,7 +262,7 @@ type ResponseWriter struct {
b *bufio.Writer
bodyAllowed bool
wroteHeader bool
mimetype string
mediatype string
}
func newResponseWriter(conn net.Conn) *ResponseWriter {
@ -301,10 +301,10 @@ func (w *ResponseWriter) WriteStatus(status Status) {
w.WriteHeader(status, status.Message())
}
// SetMimetype sets the mimetype that will be written for a successful response.
// SetMediaType sets the media type that will be written for a successful response.
// If the mimetype is not set, it will default to "text/gemini".
func (w *ResponseWriter) SetMimetype(mimetype string) {
w.mimetype = mimetype
func (w *ResponseWriter) SetMediaType(mediatype string) {
w.mediatype = mediatype
}
// Write writes the response body.
@ -315,11 +315,11 @@ func (w *ResponseWriter) SetMimetype(mimetype string) {
// with StatusSuccess and the mimetype set in SetMimetype.
func (w *ResponseWriter) Write(b []byte) (int, error) {
if !w.wroteHeader {
mimetype := w.mimetype
if mimetype == "" {
mimetype = "text/gemini"
mediatype := w.mediatype
if mediatype == "" {
mediatype = "text/gemini"
}
w.WriteHeader(StatusSuccess, mimetype)
w.WriteHeader(StatusSuccess, mediatype)
}
if !w.bodyAllowed {
return 0, ErrBodyNotAllowed