mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-14 04:07:46 +00:00
* Add redis support for distributed caching * Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! fixup! fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! fixup! fixup! fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! fixup! fixup! fixup! fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * ... and another all nighter. * fixup! ... and another all nighter. * fixup! fixup! ... and another all nighter. * fixup! fixup! fixup! ... and another all nighter. * Resolve issue #85 by adding ability to set custom claims in JWT tokens * Remove redundant validation in auth middleware ( issue #89 ) * Add ability to set cookie prefix for session cookies ( #87 ) * fixup! Add ability to set cookie prefix for session cookies ( #87 ) * Add ability to set cookie max age - issue #91 * Potential fix for code scanning alert no. 10: Size computation for allocation may overflow Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fixup! Merge main into 0.8.0-redis: resolve conflicts --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
158 lines
2.8 KiB
Go
158 lines
2.8 KiB
Go
package server
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"strconv"
|
|
)
|
|
|
|
type Simple string
|
|
|
|
// ErrProtocol is the general error for unexpected input
|
|
var ErrProtocol = errors.New("invalid request")
|
|
|
|
// client always sends arrays with bulk strings
|
|
func readArray(rd *bufio.Reader) ([]string, error) {
|
|
line, err := rd.ReadString('\n')
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(line) < 3 {
|
|
return nil, ErrProtocol
|
|
}
|
|
|
|
switch line[0] {
|
|
default:
|
|
return nil, ErrProtocol
|
|
case '*':
|
|
l, err := strconv.Atoi(line[1 : len(line)-2])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// l can be -1
|
|
var fields []string
|
|
for ; l > 0; l-- {
|
|
s, err := readString(rd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
fields = append(fields, s)
|
|
}
|
|
return fields, nil
|
|
}
|
|
}
|
|
|
|
func readString(rd *bufio.Reader) (string, error) {
|
|
line, err := rd.ReadString('\n')
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if len(line) < 3 {
|
|
return "", ErrProtocol
|
|
}
|
|
|
|
switch line[0] {
|
|
default:
|
|
return "", ErrProtocol
|
|
case '+', '-', ':':
|
|
// +: simple string
|
|
// -: errors
|
|
// :: integer
|
|
// Simple line based replies.
|
|
return string(line[1 : len(line)-2]), nil
|
|
case '$':
|
|
// bulk strings are: `$5\r\nhello\r\n`
|
|
length, err := strconv.Atoi(line[1 : len(line)-2])
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if length < 0 {
|
|
// -1 is a nil response
|
|
return "", nil
|
|
}
|
|
var (
|
|
buf = make([]byte, length+2)
|
|
pos = 0
|
|
)
|
|
for pos < length+2 {
|
|
n, err := rd.Read(buf[pos:])
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
pos += n
|
|
}
|
|
return string(buf[:length]), nil
|
|
}
|
|
}
|
|
|
|
// parse a reply
|
|
func ParseReply(rd *bufio.Reader) (interface{}, error) {
|
|
line, err := rd.ReadString('\n')
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(line) < 3 {
|
|
return nil, ErrProtocol
|
|
}
|
|
|
|
switch line[0] {
|
|
default:
|
|
return nil, ErrProtocol
|
|
case '+':
|
|
// +: simple string
|
|
return Simple(line[1 : len(line)-2]), nil
|
|
case '-':
|
|
// -: errors
|
|
return nil, errors.New(string(line[1 : len(line)-2]))
|
|
case ':':
|
|
// :: integer
|
|
v := line[1 : len(line)-2]
|
|
if v == "" {
|
|
return 0, nil
|
|
}
|
|
n, err := strconv.Atoi(v)
|
|
if err != nil {
|
|
return nil, ErrProtocol
|
|
}
|
|
return n, nil
|
|
case '$':
|
|
// bulk strings are: `$5\r\nhello\r\n`
|
|
length, err := strconv.Atoi(line[1 : len(line)-2])
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if length < 0 {
|
|
// -1 is a nil response
|
|
return nil, nil
|
|
}
|
|
var (
|
|
buf = make([]byte, length+2)
|
|
pos = 0
|
|
)
|
|
for pos < length+2 {
|
|
n, err := rd.Read(buf[pos:])
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
pos += n
|
|
}
|
|
return string(buf[:length]), nil
|
|
case '*':
|
|
// array
|
|
l, err := strconv.Atoi(line[1 : len(line)-2])
|
|
if err != nil {
|
|
return nil, ErrProtocol
|
|
}
|
|
// l can be -1
|
|
var fields []interface{}
|
|
for ; l > 0; l-- {
|
|
s, err := ParseReply(rd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
fields = append(fields, s)
|
|
}
|
|
return fields, nil
|
|
}
|
|
}
|