diff --git a/CHANGELOG.md b/CHANGELOG.md
index 190b604cb..8907031cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@ If you depend on these features, please raise your voice in
### Full Changelog
* New Proxy Core based on sans-io pattern (@mhils)
+* mitmproxy's command line interface now supports Windows (@mhils)
* Use pyca/cryptography to generate certificates, not pyOpenSSL (@mhils)
* Remove the legacy protocol stack (@Kriechi)
* Remove all deprecated pathod and pathoc tools and modules (@Kriechi)
diff --git a/docs/src/content/overview-installation.md b/docs/src/content/overview-installation.md
index 633e4b2b4..e92663b7b 100644
--- a/docs/src/content/overview-installation.md
+++ b/docs/src/content/overview-installation.md
@@ -34,17 +34,15 @@ the repository maintainers directly for issues with native packages.
## Windows
-All the mitmproxy tools are fully supported under [WSL (Windows Subsystem for
-Linux)](https://docs.microsoft.com/en-us/windows/wsl/about). We recommend to
-[install WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10), and
-then follow the mitmproxy installation instructions for Linux.
+To install mitmproxy on Windows, download the installer from [mitmproxy.org](https://mitmproxy.org/). After
+installation, mitmproxy, mitmdump and mitmweb are also added to your PATH and can be invoked from the command line.
-We also distribute native Windows packages for all tools other than the
-mitmproxy console app, which only works under WSL. To install mitmproxy on
-Windows, download the installer from [mitmproxy.org](https://mitmproxy.org/).
-After installation, you'll find shortcuts for mitmweb and mitmdump in the start
-menu. Both executables are added to your PATH and can be invoked from the
-command line.
+We highly recommend to [install Windows Terminal](https://aka.ms/terminal) to improve the rendering of the console interface.
+
+All the mitmproxy tools are also supported under
+[WSL (Windows Subsystem for Linux)](https://docs.microsoft.com/en-us/windows/wsl/about). After
+[installing WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10), follow the mitmproxy installation
+instructions for Linux.
## Advanced Installation
@@ -80,9 +78,8 @@ You can use the official mitmproxy images from
### Security Considerations for Binary Packages
Our pre-compiled binary packages and Docker images include a self-contained
-Python 3 environment, a recent version of OpenSSL that support ALPN and HTTP/2,
-and other dependencies that would otherwise be cumbersome to compile and
-install.
+Python 3 environment, a recent version of OpenSSL, and other dependencies
+that would otherwise be cumbersome to compile and install.
Dependencies in the binary packages are frozen on release, and can't be updated
in situ. This means that we necessarily capture any bugs or security issues that
diff --git a/mitmproxy/contrib/README b/mitmproxy/contrib/README
index fc44eed38..9924f9368 100644
--- a/mitmproxy/contrib/README
+++ b/mitmproxy/contrib/README
@@ -4,6 +4,5 @@ Contribs:
wbxml
- https://github.com/davidpshaw/PyWBXMLDecoder
-tls, BSD license
- - https://github.com/mhils/tls/tree/mitmproxy
- - limited to required files.
+urwid
+ - Patches vendored from https://github.com/urwid/urwid/pull/448.
\ No newline at end of file
diff --git a/mitmproxy/contrib/urwid/raw_display.py b/mitmproxy/contrib/urwid/raw_display.py
index 647c8114a..b2a56b4a1 100644
--- a/mitmproxy/contrib/urwid/raw_display.py
+++ b/mitmproxy/contrib/urwid/raw_display.py
@@ -725,7 +725,9 @@ class Screen(BaseScreen, RealTerminal):
assert self._term_output_file == sys.stdout
handle = win32.GetStdHandle(win32.STD_OUTPUT_HANDLE)
info = win32.CONSOLE_SCREEN_BUFFER_INFO()
- win32.GetConsoleScreenBufferInfo(handle, byref(info))
+ ok = win32.GetConsoleScreenBufferInfo(handle, byref(info))
+ if ok == 0:
+ raise IOError()
y, x = info.dwSize.Y, info.dwSize.X
else:
buf = fcntl.ioctl(self._term_output_file.fileno(),
diff --git a/mitmproxy/tools/console/common.py b/mitmproxy/tools/console/common.py
index 71472ed5b..fe31a6375 100644
--- a/mitmproxy/tools/console/common.py
+++ b/mitmproxy/tools/console/common.py
@@ -13,8 +13,8 @@ from mitmproxy.http import HTTPFlow
from mitmproxy.utils import human
from mitmproxy.tcp import TCPFlow
-# Detect Windows Subsystem for Linux
-IS_WSL = "Microsoft" in platform.platform()
+# Detect Windows Subsystem for Linux and Windows
+IS_WINDOWS = "Microsoft" in platform.platform() or "Windows" in platform.platform()
def is_keypress(k):
diff --git a/mitmproxy/tools/console/window.py b/mitmproxy/tools/console/window.py
index bb8bdb28c..cff2e3891 100644
--- a/mitmproxy/tools/console/window.py
+++ b/mitmproxy/tools/console/window.py
@@ -1,3 +1,4 @@
+import os
import re
import urwid
@@ -14,6 +15,11 @@ from mitmproxy.tools.console import overlay
from mitmproxy.tools.console import signals
from mitmproxy.tools.console import statusbar
+if os.name == "nt":
+ from mitmproxy.contrib.urwid import raw_display
+else:
+ from urwid import raw_display
+
class StackWidget(urwid.Frame):
def __init__(self, window, widget, title, focus):
@@ -315,10 +321,10 @@ class Window(urwid.Frame):
)
-class Screen(urwid.raw_display.Screen):
+class Screen(raw_display.Screen):
def write(self, data):
- if common.IS_WSL:
+ if common.IS_WINDOWS:
# replace urwid's SI/SO, which produce artifacts under WSL.
# at some point we may figure out what they actually do.
data = re.sub("[\x0e\x0f]", "", data)
diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py
index 7d8992787..ba0e8bf8e 100644
--- a/mitmproxy/tools/main.py
+++ b/mitmproxy/tools/main.py
@@ -122,10 +122,10 @@ def run(
def mitmproxy(args=None) -> typing.Optional[int]: # pragma: no cover
if os.name == "nt":
- print("Error: mitmproxy's console interface is not supported on Windows. "
- "You can run mitmdump or mitmweb instead.", file=sys.stderr)
- return 1
- assert_utf8_env()
+ import urwid
+ urwid.set_encoding("utf8")
+ else:
+ assert_utf8_env()
from mitmproxy.tools import console
run(console.master.ConsoleMaster, cmdline.mitmproxy, args)
return None
diff --git a/release/cibuild.py b/release/cibuild.py
index 9317e3cfe..6eef5f995 100755
--- a/release/cibuild.py
+++ b/release/cibuild.py
@@ -121,12 +121,9 @@ class BuildEnviron:
@property
def bdists(self):
- ret = {
+ return {
"mitmproxy": ["mitmproxy", "mitmdump", "mitmweb"],
}
- if self.system == "Windows":
- ret["mitmproxy"].remove("mitmproxy")
- return ret
@property
def branch(self) -> str:
diff --git a/release/installbuilder/mitmproxy.xml b/release/installbuilder/mitmproxy.xml
index ed0c94733..1e9181004 100644
--- a/release/installbuilder/mitmproxy.xml
+++ b/release/installbuilder/mitmproxy.xml
@@ -33,6 +33,9 @@
1
../build/binaries/${platform_name}/*
+
+ run.ps1
+
@@ -51,24 +54,34 @@
-
- mitmproxy ui
+ mitmproxy command line interface
+ mitmproxy
0
0
- ${installdir}\bin\mitmweb.exe
-
+ powershell.exe
+ -File "${installdir}\bin\run.ps1" mitmproxy
${installdir}/logo.ico
- ${installdir}
+ ${user_home_directory}
-
+ mitmproxy web interface
+ mitmweb
+ 0
+ 0
+ powershell.exe
+ -File "${installdir}\bin\run.ps1" mitmweb
+ ${installdir}/logo.ico
+ ${user_home_directory}
+
+
+ mitmproxy non-interactive interface
mitmdump
0
0
- ${installdir}\bin\mitmdump.exe
-
+ powershell.exe
+ -File "${installdir}\bin\run.ps1" mitmdump
${installdir}/logo.ico
- ${installdir}
+ ${user_home_directory}
@@ -85,24 +98,9 @@
cmd
- /c start "mitmproxy ui" "${installdir}\bin\mitmweb.exe" &
- Launch mitmproxy ui now
-
-
- windows
-
-
-
-
- ${installdir}/mitmproxy
- &
+ /c powershell -File "${installdir}\bin\run.ps1" mitmproxy &
Launch mitmproxy now
-
-
- 1
- windows
-
-
+ ${user_home_directory}
@@ -120,6 +118,7 @@
40
+
@@ -131,3 +130,4 @@
+
diff --git a/release/installbuilder/run.ps1 b/release/installbuilder/run.ps1
new file mode 100644
index 000000000..5f782dbf8
--- /dev/null
+++ b/release/installbuilder/run.ps1
@@ -0,0 +1,5 @@
+if (Get-Command wt -ErrorAction SilentlyContinue) {
+ Start-Process wt -ArgumentList "powershell.exe","-NoExit","-Command",$args[0]
+} else {
+ Start-Process powershell -ArgumentList "-NoExit","-Command",$args[0]
+}
diff --git a/test/mitmproxy/tools/console/test_integration.py b/test/mitmproxy/tools/console/test_integration.py
index feac17746..91ce25d3b 100644
--- a/test/mitmproxy/tools/console/test_integration.py
+++ b/test/mitmproxy/tools/console/test_integration.py
@@ -8,7 +8,6 @@ import mitmproxy.options
from mitmproxy import master
from mitmproxy.tools.console import window
from mitmproxy.tools.console.master import ConsoleMaster
-from test.conftest import skip_windows
def tokenize(input: str) -> List[str]:
@@ -40,7 +39,6 @@ def console(monkeypatch):
return m
-@skip_windows
def test_integration(tdata, console):
console.type(f":view.flows.load {tdata.path('mitmproxy/data/dumpfile-018.bin')}")
console.type("")
diff --git a/test/release/test_cibuild.py b/test/release/test_cibuild.py
index d826c3615..59da0d3e4 100644
--- a/test/release/test_cibuild.py
+++ b/test/release/test_cibuild.py
@@ -205,7 +205,7 @@ def test_buildenviron_windows(tmpdir):
)
assert be.platform_tag == "windows"
assert be.bdists == {
- "mitmproxy": ["mitmdump", "mitmweb"],
+ "mitmproxy": ["mitmproxy", "mitmdump", "mitmweb"],
}
assert be.archive_name("mitmproxy") == "mitmproxy-0.0.1-windows.zip"