Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
slapos.core
Commits
64fdaffc
Commit
64fdaffc
authored
May 04, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require Accept: application/json header.
parent
28925572
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
3 deletions
+17
-3
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+17
-3
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
64fdaffc
...
...
@@ -39,9 +39,22 @@ import xml_marshaller
import
json
import
transaction
def
requireAcceptApplicationJson
(
fn
):
def
wrapperRequireAcceptApplicationJson
(
self
,
*
args
,
**
kwargs
):
accept
=
self
.
REQUEST
.
getHeader
(
'Accept'
)
if
accept
is
not
None
and
accept
==
'application/json'
:
return
fn
(
self
,
*
args
,
**
kwargs
)
else
:
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
"error"
:
"Accept: application/json header is required"
}))
return
self
.
REQUEST
.
response
wrapperRequireAcceptApplicationJson
.
__doc__
=
fn
.
__doc__
return
wrapperRequireAcceptApplicationJson
def
responseSupport
(
anonymous
=
False
):
def
outer
(
fn
):
def
wrapper
(
self
,
*
args
,
**
kwargs
):
def
wrapper
ResponseSupport
(
self
,
*
args
,
**
kwargs
):
response
=
self
.
REQUEST
.
response
response
.
setHeader
(
'Content-Type'
,
'application/json'
)
response
.
setHeader
(
'Access-Control-Allow-Headers'
,
...
...
@@ -58,8 +71,8 @@ def responseSupport(anonymous=False):
.
portal_preferences
.
getPreferredRestApiV1TokenServerUrl
())
return
response
return
fn
(
self
,
*
args
,
**
kwargs
)
wrapper
.
__doc__
=
fn
.
__doc__
return
wrapper
wrapper
ResponseSupport
.
__doc__
=
fn
.
__doc__
return
wrapper
ResponseSupport
return
outer
class
GenericPublisher
(
Implicit
):
...
...
@@ -143,6 +156,7 @@ class InstancePublisher(GenericPublisher):
return
response
@
responseSupport
()
@
requireAcceptApplicationJson
def
__call__
(
self
):
"""Instance GET/POST support"""
if
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'POST'
:
...
...
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