[~] Refactor
This commit is contained in:
parent
f99cf5d304
commit
e2bbae5b99
@ -1056,12 +1056,25 @@ def http_server(argv):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
parser.add_option(
|
||||||
|
'--token',
|
||||||
|
dest='token',
|
||||||
|
type=str,
|
||||||
|
default=None,
|
||||||
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
'--port',
|
'--port',
|
||||||
dest='port',
|
dest='port',
|
||||||
type='int',
|
type='int',
|
||||||
default=80,
|
default=80,
|
||||||
)
|
)
|
||||||
|
parser.add_option(
|
||||||
|
'-H', '--header',
|
||||||
|
dest='response_headers',
|
||||||
|
type='str',
|
||||||
|
action='append',
|
||||||
|
default=[],
|
||||||
|
)
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
'--host',
|
'--host',
|
||||||
dest='host',
|
dest='host',
|
||||||
@ -1092,17 +1105,29 @@ def http_server(argv):
|
|||||||
if options.public:
|
if options.public:
|
||||||
location_section = 'location / {%s}' % index_section
|
location_section = 'location / {%s}' % index_section
|
||||||
else:
|
else:
|
||||||
token = os.urandom(16).hex()
|
if options.token is None:
|
||||||
|
options.token = os.urandom(16).hex()
|
||||||
|
|
||||||
if not options.prefix is None:
|
if not options.prefix is None:
|
||||||
token = options.prefix + token
|
path = options.prefix + options.token
|
||||||
|
else:
|
||||||
|
path = options.token
|
||||||
|
|
||||||
print(
|
print(
|
||||||
'access url is http://%s:%d/%s/' % (
|
'access url is http://%s:%d/%s/' % (
|
||||||
options.host,
|
options.host,
|
||||||
options.port,
|
options.port,
|
||||||
token,
|
path,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert all([
|
||||||
|
not re.compile(
|
||||||
|
r'^[A-Za-z-]+ [a-z0-9A-Z-\.]+$'
|
||||||
|
).match(o) is None
|
||||||
|
for o in options.response_headers
|
||||||
|
])
|
||||||
|
|
||||||
location_section = (
|
location_section = (
|
||||||
'location / {'
|
'location / {'
|
||||||
'deny all;'
|
'deny all;'
|
||||||
@ -1110,8 +1135,16 @@ def http_server(argv):
|
|||||||
'location /%s/ {'
|
'location /%s/ {'
|
||||||
'alias /app/;'
|
'alias /app/;'
|
||||||
'%s'
|
'%s'
|
||||||
|
'%s'
|
||||||
'}'
|
'}'
|
||||||
) % (token, index_section)
|
) % (
|
||||||
|
path,
|
||||||
|
'\n'.join([
|
||||||
|
'add_header %s;' % o
|
||||||
|
for o in options.response_headers
|
||||||
|
]),
|
||||||
|
index_section
|
||||||
|
)
|
||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
r'''
|
r'''
|
||||||
sudo docker run \
|
sudo docker run \
|
||||||
|
Loading…
Reference in New Issue
Block a user