|
|
Created:
9 years, 12 months ago by athomason Modified:
9 years, 7 months ago CC:
golang-codereviews Visibility:
Public. |
Descriptionnet/rpc: add support for RPC over HTTPS.
This adds the DialHTTP and DialHTTPSPath functions to net/rpc.
Fixes issue 7946.
Patch Set 1 #Patch Set 2 : diff -r c19d7fd53785 https://code.google.com/p/go #Patch Set 3 : diff -r ea90f25d321f https://code.google.com/p/go #Patch Set 4 : diff -r ea90f25d321f https://code.google.com/p/go #Patch Set 5 : code review 100140043: net/rpc: add support for RPC over HTTPS. #
MessagesTotal messages: 7
Hello golang-codereviews@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
Sign in to reply to this message.
Fancy seeing you here! The tree is closed for the Go 1.3 stabilization period right now. It's re-opening for additions after Go 1.3 (~Jun 1st). Please ping this thread then, and/or file a bug to track this, referencing this CL. On Mon, May 5, 2014 at 4:57 PM, <athomason@gmail.com> wrote: > Reviewers: golang-codereviews, > > Message: > Hello golang-codereviews@googlegroups.com, > > I'd like you to review this change to > https://code.google.com/p/go > > > Description: > net/rpc: add support for RPC over HTTPS. > > Please review this at https://codereview.appspot.com/100140043/ > > Affected files (+66, -5 lines): > M src/pkg/net/rpc/client.go > M src/pkg/net/rpc/server_test.go > > > Index: src/pkg/net/rpc/client.go > =================================================================== > --- a/src/pkg/net/rpc/client.go > +++ b/src/pkg/net/rpc/client.go > @@ -6,6 +6,7 @@ > > import ( > "bufio" > + "crypto/tls" > "encoding/gob" > "errors" > "io" > @@ -238,11 +239,30 @@ > // DialHTTPPath connects to an HTTP RPC server > // at the specified network address and path. > func DialHTTPPath(network, address, path string) (*Client, error) { > - var err error > conn, err := net.Dial(network, address) > if err != nil { > return nil, err > } > + return dialPath(network, address, path, conn) > +} > + > +// DialHTTPS connects to an HTTPS RPC server at the specified network > address > +// listening on the default HTTP RPC path. > +func DialHTTPS(network, address string, tlsConfig *tls.Config) (*Client, > error) { > + return DialHTTPSPath(network, address, DefaultRPCPath, tlsConfig) > +} > + > +// DialHTTPSPath connects to an HTTPS RPC server > +// at the specified network address and path. > +func DialHTTPSPath(network, address, path string, tlsConfig *tls.Config) > (*Client, error) { > + conn, err := tls.Dial(network, address, tlsConfig) > + if err != nil { > + return nil, err > + } > + return dialPath(network, address, path, conn) > +} > + > +func dialPath(network, address, path string, conn net.Conn) (*Client, > error) { > io.WriteString(conn, "CONNECT "+path+" HTTP/1.0\n\n") > > // Require successful HTTP response > Index: src/pkg/net/rpc/server_test.go > =================================================================== > --- a/src/pkg/net/rpc/server_test.go > +++ b/src/pkg/net/rpc/server_test.go > @@ -5,6 +5,7 @@ > package rpc > > import ( > + "crypto/tls" > "errors" > "fmt" > "io" > @@ -20,10 +21,10 @@ > ) > > var ( > - newServer *Server > - serverAddr, newServerAddr string > - httpServerAddr string > - once, newOnce, httpOnce sync.Once > + newServer *Server > + serverAddr, newServerAddr string > + httpServerAddr, httpsServerAddr string > + once, newOnce, httpOnce, httpsOnce sync.Once > ) > > const ( > @@ -93,6 +94,7 @@ > > HandleHTTP() > httpOnce.Do(startHttpServer) > + httpsOnce.Do(startHttpsServer) > } > > func startNewServer() { > @@ -116,6 +118,12 @@ > log.Println("Test HTTP RPC server listening on", httpServerAddr) > } > > +func startHttpsServer() { > + server := httptest.NewTLSServer(nil) > + httpsServerAddr = server.Listener.Addr().String() > + log.Println("Test HTTPS RPC server listening on", httpsServerAddr) > +} > + > func TestRPC(t *testing.T) { > once.Do(startServer) > testRPC(t, serverAddr) > @@ -302,6 +310,39 @@ > } > } > > +func TestHTTPS(t *testing.T) { > + once.Do(startServer) > + testHTTPSRPC(t, "") > + newOnce.Do(startNewServer) > + testHTTPSRPC(t, newHttpPath) > +} > + > +func testHTTPSRPC(t *testing.T, path string) { > + var client *Client > + var err error > + tlsConfig := &tls.Config{InsecureSkipVerify: true} > + if path == "" { > + client, err = DialHTTPS("tcp", httpsServerAddr, tlsConfig) > + } else { > + client, err = DialHTTPSPath("tcp", httpsServerAddr, path, > tlsConfig) > + } > + if err != nil { > + t.Fatal("dialing", err) > + } > + defer client.Close() > + > + // Synchronous calls > + args := &Args{7, 8} > + reply := new(Reply) > + err = client.Call("Arith.Add", args, reply) > + if err != nil { > + t.Errorf("Add: expected no error but got string %q", > err.Error()) > + } > + if reply.C != args.A+args.B { > + t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B) > + } > +} > + > // CodecEmulator provides a client-like api and a ServerCodec interface. > // Can be used to test ServeRequest. > type CodecEmulator struct { > > > -- > You received this message because you are subscribed to the Google Groups > "golang-codereviews" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-codereviews+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. >
Sign in to reply to this message.
Hey! Good to see you. I've filed https://code.google.com/p/go/issues/detail?id=7946 to track this. On 2014/05/06 17:45:28, bradfitz wrote: > Fancy seeing you here! > > The tree is closed for the Go 1.3 stabilization period right now. It's > re-opening for additions after Go 1.3 (~Jun 1st). Please ping this thread > then, and/or file a bug to track this, referencing this CL. > > > > > > On Mon, May 5, 2014 at 4:57 PM, <mailto:athomason@gmail.com> wrote: > > > Reviewers: golang-codereviews, > > > > Message: > > Hello mailto:golang-codereviews@googlegroups.com, > > > > I'd like you to review this change to > > https://code.google.com/p/go > > > > > > Description: > > net/rpc: add support for RPC over HTTPS. > > > > Please review this at https://codereview.appspot.com/100140043/ > > > > Affected files (+66, -5 lines): > > M src/pkg/net/rpc/client.go > > M src/pkg/net/rpc/server_test.go > > > > > > Index: src/pkg/net/rpc/client.go > > =================================================================== > > --- a/src/pkg/net/rpc/client.go > > +++ b/src/pkg/net/rpc/client.go > > @@ -6,6 +6,7 @@ > > > > import ( > > "bufio" > > + "crypto/tls" > > "encoding/gob" > > "errors" > > "io" > > @@ -238,11 +239,30 @@ > > // DialHTTPPath connects to an HTTP RPC server > > // at the specified network address and path. > > func DialHTTPPath(network, address, path string) (*Client, error) { > > - var err error > > conn, err := net.Dial(network, address) > > if err != nil { > > return nil, err > > } > > + return dialPath(network, address, path, conn) > > +} > > + > > +// DialHTTPS connects to an HTTPS RPC server at the specified network > > address > > +// listening on the default HTTP RPC path. > > +func DialHTTPS(network, address string, tlsConfig *tls.Config) (*Client, > > error) { > > + return DialHTTPSPath(network, address, DefaultRPCPath, tlsConfig) > > +} > > + > > +// DialHTTPSPath connects to an HTTPS RPC server > > +// at the specified network address and path. > > +func DialHTTPSPath(network, address, path string, tlsConfig *tls.Config) > > (*Client, error) { > > + conn, err := tls.Dial(network, address, tlsConfig) > > + if err != nil { > > + return nil, err > > + } > > + return dialPath(network, address, path, conn) > > +} > > + > > +func dialPath(network, address, path string, conn net.Conn) (*Client, > > error) { > > io.WriteString(conn, "CONNECT "+path+" HTTP/1.0\n\n") > > > > // Require successful HTTP response > > Index: src/pkg/net/rpc/server_test.go > > =================================================================== > > --- a/src/pkg/net/rpc/server_test.go > > +++ b/src/pkg/net/rpc/server_test.go > > @@ -5,6 +5,7 @@ > > package rpc > > > > import ( > > + "crypto/tls" > > "errors" > > "fmt" > > "io" > > @@ -20,10 +21,10 @@ > > ) > > > > var ( > > - newServer *Server > > - serverAddr, newServerAddr string > > - httpServerAddr string > > - once, newOnce, httpOnce sync.Once > > + newServer *Server > > + serverAddr, newServerAddr string > > + httpServerAddr, httpsServerAddr string > > + once, newOnce, httpOnce, httpsOnce sync.Once > > ) > > > > const ( > > @@ -93,6 +94,7 @@ > > > > HandleHTTP() > > httpOnce.Do(startHttpServer) > > + httpsOnce.Do(startHttpsServer) > > } > > > > func startNewServer() { > > @@ -116,6 +118,12 @@ > > log.Println("Test HTTP RPC server listening on", httpServerAddr) > > } > > > > +func startHttpsServer() { > > + server := httptest.NewTLSServer(nil) > > + httpsServerAddr = server.Listener.Addr().String() > > + log.Println("Test HTTPS RPC server listening on", httpsServerAddr) > > +} > > + > > func TestRPC(t *testing.T) { > > once.Do(startServer) > > testRPC(t, serverAddr) > > @@ -302,6 +310,39 @@ > > } > > } > > > > +func TestHTTPS(t *testing.T) { > > + once.Do(startServer) > > + testHTTPSRPC(t, "") > > + newOnce.Do(startNewServer) > > + testHTTPSRPC(t, newHttpPath) > > +} > > + > > +func testHTTPSRPC(t *testing.T, path string) { > > + var client *Client > > + var err error > > + tlsConfig := &tls.Config{InsecureSkipVerify: true} > > + if path == "" { > > + client, err = DialHTTPS("tcp", httpsServerAddr, tlsConfig) > > + } else { > > + client, err = DialHTTPSPath("tcp", httpsServerAddr, path, > > tlsConfig) > > + } > > + if err != nil { > > + t.Fatal("dialing", err) > > + } > > + defer client.Close() > > + > > + // Synchronous calls > > + args := &Args{7, 8} > > + reply := new(Reply) > > + err = client.Call("Arith.Add", args, reply) > > + if err != nil { > > + t.Errorf("Add: expected no error but got string %q", > > err.Error()) > > + } > > + if reply.C != args.A+args.B { > > + t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B) > > + } > > +} > > + > > // CodecEmulator provides a client-like api and a ServerCodec interface. > > // Can be used to test ServeRequest. > > type CodecEmulator struct { > > > > > > -- > > You received this message because you are subscribed to the Google Groups > > "golang-codereviews" group. > > To unsubscribe from this group and stop receiving emails from it, send an > > email to mailto:golang-codereviews+unsubscribe@googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > >
Sign in to reply to this message.
Ping, as requested.
Sign in to reply to this message.
Hello golang-codereviews@googlegroups.com, bradfitz@golang.org (cc: golang-codereviews@googlegroups.com), Please take another look.
Sign in to reply to this message.
Replacing golang-dev with golang-codereviews. To the author of this CL: If you are using 'hg mail -r golang-dev' to mail the CL, use simply 'hg mail' instead. If you did not name golang-dev explicitly and it was still added to the CL, it means your working copy of the repo has a stale codereview.cfg (or lib/codereview/codereview.cfg). Please run 'hg sync' to update your client to the most recent codereview.cfg. If the most recent codereview.cfg has defaultcc set to golang-dev instead of golang-codereviews, please send a CL correcting it. Thanks very much.
Sign in to reply to this message.
|