mercurial/wireprotov2server.py
changeset 40138 b5bf3dd6ec5b
parent 40133 762ef19a07e3
child 40172 30f70d11c224
--- a/mercurial/wireprotov2server.py	Mon Oct 08 15:19:32 2018 -0700
+++ b/mercurial/wireprotov2server.py	Mon Oct 08 17:24:28 2018 -0700
@@ -194,7 +194,7 @@
     reactor = wireprotoframing.serverreactor(ui, deferoutput=True)
     seencommand = False
 
-    outstream = reactor.makeoutputstream()
+    outstream = None
 
     while True:
         frame = wireprotoframing.readframe(req.bodyfh)
@@ -207,6 +207,11 @@
             # Need more data before we can do anything.
             continue
         elif action == 'runcommand':
+            # Defer creating output stream because we need to wait for
+            # protocol settings frames so proper encoding can be applied.
+            if not outstream:
+                outstream = reactor.makeoutputstream()
+
             sentoutput = _httpv2runcommand(ui, repo, req, res, authedperm,
                                            reqcommand, reactor, outstream,
                                            meta, issubsequent=seencommand)