Mercurial > hg
annotate contrib/debugcmdserver.py @ 37558:8a73132214a3
httppeer: support protocol upgrade
With the new handshake defined and in place on the server, we can
now implement it on the client.
The HTTP handshake mechanism has been taught to add headers advertising
its support for the new capabilities response. Response handling
has been adjusted to allow CBOR responses through. And makepeer()
has been taught to instantiate a mutually supported peer.
The HTTPv2 peer class doesn't implement the full peer interface. So
HTTPv2 is not yet usable as a peer.
Like the server side, we support registering handlers for
different API services. This allows extensions to easily implement
API services and peers. A practical use case for this is to
provide a previous implementation of the experimental version 2
wire protocol to a future version of Mercurial. We know there will
be BC breaks after 4.6 ships. But someone could take the peer and
server code from 4.6, drop it in an extension, and allow its use
indefinitely.
Differential Revision: https://phab.mercurial-scm.org/D3243
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 10 Apr 2018 18:16:47 -0700 |
parents | cd03fbd5ab57 |
children | 2372284d9457 |
rev | line source |
---|---|
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
2 # |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
3 # Dumps output generated by Mercurial's command server in a formatted style to a |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
4 # given file or stderr if '-' is specified. Output is also written in its raw |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
5 # format to stdout. |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 # |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 # $ ./hg serve --cmds pipe | ./contrib/debugcmdserver.py - |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 # o, 52 -> 'capabilities: getencoding runcommand\nencoding: UTF-8' |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
9 |
28353
cd03fbd5ab57
debugcmdserver: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
16687
diff
changeset
|
10 from __future__ import absolute_import, print_function |
cd03fbd5ab57
debugcmdserver: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
16687
diff
changeset
|
11 import struct |
cd03fbd5ab57
debugcmdserver: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
16687
diff
changeset
|
12 import sys |
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 if len(sys.argv) != 2: |
28353
cd03fbd5ab57
debugcmdserver: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
16687
diff
changeset
|
15 print('usage: debugcmdserver.py FILE') |
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 sys.exit(1) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 outputfmt = '>cI' |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 outputfmtsize = struct.calcsize(outputfmt) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 if sys.argv[1] == '-': |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 log = sys.stderr |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
23 else: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
24 log = open(sys.argv[1], 'a') |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 def read(size): |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
27 data = sys.stdin.read(size) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 if not data: |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
15259
diff
changeset
|
29 raise EOFError |
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 sys.stdout.write(data) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
31 sys.stdout.flush() |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
32 return data |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 try: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 while True: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
36 header = read(outputfmtsize) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
37 channel, length = struct.unpack(outputfmt, header) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 log.write('%s, %-4d' % (channel, length)) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
39 if channel in 'IL': |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
40 log.write(' -> waiting for input\n') |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
41 else: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
42 data = read(length) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
43 log.write(' -> %r\n' % data) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
44 log.flush() |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
45 except EOFError: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
46 pass |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 finally: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
48 if log != sys.stderr: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
49 log.close() |