Skip to content

Commit

Permalink
Merge #1685: ob-watcher.py: Redirect back to / after `/refreshorder…
Browse files Browse the repository at this point in the history
…book` and `/rotateOb`

8798b8b Redirect back to / after /refreshorderbook and /rotateOb (Kristaps Kaupe)

Pull request description:

  Fixes #1684.

Top commit has no ACKs.

Tree-SHA512: 3f4ff430888e3cc200ab956ffc84321d54d59ebde69b49dc78ca7534833e0bb06131a6216dfa1791e3ee2998019de5ec58d0f18e03b2efc6e0b02cea3e26ca47
  • Loading branch information
kristapsk committed May 10, 2024
2 parents 2a10899 + 8798b8b commit bc8f499
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions scripts/obwatch/ob-watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,21 @@ def do_GET(self):
self.end_headers()
self.wfile.write(orderbook_page.encode('utf-8'))

def get_url_base(self) -> str:
# This is to handle the case where the server is behind a reverse proxy
# and base path may not be /.
# First we get HTTP or HTTPS protocol from Origin header and then use
# Host header to get the base path.
# Will work with nginx config like this:
# location /ob-watcher {
# rewrite /ob-watcher/(.*) /$1 break;
# proxy_pass http://localhost:62601;
# proxy_set_header Host $host/ob-watcher;
# }
is_https = self.headers.get('Origin', '').startswith('https://')
host = self.headers.get('Host', '')
return 'https://' + host if is_https else 'http://' + host

def do_POST(self):
global filtered_offername_list
pages = ['/refreshorderbook', '/rotateOb']
Expand All @@ -713,17 +728,19 @@ def do_POST(self):
self.taker.db.execute("DELETE FROM fidelitybonds;")
self.taker.msgchan.request_orderbook()
time.sleep(5)
self.path = '/'
self.do_GET()
self.send_response(302)
self.send_header('Location', self.get_url_base() + '/')
self.end_headers()
elif self.path == '/rotateOb':
if filtered_offername_list == sw0offers:
log.debug('Showing nested segwit orderbook')
filtered_offername_list = swoffers
elif filtered_offername_list == swoffers:
log.debug('Showing native segwit orderbook')
filtered_offername_list = sw0offers
self.path = '/'
self.do_GET()
self.send_response(302)
self.send_header('Location', self.get_url_base() + '/')
self.end_headers()

class HTTPDThread(threading.Thread):
def __init__(self, taker, hostport):
Expand Down

0 comments on commit bc8f499

Please sign in to comment.