Skip to content

Commit 689ed1c

Browse files
committed
Handle response header
committer: Ralf Schlatterbeck <[email protected]>
1 parent bc818b6 commit 689ed1c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

roundup/rest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,14 @@ def post_collection(self, class_name, input):
139139
except (TypeError, IndexError, ValueError), message:
140140
raise UsageError(message)
141141

142+
# set the header Location
143+
link = self.base_path + class_name + item_id
144+
self.client.setHeader("Location", link)
145+
146+
# set the response body
142147
result = {
143148
'id': item_id,
144-
'link': self.base_path + class_name + item_id
149+
'link': link
145150
}
146151
return 201, result
147152

@@ -225,6 +230,14 @@ def dispatch(self, method, uri, input):
225230
# 2 - attribute
226231
resource_uri = uri.split("/")[1]
227232

233+
self.client.setHeader("Access-Control-Allow-Methods",
234+
"HEAD, OPTIONS, GET, POST, PUT, DELETE, PATCH")
235+
self.client.setHeader("Access-Control-Allow-Headers",
236+
"Content-Type, Authorization,"
237+
"X-HTTP-Method-Override")
238+
self.client.setHeader("Allow",
239+
"HEAD, OPTIONS, GET, POST, PUT, DELETE, PATCH")
240+
228241
output = None
229242
try:
230243
if resource_uri in self.db.classes:
@@ -264,9 +277,9 @@ def dispatch(self, method, uri, input):
264277
print 'EXCEPTION AT', time.ctime()
265278
traceback.print_exc()
266279
finally:
280+
self.client.setHeader("Content-Type", "application/json")
267281
output = RoundupJSONEncoder().encode(output)
268282

269-
print "Length: %s - Content(50 char): %s" % (len(output), output[:50])
270283
return output
271284

272285

0 commit comments

Comments
 (0)