implement running options

This commit is contained in:
csehviktor
2025-08-01 22:01:43 +02:00
parent aed36d860d
commit a9e46f5fcf
3 changed files with 32 additions and 12 deletions

View File

@@ -10,18 +10,29 @@ import (
)
type HttpHandler struct {
store *store.MemoryStore
store *store.MemoryStore
maxSize int64
}
func NewHandler(store *store.MemoryStore) *HttpHandler {
func NewHandler(store *store.MemoryStore, maxSize int64) *HttpHandler {
return &HttpHandler{
store: store,
store,
maxSize,
}
}
func (h *HttpHandler) HandleSet(w http.ResponseWriter, r *http.Request) {
// form body request looks like:
// content=...
// so +8 additional bytes must be included
r.Body = http.MaxBytesReader(w, r.Body, h.maxSize+8)
if err := r.ParseForm(); err != nil {
badRequest("invalid bin", err, w, r)
if strings.Contains(err.Error(), "request body too large") {
badRequest("content too large", nil, w, r)
} else {
badRequest("invalid form data", err, w, r)
}
return
}
@@ -31,6 +42,8 @@ func (h *HttpHandler) HandleSet(w http.ResponseWriter, r *http.Request) {
return
}
//fmt.Println(len(content))
id, err := generateId()
if err != nil {
internal("could not generate id", err, w, r)