-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlambda-server.py
More file actions
32 lines (27 loc) · 838 Bytes
/
lambda-server.py
File metadata and controls
32 lines (27 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from io import BytesIO
import base64
import gzip
import random
def gzip_b64encode(data):
compressed = BytesIO()
with gzip.GzipFile(fileobj=compressed, mode='w') as f:
f.write(data.encode('utf-8'))
return base64.b64encode(compressed.getvalue()).decode('ascii')
def lambda_handler(event, context):
with open("index.html") as file:
response=file.read()
with open("wordlist.txt") as words:
wordlist=words.read().splitlines()
random.shuffle(wordlist)
wordlist=wordlist[:50]
response=response.replace("REPLACEME"," ".join(wordlist))
return {
'isBase64Encoded': True,
'statusCode': 200,
'headers':{
'Content-Type': 'text/html',
'Content-Encoding': 'gzip',
'Access-Control-Allow-Origin': '*'
},
'body': gzip_b64encode(response)
}