aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/client.go12
-rw-r--r--handler_test.go16
-rw-r--r--instance.go20
-rw-r--r--instance_test.go6
-rw-r--r--reqres_test.go6
5 files changed, 30 insertions, 30 deletions
diff --git a/client/client.go b/client/client.go
index 6ab654a..f474401 100644
--- a/client/client.go
+++ b/client/client.go
@@ -98,7 +98,7 @@ func (c *Client) AddEntry(ctx context.Context, name, checksum []byte) (*stfe.StI
}
glog.V(3).Infof("created post data: %s", string(data))
- url := stfe.EndpointAddEntry.Url(c.protocol() + c.Log.BaseUrl)
+ url := stfe.EndpointAddEntry.Path(c.protocol() + c.Log.BaseUrl)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
if err != nil {
return nil, fmt.Errorf("failed creating http request: %v", err)
@@ -125,7 +125,7 @@ func (c *Client) AddEntry(ctx context.Context, name, checksum []byte) (*stfe.StI
// GetSth fetches and verifies the most recent STH. Safe to use without a
// client chain and corresponding private key.
func (c *Client) GetSth(ctx context.Context) (*stfe.StItem, error) {
- url := stfe.EndpointGetSth.Url(c.protocol() + c.Log.BaseUrl)
+ url := stfe.EndpointGetSth.Path(c.protocol() + c.Log.BaseUrl)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("failed creating http request: %v", err)
@@ -151,7 +151,7 @@ func (c *Client) GetSth(ctx context.Context) (*stfe.StItem, error) {
// GetConsistencyProof fetches and verifies a consistency proof between two
// STHs. Safe to use without a client chain and corresponding private key.
func (c *Client) GetConsistencyProof(ctx context.Context, first, second *stfe.StItem) (*stfe.StItem, error) {
- url := stfe.EndpointGetConsistencyProof.Url(c.protocol() + c.Log.BaseUrl)
+ url := stfe.EndpointGetConsistencyProof.Path(c.protocol() + c.Log.BaseUrl)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("failed creating http request: %v", err)
@@ -180,7 +180,7 @@ func (c *Client) GetConsistencyProof(ctx context.Context, first, second *stfe.St
// STH. Safe to use without a client chain and corresponding private key.
func (c *Client) GetProofByHash(ctx context.Context, treeSize uint64, rootHash, leaf []byte) (*stfe.StItem, error) {
leafHash := rfc6962.DefaultHasher.HashLeaf(leaf)
- url := stfe.EndpointGetProofByHash.Url(c.protocol() + c.Log.BaseUrl)
+ url := stfe.EndpointGetProofByHash.Path(c.protocol() + c.Log.BaseUrl)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("failed creating http request: %v", err)
@@ -213,7 +213,7 @@ func (c *Client) GetProofByHash(ctx context.Context, treeSize uint64, rootHash,
// Note that a certificate chain is considered valid if it is chained correctly.
// In other words, the caller may want to check whether the anchor is trusted.
func (c *Client) GetEntries(ctx context.Context, start, end uint64) ([]*stfe.GetEntryResponse, error) {
- url := stfe.EndpointGetEntries.Url(c.protocol() + c.Log.BaseUrl)
+ url := stfe.EndpointGetEntries.Path(c.protocol() + c.Log.BaseUrl)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("failed creating http request: %v", err)
@@ -251,7 +251,7 @@ func (c *Client) GetEntries(ctx context.Context, start, end uint64) ([]*stfe.Get
// GetAnchors fetches the log's trust anchors. Safe to use without a client
// chain and corresponding private key.
func (c *Client) GetAnchors(ctx context.Context) ([]*x509.Certificate, error) {
- url := stfe.EndpointGetAnchors.Url(c.protocol() + c.Log.BaseUrl)
+ url := stfe.EndpointGetAnchors.Path(c.protocol() + c.Log.BaseUrl)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("failed creating http request: %v", err)
diff --git a/handler_test.go b/handler_test.go
index 34f390a..689541b 100644
--- a/handler_test.go
+++ b/handler_test.go
@@ -85,7 +85,7 @@ func TestGetHandlersRejectPost(t *testing.T) {
s := httptest.NewServer(handler)
defer s.Close()
- url := endpoint.Url(s.URL, th.instance.LogParameters.Prefix)
+ url := endpoint.Path(s.URL, th.instance.LogParameters.Prefix)
if rsp, err := http.Post(url, "application/json", nil); err != nil {
t.Fatalf("http.Post(%s)=(_,%q), want (_,nil)", url, err)
} else if rsp.StatusCode != http.StatusMethodNotAllowed {
@@ -105,7 +105,7 @@ func TestPostHandlersRejectGet(t *testing.T) {
s := httptest.NewServer(handler)
defer s.Close()
- url := endpoint.Url(s.URL, th.instance.LogParameters.Prefix)
+ url := endpoint.Path(s.URL, th.instance.LogParameters.Prefix)
if rsp, err := http.Get(url); err != nil {
t.Fatalf("http.Get(%s)=(_,%q), want (_,nil)", url, err)
} else if rsp.StatusCode != http.StatusMethodNotAllowed {
@@ -120,7 +120,7 @@ func TestGetAnchors(t *testing.T) {
th := newTestHandler(t, nil)
defer th.mockCtrl.Finish()
- url := EndpointGetAnchors.Url("http://example.com", th.instance.LogParameters.Prefix)
+ url := EndpointGetAnchors.Path("http://example.com", th.instance.LogParameters.Prefix)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("failed creating http request: %v", err)
@@ -199,7 +199,7 @@ func TestGetEntries(t *testing.T) {
th := newTestHandler(t, nil)
defer th.mockCtrl.Finish()
- url := EndpointGetEntries.Url("http://example.com", th.instance.LogParameters.Prefix)
+ url := EndpointGetEntries.Path("http://example.com", th.instance.LogParameters.Prefix)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("failed creating http request: %v", err)
@@ -312,7 +312,7 @@ func TestAddEntry(t *testing.T) {
th := newTestHandler(t, table.signer)
defer th.mockCtrl.Finish()
- url := EndpointAddEntry.Url("http://example.com", th.instance.LogParameters.Prefix)
+ url := EndpointAddEntry.Path("http://example.com", th.instance.LogParameters.Prefix)
req, err := http.NewRequest("POST", url, table.breq)
if err != nil {
t.Fatalf("failed creating http request: %v", err)
@@ -406,7 +406,7 @@ func TestGetSth(t *testing.T) {
th := newTestHandler(t, table.signer)
defer th.mockCtrl.Finish()
- url := EndpointGetSth.Url("http://example.com", th.instance.LogParameters.Prefix)
+ url := EndpointGetSth.Path("http://example.com", th.instance.LogParameters.Prefix)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("failed creating http request: %v", err)
@@ -510,7 +510,7 @@ func TestGetConsistencyProof(t *testing.T) {
th := newTestHandler(t, nil)
defer th.mockCtrl.Finish()
- url := EndpointGetConsistencyProof.Url("http://example.com", th.instance.LogParameters.Prefix)
+ url := EndpointGetConsistencyProof.Path("http://example.com", th.instance.LogParameters.Prefix)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("failed creating http request: %v", err)
@@ -619,7 +619,7 @@ func TestGetProofByHash(t *testing.T) {
th := newTestHandler(t, nil)
defer th.mockCtrl.Finish()
- url := EndpointGetProofByHash.Url("http://example.com", th.instance.LogParameters.Prefix)
+ url := EndpointGetProofByHash.Path("http://example.com", th.instance.LogParameters.Prefix)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("failed creating http request: %v", err)
diff --git a/instance.go b/instance.go
index 55b23fc..2c108aa 100644
--- a/instance.go
+++ b/instance.go
@@ -28,10 +28,10 @@ const (
EndpointGetSth = Endpoint("get-sth")
)
-// Url builds an endpoint url from a number of components, e.g., base and prefix
-func (e Endpoint) Url(components ...string) string {
- components = append(components, string(e))
- return strings.Join(components, "/")
+// Path joins a number of components to form a full endpoint path, e.g., base
+// ("example.com"), prefix ("st/v1"), and the endpoint itself ("get-sth").
+func (e Endpoint) Path(components ...string) string {
+ return strings.Join(append(components, string(e)), "/")
}
// Instance is an instance of a particular log front-end
@@ -122,27 +122,27 @@ func (i *Instance) registerHandlers(mux *http.ServeMux) {
handler handler
}{
{
- EndpointAddEntry.Url("", i.LogParameters.Prefix),
+ EndpointAddEntry.Path("", i.LogParameters.Prefix),
handler{instance: i, handler: addEntry, endpoint: EndpointAddEntry, method: http.MethodPost},
},
{
- EndpointGetEntries.Url("", i.LogParameters.Prefix),
+ EndpointGetEntries.Path("", i.LogParameters.Prefix),
handler{instance: i, handler: getEntries, endpoint: EndpointGetEntries, method: http.MethodGet},
},
{
- EndpointGetAnchors.Url("", i.LogParameters.Prefix),
+ EndpointGetAnchors.Path("", i.LogParameters.Prefix),
handler{instance: i, handler: getAnchors, endpoint: EndpointGetAnchors, method: http.MethodGet},
},
{
- EndpointGetProofByHash.Url("", i.LogParameters.Prefix),
+ EndpointGetProofByHash.Path("", i.LogParameters.Prefix),
handler{instance: i, handler: getProofByHash, endpoint: EndpointGetProofByHash, method: http.MethodGet},
},
{
- EndpointGetConsistencyProof.Url("", i.LogParameters.Prefix),
+ EndpointGetConsistencyProof.Path("", i.LogParameters.Prefix),
handler{instance: i, handler: getConsistencyProof, endpoint: EndpointGetConsistencyProof, method: http.MethodGet},
},
{
- EndpointGetSth.Url("", i.LogParameters.Prefix),
+ EndpointGetSth.Path("", i.LogParameters.Prefix),
handler{instance: i, handler: getSth, endpoint: EndpointGetSth, method: http.MethodGet},
},
} {
diff --git a/instance_test.go b/instance_test.go
index 6fe0e5b..b4b13c8 100644
--- a/instance_test.go
+++ b/instance_test.go
@@ -39,7 +39,7 @@ func makeTestLogParameters(t *testing.T, signer crypto.Signer) *LogParameters {
}
}
-func TestEndpointUrl(t *testing.T) {
+func TestEndpointPath(t *testing.T) {
base, prefix := "http://example.com", "test"
for _, table := range []struct {
endpoint Endpoint
@@ -70,10 +70,10 @@ func TestEndpointUrl(t *testing.T) {
want: "http://example.com/test/get-anchors",
},
} {
- if got, want := table.endpoint.Url(base, prefix), table.want; got != want {
+ if got, want := table.endpoint.Path(base, prefix), table.want; got != want {
t.Errorf("got %s but wanted %s with multiple components", got, want)
}
- if got, want := table.endpoint.Url(base+"/"+prefix), table.want; got != want {
+ if got, want := table.endpoint.Path(base+"/"+prefix), table.want; got != want {
t.Errorf("got %s but wanted %s with one component", got, want)
}
}
diff --git a/reqres_test.go b/reqres_test.go
index 1bb0348..3574750 100644
--- a/reqres_test.go
+++ b/reqres_test.go
@@ -65,7 +65,7 @@ func TestNewGetEntriesRequest(t *testing.T) {
end: fmt.Sprintf("%d", testMaxRange-1),
},
} {
- url := EndpointGetEntries.Url("http://example.com/", lp.Prefix)
+ url := EndpointGetEntries.Path("http://example.com/", lp.Prefix)
r, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("must make http request in test %q: %v", table.description, err)
@@ -136,7 +136,7 @@ func TestNewGetProofByHashRequest(t *testing.T) {
hash: b64(testNodeHash),
},
} {
- url := EndpointGetProofByHash.Url("http://example.com/", lp.Prefix)
+ url := EndpointGetProofByHash.Path("http://example.com/", lp.Prefix)
r, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("must make http request in test %q: %v", table.description, err)
@@ -201,7 +201,7 @@ func TestNewGetConsistencyProofRequest(t *testing.T) {
second: "2",
},
} {
- url := EndpointGetConsistencyProof.Url("http://example.com/", lp.Prefix)
+ url := EndpointGetConsistencyProof.Path("http://example.com/", lp.Prefix)
r, err := http.NewRequest("GET", url, nil)
if err != nil {
t.Fatalf("must make http request in test %q: %v", table.description, err)