Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
37786e0e
Commit
37786e0e
authored
Feb 14, 2016
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make IsHTTPHeaderName return error strings
parent
3ad6c397
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
9 deletions
+12
-9
validation.go
pkg/api/validation/validation.go
+2
-2
validation.go
pkg/util/validation/validation.go
+7
-4
validation_test.go
pkg/util/validation/validation_test.go
+3
-3
No files found.
pkg/api/validation/validation.go
View file @
37786e0e
...
...
@@ -1314,8 +1314,8 @@ func validateHTTPGetAction(http *api.HTTPGetAction, fldPath *field.Path) field.E
allErrors
=
append
(
allErrors
,
field
.
NotSupported
(
fldPath
.
Child
(
"scheme"
),
http
.
Scheme
,
supportedHTTPSchemes
.
List
()))
}
for
_
,
header
:=
range
http
.
HTTPHeaders
{
if
!
validation
.
IsHTTPHeaderName
(
header
.
Name
)
{
allErrors
=
append
(
allErrors
,
field
.
Invalid
(
fldPath
.
Child
(
"httpHeaders"
),
header
.
Name
,
fmt
.
Sprintf
(
"name must match %s"
,
validation
.
HTTPHeaderNameFmt
)
))
for
_
,
msg
:=
range
validation
.
IsHTTPHeaderName
(
header
.
Name
)
{
allErrors
=
append
(
allErrors
,
field
.
Invalid
(
fldPath
.
Child
(
"httpHeaders"
),
header
.
Name
,
msg
))
}
}
return
allErrors
...
...
pkg/util/validation/validation.go
View file @
37786e0e
...
...
@@ -234,14 +234,17 @@ func IsValidPercent(percent string) []string {
return
nil
}
const
HTTP
HeaderNameFmt
string
=
"[-A-Za-z0-9]+"
const
http
HeaderNameFmt
string
=
"[-A-Za-z0-9]+"
var
httpHeaderNameRegexp
=
regexp
.
MustCompile
(
"^"
+
HTTP
HeaderNameFmt
+
"$"
)
var
httpHeaderNameRegexp
=
regexp
.
MustCompile
(
"^"
+
http
HeaderNameFmt
+
"$"
)
// IsHTTPHeaderName checks that a string conforms to the Go HTTP library's
// definition of a valid header field name (a stricter subset than RFC7230).
func
IsHTTPHeaderName
(
value
string
)
bool
{
return
httpHeaderNameRegexp
.
MatchString
(
value
)
func
IsHTTPHeaderName
(
value
string
)
[]
string
{
if
!
httpHeaderNameRegexp
.
MatchString
(
value
)
{
return
[]
string
{
RegexError
(
httpHeaderNameFmt
,
"X-Header-Name"
)}
}
return
nil
}
// MaxLenError returns a string explanation of a "string too long" validation
...
...
pkg/util/validation/validation_test.go
View file @
37786e0e
...
...
@@ -321,8 +321,8 @@ func TestIsHTTPHeaderName(t *testing.T) {
"A"
,
"AB"
,
"AbC"
,
"A1"
,
"-A"
,
"A-"
,
"A-B"
,
"A-1"
,
"A--1--2--B"
,
"--123-ABC"
,
}
for
_
,
val
:=
range
goodValues
{
if
!
IsHTTPHeaderName
(
val
)
{
t
.
Errorf
(
"expected true for '%s'
"
,
val
)
if
msgs
:=
IsHTTPHeaderName
(
val
);
len
(
msgs
)
!=
0
{
t
.
Errorf
(
"expected true for '%s'
: %v"
,
val
,
msgs
)
}
}
...
...
@@ -333,7 +333,7 @@ func TestIsHTTPHeaderName(t *testing.T) {
"?"
,
"@"
,
"{"
,
}
for
_
,
val
:=
range
badValues
{
if
IsHTTPHeaderName
(
val
)
{
if
msgs
:=
IsHTTPHeaderName
(
val
);
len
(
msgs
)
==
0
{
t
.
Errorf
(
"expected false for '%s'"
,
val
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment