mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-12 15:20:41 -06:00
* implement correct Etag and If-None-Match handling, responding with 304 Not Modified if they match * introduce SessionState and State string type aliases to ensure we are using the correct fields for those, respectively * extract the SessionState from the JMAP response bodies in the groupware framework instead of having to do that in every single groupware API * use uint instead of int in some places to clarify that the values are >= 0 * trace-log how long a Session was held in cache before being evicted * add Trace-Id header handling: add to response when specified in request, and implement a custom request logger to include it as a field * implement a more compact trace-logging of all the methods and URIs that are served, to put them into a single log entry instead of creating one log entry for every URI
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package log
|
|
|
|
import "github.com/rs/zerolog"
|
|
|
|
const (
|
|
logMaxStrLength = 512
|
|
logMaxStrArrayLength = 16 // 8kb
|
|
)
|
|
|
|
// Safely caps a string to a given size to avoid log bombing.
|
|
// Use this function to wrap strings that are user input (HTTP headers, path parameters, URI parameters, HTTP body, ...).
|
|
func SafeString(text string) string {
|
|
runes := []rune(text)
|
|
|
|
if len(runes) <= logMaxStrLength {
|
|
return text
|
|
} else {
|
|
return string(runes[0:logMaxStrLength-1]) + `\u2026` // hellip
|
|
}
|
|
}
|
|
|
|
type SafeLogStringArrayMarshaller struct {
|
|
array []string
|
|
}
|
|
|
|
func (m SafeLogStringArrayMarshaller) MarshalZerologArray(a *zerolog.Array) {
|
|
for i, elem := range m.array {
|
|
if i >= logMaxStrArrayLength {
|
|
return
|
|
}
|
|
a.Str(SafeString(elem))
|
|
}
|
|
}
|
|
|
|
var _ zerolog.LogArrayMarshaler = SafeLogStringArrayMarshaller{}
|
|
|
|
func SafeStringArray(array []string) SafeLogStringArrayMarshaller {
|
|
return SafeLogStringArrayMarshaller{array: array}
|
|
}
|
|
|
|
type StringArrayMarshaller struct {
|
|
array []string
|
|
}
|
|
|
|
func (m StringArrayMarshaller) MarshalZerologArray(a *zerolog.Array) {
|
|
for _, elem := range m.array {
|
|
a.Str(elem)
|
|
}
|
|
}
|
|
|
|
var _ zerolog.LogArrayMarshaler = StringArrayMarshaller{}
|
|
|
|
func StringArray(array []string) StringArrayMarshaller {
|
|
return StringArrayMarshaller{array: array}
|
|
}
|
|
|
|
func From(context zerolog.Context) *Logger {
|
|
return &Logger{Logger: context.Logger()}
|
|
}
|