mirror of
https://github.com/skidoodle/safebin.git
synced 2026-04-28 03:07:41 +02:00
fix: relax chunk limits, support proxies, optimize reads
Signed-off-by: skidoodle <contact@albert.lol>
This commit is contained in:
@@ -22,6 +22,7 @@ const (
|
||||
ShutdownTimeout = 10 * time.Second
|
||||
|
||||
UploadChunkSize = 8 << 20
|
||||
MinChunkSize = 1 << 20
|
||||
MaxRequestOverhead = 10 << 20
|
||||
PermUserRWX = 0o700
|
||||
MegaByte = 1 << 20
|
||||
|
||||
@@ -72,9 +72,12 @@ func (app *App) RespondWithLink(writer http.ResponseWriter, request *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
scheme := "https"
|
||||
if request.TLS == nil {
|
||||
scheme = "http"
|
||||
scheme := request.Header.Get("X-Forwarded-Proto")
|
||||
if scheme == "" {
|
||||
scheme = "https"
|
||||
if request.TLS == nil {
|
||||
scheme = "http"
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprintf(writer, "%s://%s\n", scheme, link); err != nil {
|
||||
|
||||
@@ -112,7 +112,7 @@ func (app *App) HandleChunk(writer http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
maxChunks := int((app.Conf.MaxMB*MegaByte)/UploadChunkSize) + ChunkSafetyMargin
|
||||
maxChunks := int((app.Conf.MaxMB*MegaByte)/MinChunkSize) + ChunkSafetyMargin
|
||||
|
||||
if !reUploadID.MatchString(uid) || idx > maxChunks || idx < 0 {
|
||||
app.SendError(writer, request, http.StatusBadRequest)
|
||||
@@ -148,7 +148,7 @@ func (app *App) HandleFinish(writer http.ResponseWriter, request *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
maxChunks := int((app.Conf.MaxMB*MegaByte)/UploadChunkSize) + ChunkSafetyMargin
|
||||
maxChunks := int((app.Conf.MaxMB*MegaByte)/MinChunkSize) + ChunkSafetyMargin
|
||||
|
||||
if !reUploadID.MatchString(uid) || total > maxChunks || total <= 0 {
|
||||
app.SendError(writer, request, http.StatusBadRequest)
|
||||
|
||||
Reference in New Issue
Block a user