Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
ee889e99
authored
2014-02-22 14:40:18 +0800
by
slene
Committed by
asta.xie
2014-03-12 15:56:04 +0800
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
skip cookie args when value is nil
1 parent
d8b9db8d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
6 deletions
context/output.go
context/output.go
View file @
ee889e9
...
...
@@ -98,38 +98,56 @@ func (output *BeegoOutput) Cookie(name string, value string, others ...interface
}
}
}
// the settings below
// Path, Domain, Secure, HttpOnly
// can use nil skip set
// default "/"
if
len
(
others
)
>
1
{
if
v
,
ok
:=
others
[
1
]
.
(
string
);
ok
&&
len
(
v
)
>
0
{
fmt
.
Fprintf
(
&
b
,
"; Path=%s"
,
sanitizeValue
(
v
))
}
else
{
fmt
.
Fprintf
(
&
b
,
"; Path=%s"
,
'/'
)
}
}
else
{
fmt
.
Fprintf
(
&
b
,
"; Path=%s"
,
"/"
)
}
// default empty
if
len
(
others
)
>
2
{
if
v
,
ok
:=
others
[
2
]
.
(
string
);
ok
&&
len
(
v
)
>
0
{
fmt
.
Fprintf
(
&
b
,
"; Domain=%s"
,
sanitizeValue
(
v
))
}
}
// default empty
if
len
(
others
)
>
3
{
var
secure
bool
switch
v
:=
others
[
3
]
.
(
type
)
{
case
bool
:
secure
=
v
default
:
secure
=
true
if
others
[
3
]
!=
nil
{
secure
=
true
}
}
if
secure
{
fmt
.
Fprintf
(
&
b
,
"; Secure"
)
}
}
// default true
httponly
:=
true
if
len
(
others
)
>
4
{
if
v
,
ok
:=
others
[
4
]
.
(
bool
);
ok
&&
!
v
{
if
v
,
ok
:=
others
[
4
]
.
(
bool
);
ok
&&
!
v
||
others
[
4
]
==
nil
{
// HttpOnly = false
}
else
{
fmt
.
Fprintf
(
&
b
,
"; HttpOnly"
)
httponly
=
false
}
}
if
httponly
{
fmt
.
Fprintf
(
&
b
,
"; HttpOnly"
)
}
output
.
Context
.
ResponseWriter
.
Header
()
.
Add
(
"Set-Cookie"
,
b
.
String
())
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment