Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
8ea59e8c
Commit
8ea59e8c
authored
Jan 29, 2014
by
Romeo Theriault
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix following redirects
parent
8065bdfb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
12 deletions
+24
-12
library/network/uri
+24
-12
No files found.
library/network/uri
View file @
8ea59e8c
...
...
@@ -87,10 +87,15 @@ options:
default: "no"
follow_redirects:
description:
- Whether or not the URI module should follow all redirects.
- Whether or not the URI module should follow redirects. C(all) will follow all redirects.
C(safe) will follow only "safe" redirects, where "safe" means that the client is only
doing a GET or HEAD on the URI to which it is being redirected. C(none) will not follow
any redirects. Note that C(yes) and C(no) choices are accepted for backwards compatibility,
where C(yes) is the equivalent of C(all) and C(no) is the equivalent of C(safe). C(yes) and C(no)
are deprecated and will be removed in some future version of Ansible.
required: false
choices: [ "
yes", "no
" ]
default: "
no
"
choices: [ "
all", "safe", "none
" ]
default: "
safe
"
creates:
description:
- a filename, when it already exists, this step will not be run.
...
...
@@ -231,9 +236,21 @@ def uri(module, url, dest, user, password, body, method, headers, redirects, soc
# To debug
#httplib2.debug = 4
# Handle Redirects
if
redirects
==
"all"
or
redirects
==
"yes"
:
follow_redirects
=
True
follow_all_redirects
=
True
elif
redirects
==
"none"
:
follow_redirects
=
False
follow_all_redirects
=
False
else
:
follow_redirects
=
True
follow_all_redirects
=
False
# Create a Http object and set some default options.
h
=
httplib2
.
Http
(
disable_ssl_certificate_validation
=
True
,
timeout
=
socket_timeout
)
h
.
follow_all_redirects
=
redirects
h
.
follow_all_redirects
=
follow_all_redirects
h
.
follow_redirects
=
follow_redirects
h
.
forward_authorization_headers
=
True
# If they have a username or password verify they have both, then add them to the request
...
...
@@ -272,7 +289,7 @@ def uri(module, url, dest, user, password, body, method, headers, redirects, soc
headers
[
'If-Modified-Since'
]
=
tstamp
# do safe redirects now, including 307
h
.
follow_redirects
=
True
h
.
follow_redirects
=
follow_redirects
# Make the request, or try to :)
try
:
...
...
@@ -312,7 +329,7 @@ def main():
method
=
dict
(
required
=
False
,
default
=
'GET'
,
choices
=
[
'GET'
,
'POST'
,
'PUT'
,
'HEAD'
,
'DELETE'
,
'OPTIONS'
]),
return_content
=
dict
(
required
=
False
,
default
=
'no'
,
type
=
'bool'
),
force_basic_auth
=
dict
(
required
=
False
,
default
=
'no'
,
type
=
'bool'
),
follow_redirects
=
dict
(
required
=
False
,
default
=
'
no'
,
type
=
'bool'
),
follow_redirects
=
dict
(
required
=
False
,
default
=
'
safe'
,
choices
=
[
'all'
,
'safe'
,
'none'
,
'yes'
,
'no'
]
),
creates
=
dict
(
required
=
False
,
default
=
None
),
removes
=
dict
(
required
=
False
,
default
=
None
),
status_code
=
dict
(
required
=
False
,
default
=
200
,
type
=
'int'
),
...
...
@@ -335,7 +352,7 @@ def main():
dest
=
module
.
params
[
'dest'
]
return_content
=
module
.
params
[
'return_content'
]
force_basic_auth
=
module
.
params
[
'force_basic_auth'
]
follow_
redirects
=
module
.
params
[
'follow_redirects'
]
redirects
=
module
.
params
[
'follow_redirects'
]
creates
=
module
.
params
[
'creates'
]
removes
=
module
.
params
[
'removes'
]
status_code
=
int
(
module
.
params
[
'status_code'
])
...
...
@@ -372,11 +389,6 @@ def main():
if
force_basic_auth
:
dict_headers
[
"Authorization"
]
=
"Basic {0}"
.
format
(
base64
.
b64encode
(
"{0}:{1}"
.
format
(
user
,
password
)))
# Redirects
if
follow_redirects
:
redirects
=
True
else
:
redirects
=
False
# Make the request
resp
,
content
,
dest
=
uri
(
module
,
url
,
dest
,
user
,
password
,
body
,
method
,
dict_headers
,
redirects
,
socket_timeout
)
...
...
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