Skip to content

Commit

Permalink
Update server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gnh1201 authored Mar 6, 2024
1 parent 56c2db1 commit c94125c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,30 @@ def parse_first_data(data):
return parsed_data

def conn_string(conn, data, addr):
# check is it JSON-RPC 2.0 request
if data.find(b'{') == 0:
# JSON-RPC 2.0 request
def process_jsonrpc2(data):
jsondata = json.loads(data.decode(client_encoding, errors='ignore'))
if jsondata['jsonrpc'] == "2.0":
jsonrpc2_server(conn, jsondata['id'], jsondata['method'], jsondata['params'])
return
return True
return False

# JSON-RPC 2.0 request over Socket
if data.find(b'{') == 0 and process_jsonrpc2(data):
# no connection close: wait until the client disconnected
return

# parse first data (header)
webserver, port, scheme, method, url = parse_first_data(data)

# JSON-RPC 2.0 request over HTTP
if url.decode(client_encoding).endswith("/proxy-cgi/jsonrpc2"):
conn.send(b'HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n')
pos = data.find(b'\r\n\r\n')
if pos > -1 and process_jsonrpc2(data[pos+4:]):
conn.close() # connection close: when the request is completed, the server will disconnect
return

# if it is reverse proxy
if local_domain != '':
localserver = local_domain.encode(client_encoding)
Expand Down

0 comments on commit c94125c

Please sign in to comment.