mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Include Location header in POST /transactions
This commit is contained in:
parent
6cedab47a1
commit
eb791aa2ce
@ -4,7 +4,7 @@ For more information please refer to the documentation: http://bigchaindb.com/ht
|
||||
"""
|
||||
import logging
|
||||
|
||||
from flask import current_app, request
|
||||
from flask import current_app, request, jsonify
|
||||
from flask_restful import Resource, reqparse
|
||||
|
||||
from bigchaindb.common.exceptions import SchemaValidationError, ValidationError
|
||||
@ -87,4 +87,16 @@ class TransactionListApi(Resource):
|
||||
else:
|
||||
bigchain.write_transaction(tx_obj)
|
||||
|
||||
return tx, 202
|
||||
response = jsonify(tx)
|
||||
response.status_code = 202
|
||||
|
||||
# NOTE: According to W3C, sending a relative URI is not allowed in the
|
||||
# Location Header:
|
||||
# - https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
|
||||
#
|
||||
# Flask is autocorrecting relative URIs. With the following command,
|
||||
# we're able to prevent this.
|
||||
response.autocorrect_location_header = False
|
||||
status_monitor = '../statuses?transaction_id={}'.format(tx_obj.id)
|
||||
response.headers['Location'] = status_monitor
|
||||
return response
|
||||
|
@ -68,6 +68,7 @@ Content-Type: application/json
|
||||
|
||||
TPLS['post-tx-response'] = """\
|
||||
HTTP/1.1 202 Accepted
|
||||
Location: ../statuses?transaction_id=%(txid)s
|
||||
Content-Type: application/json
|
||||
|
||||
%(tx)s
|
||||
|
@ -148,6 +148,7 @@ Transactions
|
||||
:language: http
|
||||
|
||||
:resheader Content-Type: ``application/json``
|
||||
:resheader Location: Relative link to a status monitor for the submitted transaction.
|
||||
|
||||
:statuscode 202: The pushed transaction was accepted in the ``BACKLOG``, but the processing has not been completed.
|
||||
:statuscode 400: The transaction was malformed and not accepted in the ``BACKLOG``.
|
||||
|
@ -40,6 +40,9 @@ def test_post_create_transaction_endpoint(b, client):
|
||||
|
||||
assert res.status_code == 202
|
||||
|
||||
assert '../statuses?transaction_id={}'.format(tx.id) in \
|
||||
res.headers['Location']
|
||||
|
||||
assert res.json['inputs'][0]['owners_before'][0] == user_pub
|
||||
assert res.json['outputs'][0]['public_keys'][0] == user_pub
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user