-
Notifications
You must be signed in to change notification settings - Fork 35
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
Update transport.go , to fix ntlm 407 challenge httpresponse containing extra httpbody issue #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"net" | ||
"net/http" | ||
"net/url" | ||
"io" | ||
) | ||
|
||
// transport creates and manages the lifetime of a net.Conn. Between the time that a remote server | ||
|
@@ -57,7 +58,24 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) { | |
if err := req.Write(t.conn); err != nil { | ||
return nil, err | ||
} | ||
return http.ReadResponse(t.reader, req) | ||
var resp2 *http.Response | ||
var err2 error | ||
|
||
resp2,err2 = http.ReadResponse(t.reader, req) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it's correct to read another response here. This function gets called by ProxyHandler.proxyRequest(), and the body of the response gets closed later in that file. Since this is done in a If that's the case, then I think #120 would fix it - any chance you can give that branch a try and let me know if it fixes your issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure let me test it out and come back to you, most likely removing defer will also fix the issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, let's continue the discussion in that PR. |
||
|
||
if (resp2 != nil) { | ||
if resp2.StatusCode == http.StatusProxyAuthRequired { //if 407 extra http body is not used, discard it issue #118 | ||
//if http body is not read from stream here, it will get stuck in ioreader and cause a malformed HTTP response error i.e. <html<head> | ||
//pop the stream reader | ||
bodyBytes, _ := io.ReadAll(resp2.Body) | ||
_ = bodyBytes //unused variable | ||
} | ||
} | ||
|
||
return resp2,err2 //return the actual error | ||
|
||
|
||
//return http.ReadResponse(t.reader, req) | ||
} | ||
|
||
func (t *transport) hijack() net.Conn { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to do a UDP dial and take the local IP address, but it's not really clear to me which network interface the OS will choose to dial 192.0.2.1. RFC5737 says that this address "SHOULD" be unroutable, but maybe it's possible for people to, for example, set this up as a local test network which would quietly break Alpaca in unexpected ways?
Before we settle on an approach, I'd like to test a few scenarios myself first (including what happens if I try to make a UDP connection to this IP). I'll get back to you on that later this week, but let's make this myIpAddress() fix in a separate PR? It seems unrelated to the other change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ziyiwang I took a look at this, and yes Alpaca does give the "wrong" IP address back - in my case, it returns my WiFi adapter's IP address, rather than the VPN address, so similar to what you were seeing.
I've written up the problem here: #122.
I personally don't need to use the myIpAddress() function, so thanks for reporting this, it's not something I would've noticed myself.