Fix file extension detection; fix HTTPS port

pull/82/head
Philipp Heckel 2022-01-06 14:45:23 +01:00
parent 5eca20469f
commit 9171e94e5a
2 changed files with 8 additions and 7 deletions

View File

@ -293,7 +293,7 @@ func (s *Server) Run() error {
errChan <- s.httpServer.ListenAndServe() errChan <- s.httpServer.ListenAndServe()
}() }()
if s.config.ListenHTTPS != "" { if s.config.ListenHTTPS != "" {
s.httpsServer = &http.Server{Addr: s.config.ListenHTTP, Handler: mux} s.httpsServer = &http.Server{Addr: s.config.ListenHTTPS, Handler: mux}
go func() { go func() {
errChan <- s.httpsServer.ListenAndServeTLS(s.config.CertFile, s.config.KeyFile) errChan <- s.httpsServer.ListenAndServeTLS(s.config.CertFile, s.config.KeyFile)
}() }()
@ -479,7 +479,8 @@ func (s *Server) handlePublish(w http.ResponseWriter, r *http.Request, v *visito
return err return err
} }
m := newDefaultMessage(t.ID, "") m := newDefaultMessage(t.ID, "")
if !body.LimitReached && utf8.Valid(body.PeakedBytes) { filename := readParam(r, "x-filename", "filename", "file", "f")
if filename == "" && !body.LimitReached && utf8.Valid(body.PeakedBytes) {
m.Message = strings.TrimSpace(string(body.PeakedBytes)) m.Message = strings.TrimSpace(string(body.PeakedBytes))
} else if s.config.AttachmentCacheDir != "" { } else if s.config.AttachmentCacheDir != "" {
if err := s.writeAttachment(r, v, m, body); err != nil { if err := s.writeAttachment(r, v, m, body); err != nil {

View File

@ -21,7 +21,7 @@ var (
random = rand.New(rand.NewSource(time.Now().UnixNano())) random = rand.New(rand.NewSource(time.Now().UnixNano()))
randomMutex = sync.Mutex{} randomMutex = sync.Mutex{}
sizeStrRegex = regexp.MustCompile(`(?i)^(\d+)([gmkb])?$`) sizeStrRegex = regexp.MustCompile(`(?i)^(\d+)([gmkb])?$`)
extRegex = regexp.MustCompile(`^\.[-_A-Za-z0-9]+$`)
errInvalidPriority = errors.New("invalid priority") errInvalidPriority = errors.New("invalid priority")
) )
@ -175,7 +175,7 @@ func ExtensionByType(contentType string) string {
return ".jpg" return ".jpg"
default: default:
exts, err := mime.ExtensionsByType(contentType) exts, err := mime.ExtensionsByType(contentType)
if err == nil && len(exts) > 0 { if err == nil && len(exts) > 0 && extRegex.MatchString(exts[0]) {
return exts[0] return exts[0]
} }
return ".bin" return ".bin"