from bottle import Bottle, response, request
import bottle
from bottle.ext import beaker
from bottle import redirect, request, response, route, run, static_file, error
from bottle import Bottle, get, ServerAdapter
from bottle.ext import beaker
#app = Bottle()
app = beaker.middleware.SessionMiddleware(bottle.app())
def enable_cors(fn):
def _enable_cors(*args, **kwargs):
# set CORS headers
response.headers['Access-Control-Allow-Origin'] = '100.200.100.500,100.300.100.400' # not working
response.headers[
'Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers[
'Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type,' \
' X-Requested-With, X-CSRF-Token'
response.add_header('Server', ' ') # not able to make changes
response.set_header('Server', ' ') # not able to make changes
if request.method != 'OPTIONS':
# actual request; reply with the actual response
return fn(*args, **kwargs)
return _enable_cors
@route('/about', method=['OPTIONS', 'GET', 'POST'], strict_slash=True)
@enable_cors
def about():
response.headers['content_type'] = 'text/ttt' # able to make changes
response.headers['Server'] = ' ' # not able to make changes
response.server = ' '
print "request :: ",dict(request.headers)
print response.iter_headers()
#return HTTPResponse(content_type = 'text/plain', body="Tell me about yourself.")
return "Tell me about yourself."
if __name__ == '__main__':
#bottle.run(host='localhost', port=5010, debug=True, server='paste')
#app.run(host='localhost', port=5010, debug=True, server='paste')
run(app=app, host='100.200.100.500', port=8080, debug=True, server='paste')
问题::
有什么帮助吗?