Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
c3b9650c
Commit
c3b9650c
authored
Jan 25, 2012
by
Andrew Balholm
Committed by
David Symonds
Jan 25, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/http: parse CONNECT requests
Fixes #2755 R=dsymonds, rsc CC=golang-dev
https://golang.org/cl/5571052
parent
03ea8b1c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
0 deletions
+91
-0
readrequest_test.go
src/pkg/net/http/readrequest_test.go
+69
-0
request.go
src/pkg/net/http/request.go
+22
-0
No files found.
src/pkg/net/http/readrequest_test.go
View file @
c3b9650c
...
...
@@ -171,6 +171,75 @@ var reqTests = []reqTest{
},
noError
,
},
// CONNECT request with domain name:
{
"CONNECT www.google.com:443 HTTP/1.1
\r\n\r\n
"
,
&
Request
{
Method
:
"CONNECT"
,
URL
:
&
url
.
URL
{
Host
:
"www.google.com:443"
,
},
Proto
:
"HTTP/1.1"
,
ProtoMajor
:
1
,
ProtoMinor
:
1
,
Header
:
Header
{},
Close
:
false
,
ContentLength
:
0
,
Host
:
"www.google.com:443"
,
},
noBody
,
noTrailer
,
noError
,
},
// CONNECT request with IP address:
{
"CONNECT 127.0.0.1:6060 HTTP/1.1
\r\n\r\n
"
,
&
Request
{
Method
:
"CONNECT"
,
URL
:
&
url
.
URL
{
Host
:
"127.0.0.1:6060"
,
},
Proto
:
"HTTP/1.1"
,
ProtoMajor
:
1
,
ProtoMinor
:
1
,
Header
:
Header
{},
Close
:
false
,
ContentLength
:
0
,
Host
:
"127.0.0.1:6060"
,
},
noBody
,
noTrailer
,
noError
,
},
// CONNECT request for RPC:
{
"CONNECT /_goRPC_ HTTP/1.1
\r\n\r\n
"
,
&
Request
{
Method
:
"CONNECT"
,
URL
:
&
url
.
URL
{
Path
:
"/_goRPC_"
,
},
Proto
:
"HTTP/1.1"
,
ProtoMajor
:
1
,
ProtoMinor
:
1
,
Header
:
Header
{},
Close
:
false
,
ContentLength
:
0
,
Host
:
""
,
},
noBody
,
noTrailer
,
noError
,
},
}
func
TestReadRequest
(
t
*
testing
.
T
)
{
...
...
src/pkg/net/http/request.go
View file @
c3b9650c
...
...
@@ -305,6 +305,9 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header) err
ruri
:=
req
.
URL
.
RequestURI
()
if
usingProxy
&&
req
.
URL
.
Scheme
!=
""
&&
req
.
URL
.
Opaque
==
""
{
ruri
=
req
.
URL
.
Scheme
+
"://"
+
host
+
ruri
}
else
if
req
.
Method
==
"CONNECT"
&&
req
.
URL
.
Path
==
""
{
// CONNECT requests normally give just the host and port, not a full URL.
ruri
=
host
}
// TODO(bradfitz): escape at least newlines in ruri?
...
...
@@ -463,10 +466,29 @@ func ReadRequest(b *bufio.Reader) (req *Request, err error) {
return
nil
,
&
badStringError
{
"malformed HTTP version"
,
req
.
Proto
}
}
// CONNECT requests are used two different ways, and neither uses a full URL:
// The standard use is to tunnel HTTPS through an HTTP proxy.
// It looks like "CONNECT www.google.com:443 HTTP/1.1", and the parameter is
// just the authority section of a URL. This information should go in req.URL.Host.
//
// The net/rpc package also uses CONNECT, but there the parameter is a path
// that starts with a slash. It can be parsed with the regular URL parser,
// and the path will end up in req.URL.Path, where it needs to be in order for
// RPC to work.
justAuthority
:=
req
.
Method
==
"CONNECT"
&&
!
strings
.
HasPrefix
(
rawurl
,
"/"
)
if
justAuthority
{
rawurl
=
"http://"
+
rawurl
}
if
req
.
URL
,
err
=
url
.
ParseRequest
(
rawurl
);
err
!=
nil
{
return
nil
,
err
}
if
justAuthority
{
// Strip the bogus "http://" back off.
req
.
URL
.
Scheme
=
""
}
// Subsequent lines: Key: value.
mimeHeader
,
err
:=
tp
.
ReadMIMEHeader
()
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment