mirror of
https://github.com/aler9/rtsp-simple-server
synced 2026-04-22 23:17:11 +08:00
caeccdceff
impose a maximum size on body of incoming HTTP requests and responses.
49 lines
959 B
Go
49 lines
959 B
Go
package api //nolint:revive
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/conf"
|
|
"github.com/bluenviron/mediamtx/internal/conf/jsonwrapper"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (a *API) onConfigGlobalGet(ctx *gin.Context) {
|
|
a.mutex.RLock()
|
|
c := a.Conf
|
|
a.mutex.RUnlock()
|
|
|
|
ctx.JSON(http.StatusOK, c.Global())
|
|
}
|
|
|
|
func (a *API) onConfigGlobalPatch(ctx *gin.Context) {
|
|
var c conf.OptionalGlobal
|
|
err := jsonwrapper.Decode(io.LimitReader(ctx.Request.Body, maxInboundConfigSize), &c)
|
|
if err != nil {
|
|
a.writeError(ctx, http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
|
|
a.mutex.Lock()
|
|
defer a.mutex.Unlock()
|
|
|
|
newConf := a.Conf.Clone()
|
|
|
|
newConf.PatchGlobal(&c)
|
|
|
|
err = newConf.Validate(nil)
|
|
if err != nil {
|
|
a.writeError(ctx, http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
|
|
a.Conf = newConf
|
|
|
|
// since reloading the configuration can cause the shutdown of the API,
|
|
// call it in a goroutine
|
|
go a.Parent.APIConfigSet(newConf)
|
|
|
|
a.writeOK(ctx)
|
|
}
|