mercurial/wireprotov2server.py
changeset 41403 e82288a9556c
parent 41377 e053053ceba7
child 41840 d6569f1e9b37
equal deleted inserted replaced
41402:4f0aca2b8c21 41403:e82288a9556c
    21     error,
    21     error,
    22     match as matchmod,
    22     match as matchmod,
    23     narrowspec,
    23     narrowspec,
    24     pycompat,
    24     pycompat,
    25     streamclone,
    25     streamclone,
       
    26     templatefilters,
    26     util,
    27     util,
    27     wireprotoframing,
    28     wireprotoframing,
    28     wireprototypes,
    29     wireprototypes,
    29 )
    30 )
    30 from .utils import (
    31 from .utils import (
   146     Instead of routing the request through the normal dispatch mechanism,
   147     Instead of routing the request through the normal dispatch mechanism,
   147     we instead read all frames, decode them, and feed them into our state
   148     we instead read all frames, decode them, and feed them into our state
   148     tracker. We then dump the log of all that activity back out to the
   149     tracker. We then dump the log of all that activity back out to the
   149     client.
   150     client.
   150     """
   151     """
   151     import json
       
   152 
       
   153     # Reflection APIs have a history of being abused, accidentally disclosing
   152     # Reflection APIs have a history of being abused, accidentally disclosing
   154     # sensitive data, etc. So we have a config knob.
   153     # sensitive data, etc. So we have a config knob.
   155     if not ui.configbool('experimental', 'web.api.debugreflect'):
   154     if not ui.configbool('experimental', 'web.api.debugreflect'):
   156         res.status = b'404 Not Found'
   155         res.status = b'404 Not Found'
   157         res.headers[b'Content-Type'] = b'text/plain'
   156         res.headers[b'Content-Type'] = b'text/plain'
   173         states.append(b'received: %d %d %d %s' % (frame.typeid, frame.flags,
   172         states.append(b'received: %d %d %d %s' % (frame.typeid, frame.flags,
   174                                                   frame.requestid,
   173                                                   frame.requestid,
   175                                                   frame.payload))
   174                                                   frame.payload))
   176 
   175 
   177         action, meta = reactor.onframerecv(frame)
   176         action, meta = reactor.onframerecv(frame)
   178         states.append(json.dumps((action, meta), sort_keys=True,
   177         states.append(templatefilters.json((action, meta)))
   179                                  separators=(', ', ': ')))
       
   180 
   178 
   181     action, meta = reactor.oninputeof()
   179     action, meta = reactor.oninputeof()
   182     meta['action'] = action
   180     meta['action'] = action
   183     states.append(json.dumps(meta, sort_keys=True, separators=(', ',': ')))
   181     states.append(templatefilters.json(meta))
   184 
   182 
   185     res.status = b'200 OK'
   183     res.status = b'200 OK'
   186     res.headers[b'Content-Type'] = b'text/plain'
   184     res.headers[b'Content-Type'] = b'text/plain'
   187     res.setbodybytes(b'\n'.join(states))
   185     res.setbodybytes(b'\n'.join(states))
   188 
   186