THRIFT-3251 Add http transport for server to Go lib
Client: Go
Patch: claudemiro <dimiro1@gmail.com>
This closes #785
diff --git a/test/go/src/common/client.go b/test/go/src/common/client.go
index e55dc6d..4251d91 100644
--- a/test/go/src/common/client.go
+++ b/test/go/src/common/client.go
@@ -25,6 +25,7 @@
"flag"
"fmt"
"gen/thrifttest"
+ "net/http"
"thrift"
)
@@ -75,10 +76,21 @@
}
switch transport {
case "http":
- trans, err = thrift.NewTHttpClient(fmt.Sprintf("http://%s/service", hostPort))
+ if ssl {
+ tr := &http.Transport{
+ TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+ }
+ client := &http.Client{Transport: tr}
+ trans, err = thrift.NewTHttpPostClientWithOptions(fmt.Sprintf("https://%s/", hostPort), thrift.THttpClientOptions{Client: client})
+ fmt.Println(hostPort)
+ } else {
+ trans, err = thrift.NewTHttpPostClient(fmt.Sprintf("http://%s/", hostPort))
+ }
+
if err != nil {
return nil, err
}
+
case "framed":
trans = thrift.NewTFramedTransport(trans)
case "buffered":
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index 5c8915a..26fa7af 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -20,12 +20,13 @@
package common
import (
- "github.com/golang/mock/gomock"
"errors"
"gen/thrifttest"
"reflect"
"testing"
"thrift"
+
+ "github.com/golang/mock/gomock"
)
type test_unit struct {
@@ -56,7 +57,15 @@
ctrl := gomock.NewController(t)
defer ctrl.Finish()
handler := NewMockThriftTest(ctrl)
- server, err := StartServer(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
+
+ processor, serverTransport, transportFactory, protocolFactory, err := GetServerParams(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
+
+ server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
+ if err = server.Listen(); err != nil {
+ return
+ }
+ go server.AcceptLoop()
+ server.Serve()
if err != nil {
t.Errorf("Unable to start server", err)
t.FailNow()
@@ -175,7 +184,7 @@
}
// TODO: add TestBinary() call
-
+
xs := thrifttest.NewXtruct()
xs.StringThing = "thing"
xs.ByteThing = 42
diff --git a/test/go/src/common/server.go b/test/go/src/common/server.go
index dc380b2..5ac4400 100644
--- a/test/go/src/common/server.go
+++ b/test/go/src/common/server.go
@@ -37,7 +37,7 @@
flag.BoolVar(&debugServerProtocol, "debug_server_protocol", false, "turn server protocol trace on")
}
-func StartServer(
+func GetServerParams(
host string,
port int64,
domain_socket string,
@@ -45,8 +45,9 @@
protocol string,
ssl bool,
certPath string,
- handler thrifttest.ThriftTest) (srv *thrift.TSimpleServer, err error) {
+ handler thrifttest.ThriftTest) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
+ var err error
hostPort := fmt.Sprintf("%s:%d", host, port)
var protocolFactory thrift.TProtocolFactory
@@ -60,7 +61,7 @@
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
- return nil, fmt.Errorf("Invalid protocol specified %s", protocol)
+ return nil, nil, nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
}
if debugServerProtocol {
protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "server:")
@@ -70,7 +71,7 @@
if ssl {
cfg := new(tls.Config)
if cert, err := tls.LoadX509KeyPair(certPath+"/server.crt", certPath+"/server.key"); err != nil {
- return nil, err
+ return nil, nil, nil, nil, err
} else {
cfg.Certificates = append(cfg.Certificates, cert)
}
@@ -83,18 +84,15 @@
}
}
if err != nil {
- return nil, err
+ return nil, nil, nil, nil, err
}
var transportFactory thrift.TTransportFactory
switch transport {
case "http":
- return nil, fmt.Errorf("Http server transport is not supported")
- // trans, err = thrift.NewTHttpClient(fmt.Sprintf("http://%s/service", hostPort))
- // if err != nil {
- // return nil, err
- // }
+ // there is no such factory, and we don't need any
+ transportFactory = nil
case "framed":
transportFactory = thrift.NewTTransportFactory()
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
@@ -105,13 +103,9 @@
case "":
transportFactory = thrift.NewTTransportFactory()
default:
- return nil, fmt.Errorf("Invalid transport specified %s", transport)
+ return nil, nil, nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
}
processor := thrifttest.NewThriftTestProcessor(handler)
- server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
- if err = server.Listen(); err != nil {
- return
- }
- go server.AcceptLoop()
- return server, nil
+
+ return processor, serverTransport, transportFactory, protocolFactory, nil
}