Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
9a583323
Commit
9a583323
authored
Aug 20, 2014
by
smallfish
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SetBasicAuth function for HTTP Auth
parent
ff9c8d94
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
httplib.go
httplib/httplib.go
+6
-0
httplib_test.go
httplib/httplib_test.go
+12
-0
No files found.
httplib/httplib.go
View file @
9a583323
...
@@ -147,6 +147,12 @@ func (b *BeegoHttpRequest) Setting(setting BeegoHttpSettings) *BeegoHttpRequest
...
@@ -147,6 +147,12 @@ func (b *BeegoHttpRequest) Setting(setting BeegoHttpSettings) *BeegoHttpRequest
return
b
return
b
}
}
// SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func
(
b
*
BeegoHttpRequest
)
SetBasicAuth
(
username
,
password
string
)
*
BeegoHttpRequest
{
b
.
req
.
SetBasicAuth
(
username
,
password
)
return
b
}
// SetEnableCookie sets enable/disable cookiejar
// SetEnableCookie sets enable/disable cookiejar
func
(
b
*
BeegoHttpRequest
)
SetEnableCookie
(
enable
bool
)
*
BeegoHttpRequest
{
func
(
b
*
BeegoHttpRequest
)
SetEnableCookie
(
enable
bool
)
*
BeegoHttpRequest
{
b
.
setting
.
EnableCookie
=
enable
b
.
setting
.
EnableCookie
=
enable
...
...
httplib/httplib_test.go
View file @
9a583323
...
@@ -120,6 +120,18 @@ func TestWithCookie(t *testing.T) {
...
@@ -120,6 +120,18 @@ func TestWithCookie(t *testing.T) {
}
}
}
}
func
TestWithBasicAuth
(
t
*
testing
.
T
)
{
str
,
err
:=
Get
(
"http://httpbin.org/basic-auth/user/passwd"
)
.
SetBasicAuth
(
"user"
,
"passwd"
)
.
String
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
t
.
Log
(
str
)
n
:=
strings
.
Index
(
str
,
"authenticated"
)
if
n
==
-
1
{
t
.
Fatal
(
"authenticated not found in response"
)
}
}
func
TestWithUserAgent
(
t
*
testing
.
T
)
{
func
TestWithUserAgent
(
t
*
testing
.
T
)
{
v
:=
"beego"
v
:=
"beego"
str
,
err
:=
Get
(
"http://httpbin.org/headers"
)
.
SetUserAgent
(
v
)
.
String
()
str
,
err
:=
Get
(
"http://httpbin.org/headers"
)
.
SetUserAgent
(
v
)
.
String
()
...
...
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