Skip to content

Commit

Permalink
refactor(uri): move cookie name validator to httpcookie package
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Mar 1, 2023
1 parent 91049af commit 3a0d414
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions internal/httpcookie/httpcookie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package httpcookie contains some utilities to validate cookie values.
package httpcookie
5 changes: 3 additions & 2 deletions uri/cookie_valid.go → internal/httpcookie/valid.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package uri
package httpcookie

import (
"strings"
Expand All @@ -11,7 +11,8 @@ import (

// Copied from https://github.com/golang/go/blob/bb8f9a6ae66d742cb67b4ad444179905a537de00/src/net/http/cookie.go#L463

func isCookieNameValid(raw string) bool {
// IsCookieNameValid returns true, if cookie name is invalid.
func IsCookieNameValid(raw string) bool {
if raw == "" {
return false
}
Expand Down
6 changes: 4 additions & 2 deletions uri/cookie_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"net/http"

"github.com/go-faster/errors"

"github.com/ogen-go/ogen/internal/httpcookie"
)

type CookieEncoder struct {
Expand All @@ -22,8 +24,8 @@ type CookieParameterEncodingConfig struct {
}

func (e *CookieEncoder) EncodeParam(cfg CookieParameterEncodingConfig, f func(Encoder) error) error {
if !isCookieNameValid(cfg.Name) {
return errors.Errorf("invalid cookie name %q", cfg.Name)
if name := cfg.Name; !httpcookie.IsCookieNameValid(name) {
return errors.Errorf("invalid cookie name %q", name)
}
p := &cookieParamEncoder{
receiver: newReceiver(),
Expand Down

0 comments on commit 3a0d414

Please sign in to comment.