mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-08-01 02:11:15 -04:00
fix: return 413 when the announcement body exceeds the size cap
Distinguish the http.MaxBytesReader limit from a malformed body: an oversized payload now returns 413 Request Entity Too Large instead of a generic 400.
This commit is contained in:
@@ -170,7 +170,7 @@ var _ = Describe("Service", func() {
|
||||
s := newStore()
|
||||
newService(s, true).Set(resp, req)
|
||||
|
||||
Expect(resp.Code).To(Equal(http.StatusBadRequest))
|
||||
Expect(resp.Code).To(Equal(http.StatusRequestEntityTooLarge))
|
||||
got, _ := s.Get()
|
||||
Expect(got.BannerText).To(BeEmpty())
|
||||
})
|
||||
|
||||
@@ -143,6 +143,11 @@ func (s Service) Set(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var body Announcement
|
||||
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, _maxBodySize)).Decode(&body); err != nil {
|
||||
var maxBytesErr *http.MaxBytesError
|
||||
if errors.As(err, &maxBytesErr) {
|
||||
w.WriteHeader(http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user