Python's json module doesn't like to encode bytes instances.
This makes this code difficult to work with Python 3.
We simply swap in Mercurial's JSON encoder to work around it.
pulkit |
hg-reviewers |
Python's json module doesn't like to encode bytes instances.
This makes this code difficult to work with Python 3.
We simply swap in Mercurial's JSON encoder to work around it.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
from . import ( | from . import ( | ||||
discovery, | discovery, | ||||
encoding, | encoding, | ||||
error, | error, | ||||
match as matchmod, | match as matchmod, | ||||
narrowspec, | narrowspec, | ||||
pycompat, | pycompat, | ||||
streamclone, | streamclone, | ||||
templatefilters, | |||||
util, | util, | ||||
wireprotoframing, | wireprotoframing, | ||||
wireprototypes, | wireprototypes, | ||||
) | ) | ||||
from .utils import ( | from .utils import ( | ||||
cborutil, | cborutil, | ||||
interfaceutil, | interfaceutil, | ||||
stringutil, | stringutil, | ||||
This special endpoint can be used to help debug the wire protocol. | This special endpoint can be used to help debug the wire protocol. | ||||
Instead of routing the request through the normal dispatch mechanism, | Instead of routing the request through the normal dispatch mechanism, | ||||
we instead read all frames, decode them, and feed them into our state | we instead read all frames, decode them, and feed them into our state | ||||
tracker. We then dump the log of all that activity back out to the | tracker. We then dump the log of all that activity back out to the | ||||
client. | client. | ||||
""" | """ | ||||
import json | |||||
# Reflection APIs have a history of being abused, accidentally disclosing | # Reflection APIs have a history of being abused, accidentally disclosing | ||||
# sensitive data, etc. So we have a config knob. | # sensitive data, etc. So we have a config knob. | ||||
if not ui.configbool('experimental', 'web.api.debugreflect'): | if not ui.configbool('experimental', 'web.api.debugreflect'): | ||||
res.status = b'404 Not Found' | res.status = b'404 Not Found' | ||||
res.headers[b'Content-Type'] = b'text/plain' | res.headers[b'Content-Type'] = b'text/plain' | ||||
res.setbodybytes(_('debugreflect service not available')) | res.setbodybytes(_('debugreflect service not available')) | ||||
return | return | ||||
states.append(b'received: <no frame>') | states.append(b'received: <no frame>') | ||||
break | break | ||||
states.append(b'received: %d %d %d %s' % (frame.typeid, frame.flags, | states.append(b'received: %d %d %d %s' % (frame.typeid, frame.flags, | ||||
frame.requestid, | frame.requestid, | ||||
frame.payload)) | frame.payload)) | ||||
action, meta = reactor.onframerecv(frame) | action, meta = reactor.onframerecv(frame) | ||||
states.append(json.dumps((action, meta), sort_keys=True, | states.append(templatefilters.json((action, meta))) | ||||
separators=(', ', ': '))) | |||||
action, meta = reactor.oninputeof() | action, meta = reactor.oninputeof() | ||||
meta['action'] = action | meta['action'] = action | ||||
states.append(json.dumps(meta, sort_keys=True, separators=(', ',': '))) | states.append(templatefilters.json(meta)) | ||||
res.status = b'200 OK' | res.status = b'200 OK' | ||||
res.headers[b'Content-Type'] = b'text/plain' | res.headers[b'Content-Type'] = b'text/plain' | ||||
res.setbodybytes(b'\n'.join(states)) | res.setbodybytes(b'\n'.join(states)) | ||||
def _processhttpv2request(ui, repo, req, res, authedperm, reqcommand, proto): | def _processhttpv2request(ui, repo, req, res, authedperm, reqcommand, proto): | ||||
"""Post-validation handler for HTTPv2 requests. | """Post-validation handler for HTTPv2 requests. | ||||