Skip to content

Commit a1c3e8a

Browse files
committed
handler: reduce allocations
1 parent ed8c0d1 commit a1c3e8a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

handler/handler.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,22 @@ func (a *BasicHMACAuthHandler) Run(input io.Reader, output io.Writer) error {
3333
emitter := proto.NewResponseEmitter(output)
3434

3535
for scanner.Scan() {
36-
parts := bytes.SplitN(scanner.Bytes(), []byte{' '}, 4)
37-
if len(parts) < 3 {
38-
err := fmt.Errorf("bad request line sent to auth helper: %q", string(scanner.Bytes()))
39-
return err
36+
line := scanner.Bytes()
37+
38+
before, after, found := bytes.Cut(line, []byte{' '})
39+
if !found {
40+
return fmt.Errorf("bad request line sent to auth helper: %q", line)
41+
}
42+
channelID := before
43+
44+
before, after, found = bytes.Cut(after, []byte{' '})
45+
if !found {
46+
return fmt.Errorf("bad request line sent to auth helper: %q", line)
4047
}
41-
channelID := parts[0]
42-
username := proto.RFC1738Unescape(parts[1])
43-
password := proto.RFC1738Unescape(parts[2])
48+
username := proto.RFC1738Unescape(before)
49+
50+
before, _, _ = bytes.Cut(after, []byte{' '})
51+
password := proto.RFC1738Unescape(before)
4452

4553
if verifier.VerifyLoginAndPassword(username, password) {
4654
if err := emitter.EmitOK(channelID); err != nil {

0 commit comments

Comments
 (0)