Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is proxy hardcoded to return HTTP/1.1? #572

Closed
dlethin opened this issue May 1, 2015 · 7 comments
Closed

Is proxy hardcoded to return HTTP/1.1? #572

dlethin opened this issue May 1, 2015 · 7 comments

Comments

@dlethin
Copy link
Contributor

dlethin commented May 1, 2015

We're attempting to use the proxy in a legacy java application and running into a problem. We've configured java to use a proxy pointing to mitmdump we've started. However, one of the calls is failing. This is apparently because we are using a library which attempts to make an HTTP/1.0 request to the proxy, but the mitmdump is returning "HTTP/1.1"

Here is the failure our application returns:

09:48:57 Message: Unable to tunnel through 127.0.0.1:8897.  Proxy returns "HTTP/1.1 200 Connection established"

I tracked down the corresponding code for the library we are using:


                Socket tunnel = new Socket(proxyHostName, proxyPort);
                OutputStream out = tunnel.getOutputStream();
                String connect = "CONNECT " + host + ":" + port + " HTTP/1.0\r\n\r\n";
                byte buf[];
...
               // We asked for HTTP/1.0, so we should get that back
                if (!replyStr.startsWith("HTTP/1.0 200")) {
                    throw new IOException("Unable to tunnel through "
                                          + proxyHostName + ":" + proxyPort
                                          + ".  Proxy returns \"" + replyStr + "\"");
                }

Is there anything we can do via command line parameters or configuration of mitmdump which will ensure that HTTP 1.0 requests to the proxy will return v1.0 responses? That would be preferable at least in the short term rather than trying to get our application to use a new version of this code.

As additional background on this, we came across this when attempting to move our continuous integration build from a server running on OSX to a server running on Linux (RedHat7). The OSX build is not experiencing this problem (which is running mitmproxy 0.10.1). However, on RedHat7, we get the failure whether I run the latest (v0.11.x) or 0.10.1. I don't know much about origin of how the mitmproxy was installed on the OSX machine. Its a binary executable, where as the one I installed on our linux box was done through pip. The java code being run is that same as well as the java version on both platforms. I don't know enough about mitmproxy to know where the http protocol version is coming from. Maybe its a matter of changing the version of downstream python library dependency.

Thanks.

Doug

@mhils
Copy link
Member

mhils commented May 1, 2015

Hi Doug,

you should be able to fix this by just changing the source code here: http.py#L1251-L1254.
If that works for you, please send a PR so that we can include this fix in mitmproxy.

Cheers,
Max

@dlethin
Copy link
Contributor Author

dlethin commented May 1, 2015

Thanks for the fast response. I can certainly make an attempt to fork this repo and try to patch based on your recommendation and if it works submit a PR request.

That being said, I'm a bit out of my element knowing how to get a build from my fork installed on the server in question. I've used 'pip' to install. Is it a matter of somehow configuring pip to point to the HEAD of my forked repo? Or is there some other way you would recommend?

Thanks.

@mhils
Copy link
Member

mhils commented May 1, 2015

pip install git+https://github.com/mitmproxy/mitmproxy.git@master installs from git directly (adjust accordingly).

Cheers,
Max

@mhils
Copy link
Member

mhils commented May 8, 2015

Any update on this? :-)

@dlethin
Copy link
Contributor Author

dlethin commented May 16, 2015

Sorry for the delayed response. I appear to not be getting notified when there are entries to conversations I'm participating in. I was able to make a quick hack to hardcode the response to the http version I was expecting and got passed my problem. I have to follow up now and make a better fix. I'm somewhat delayed and its not helping that I'm very rusty in python to make a cleaner fix.

@dlethin
Copy link
Contributor Author

dlethin commented May 16, 2015

Ok - I've submitted a pull request #584
Turns out it wasn't very hard to get the request httpversion. You had a nice example right in the file I needed to modify. Thanks again.

@cortesi
Copy link
Member

cortesi commented May 18, 2015

Resolved in cdff79f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants