ЛР3 - БВТ2304 - Кораблев - на 5 #14

Closed
Sh1pYe wants to merge 2 commits from Sh1pYe/mtusi2026lab3:solution/BVT2304-korablev into main
2 changed files with 9 additions and 3 deletions
Showing only changes of commit 71a79c3d86 - Show all commits
+1 -1
View File
@@ -12,7 +12,7 @@ def write(name, value):
if path.exists():
print('keep secrets/' + name)
return path.read_text().strip()
path.write_text(value + '\n', newline='\n')
path.write_bytes((value + '\n').encode('utf-8'))
print('created secrets/' + name)
return value
+8 -2
View File
@@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/json"
"errors"
"io"
"mime"
"net/http"
"regexp"
@@ -60,8 +61,13 @@ func decodeJSON(w http.ResponseWriter, r *http.Request, dst any) *apperr.AppErro
}
return apperr.InvalidRequest("malformed JSON body")
}
if dec.More() {
return apperr.InvalidRequest("multiple JSON documents in body")
var extra json.RawMessage
if err := dec.Decode(&extra); err != io.EOF {
var maxErr *http.MaxBytesError
if errors.As(err, &maxErr) {
return apperr.PayloadTooLarge("request body too large")
}
return apperr.InvalidRequest("malformed JSON body")
}
return nil
}