Browse Source

Merge JoinMarket-Org/joinmarket-clientserver#1685: ob-watcher.py: Redirect back to `/` after `/refreshorderbook` and `/rotateOb`

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

Pull request description:

  Fixes #1684.

Top commit has no ACKs.

Tree-SHA512: 3f4ff430888e3cc200ab956ffc84321d54d59ebde69b49dc78ca7534833e0bb06131a6216dfa1791e3ee2998019de5ec58d0f18e03b2efc6e0b02cea3e26ca47
master
Kristaps Kaupe 2 years ago
parent
commit
bc8f499fd2
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 25
      scripts/obwatch/ob-watcher.py

25
scripts/obwatch/ob-watcher.py

@ -702,6 +702,21 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler):
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']
@ -713,8 +728,9 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler):
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')
@ -722,8 +738,9 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler):
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):

Loading…
Cancel
Save