Skip to content

Commit

Permalink
minimal HTTP memcache proxy in new /memcache endpoint
Browse files Browse the repository at this point in the history
for #1472
  • Loading branch information
snarfed committed Dec 14, 2024
1 parent 6388aab commit 604a7f6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,24 @@ def instance_info():
@flask_util.headers(CACHE_CONTROL)
def log():
return logs.log()


@app.post('/memcache')
def memcache_command():
"""Minimal memcache text protocol command handler.
Requires the Flask app's secret key in the Authorization HTTP header.
Example usage:
curl https://fed.brid.gy/memcache -H 'Authorization: ...' -d 'stats items'
https://docs.memcached.org/protocols/
https://github.com/memcached/memcached/blob/master/doc/protocol.txt
"""
if request.headers.get('Authorization') != app.config['SECRET_KEY']:
return '', 401

resp = common.memcache.raw_command(request.get_data(as_text=True),
end_tokens='END\r\n')
return resp.decode(), {'Content-Type': 'text/plain'}

0 comments on commit 604a7f6

Please sign in to comment.