Skip to content

Commit 38c1318

Browse files
committed
fix URL paths when simulating client-side streaming endpoints
1 parent bdc50e1 commit 38c1318

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

ldservices/streaming_service.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ const (
2020
// MobileSDKStreamingBasePath is the expected request path for mobile SDK stream requests that
2121
// use the REPORT method, or the base path (not including ClientSideOrMobileUserSubpath) for requests that
2222
// use the GET method.
23-
MobileSDKStreamingBasePath = "/meval"
24-
// ClientSideOrMobileUserSubpath is a subpath added to client-side/mobile GET requests. The base64-encoded
25-
// user data follows this.
26-
ClientSideOrMobileUserSubpath = "/user/"
23+
MobileSDKStreamingBasePath = "/meval"
24+
arbitraryPathComponentRegex = "/[^/]*"
2725
)
2826

2927
// StreamingServiceHandler creates an HTTP handler that provides an SSE stream.
@@ -93,17 +91,17 @@ func ClientSideStreamingServiceHandler(
9391
eventsCh <-chan eventsource.Event,
9492
) (http.Handler, io.Closer) {
9593
handler, closer := StreamingServiceHandler(initialEvent, eventsCh)
96-
return httphelpers.HandlerForPath(
97-
ClientSideSDKStreamingBasePath,
94+
return httphelpers.HandlerForPathRegex(
95+
"^"+ClientSideSDKStreamingBasePath+arbitraryPathComponentRegex+"$",
9896
httphelpers.HandlerForMethod("REPORT", handler, nil),
9997
httphelpers.HandlerForPathRegex(
100-
"^"+ClientSideSDKStreamingBasePath+ClientSideOrMobileUserSubpath+".*",
98+
"^"+ClientSideSDKStreamingBasePath+arbitraryPathComponentRegex+arbitraryPathComponentRegex+"$",
10199
httphelpers.HandlerForMethod("GET", handler, nil),
102100
httphelpers.HandlerForPath(
103101
MobileSDKStreamingBasePath,
104102
httphelpers.HandlerForMethod("REPORT", handler, nil),
105103
httphelpers.HandlerForPathRegex(
106-
"^"+MobileSDKStreamingBasePath+ClientSideOrMobileUserSubpath+".*",
104+
"^"+MobileSDKStreamingBasePath+arbitraryPathComponentRegex+"$",
107105
httphelpers.HandlerForMethod("GET", handler, nil),
108106
nil,
109107
),

ldservices/streaming_service_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func TestClientSideStreamingEndpoint(t *testing.T) {
139139
defer closer.Close()
140140

141141
httphelpers.WithServer(handler, func(server *httptest.Server) {
142-
stream1, err := eventsource.SubscribeWithURL(server.URL + ClientSideSDKStreamingBasePath + "/user/00000")
142+
stream1, err := eventsource.SubscribeWithURL(server.URL + ClientSideSDKStreamingBasePath + "/envxxx/userxxx")
143143
require.NoError(t, err)
144144
defer stream1.Close()
145145

@@ -155,11 +155,11 @@ func TestClientSideStreamingEndpoint(t *testing.T) {
155155
assert.Equal(t, event2.Event(), event3.Event())
156156
assert.Equal(t, event2.Data(), event3.Data())
157157

158-
stream2, err := eventsource.SubscribeWithURL(server.URL + MobileSDKStreamingBasePath + "/user/00000")
158+
stream2, err := eventsource.SubscribeWithURL(server.URL + MobileSDKStreamingBasePath + "/userxxx")
159159
require.NoError(t, err)
160160
stream2.Close()
161161

162-
req3, _ := http.NewRequest("REPORT", server.URL+ClientSideSDKStreamingBasePath, bytes.NewReader([]byte("{}")))
162+
req3, _ := http.NewRequest("REPORT", server.URL+ClientSideSDKStreamingBasePath+"/envxxx", bytes.NewReader([]byte("{}")))
163163
stream3, err := eventsource.SubscribeWithRequestAndOptions(req3)
164164
require.NoError(t, err)
165165
stream3.Close()

0 commit comments

Comments
 (0)