Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit ff37ade

Browse files
author
Maciej Winnicki
committed
temporary remote HTTP response support
1 parent 00616de commit ff37ade

File tree

4 files changed

+0
-80
lines changed

4 files changed

+0
-80
lines changed

README.md

-10
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,6 @@ Request: arbitrary payload, subscribed function receives an event in above schem
304304

305305
Response: function response
306306

307-
### Respond to an HTTP Event
308-
309-
To respond to an HTTP event a function needs to return object with following fields:
310-
311-
- `statusCode` - `int` - response status code, default: 200
312-
- `headers` - `object` - response headers
313-
- `body` - `string` - response body
314-
315-
Currently, the event gateway supports only string responses.
316-
317307
### Invoking a Registered Function (Sync Function Invocation)
318308

319309
`POST /` with `Event` header set to `invoke` and `Function-ID` set to function ID.

router/event.go

-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ type HTTPEvent struct {
3939
Method string `json:"method"`
4040
}
4141

42-
// HTTPResponse is a response schema returned by subscribed function in case of HTTP event.
43-
type HTTPResponse struct {
44-
StatusCode int `json:"statusCode"`
45-
Headers map[string]string `json:"headers"`
46-
Body string `json:"body"`
47-
}
48-
4942
const (
5043
mimeJSON = "application/json"
5144
mimeOctetStrem = "application/octet-stream"

router/integration_test.go

-49
Original file line numberDiff line numberDiff line change
@@ -144,55 +144,6 @@ func TestIntegration_HTTPSubscription(t *testing.T) {
144144
shutdownGuard.ShutdownAndWait()
145145
}
146146

147-
func TestIntegration_HTTPResponse(t *testing.T) {
148-
logCfg := zap.NewDevelopmentConfig()
149-
logCfg.DisableStacktrace = true
150-
log, _ := logCfg.Build()
151-
152-
kv, shutdownGuard := newTestEtcd()
153-
154-
testAPIServer := newConfigAPIServer(kv, log)
155-
defer testAPIServer.Close()
156-
157-
router, testRouterServer := newTestRouterServer(kv, log)
158-
defer testRouterServer.Close()
159-
160-
testTargetServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
161-
fmt.Fprintf(w, `{"statusCode":201,"headers":{"content-type":"text/html"},"body":"<head></head>"}`)
162-
}))
163-
defer testTargetServer.Close()
164-
165-
post(testAPIServer.URL+"/v1/functions",
166-
functions.Function{
167-
ID: functions.FunctionID("httpresponse"),
168-
Provider: &functions.Provider{
169-
Type: functions.HTTPEndpoint,
170-
URL: testTargetServer.URL,
171-
},
172-
})
173-
174-
post(testAPIServer.URL+"/v1/subscriptions", subscriptions.Subscription{
175-
FunctionID: functions.FunctionID("httpresponse"),
176-
Event: "http",
177-
Method: "GET",
178-
Path: "/httpresponse",
179-
})
180-
181-
select {
182-
case <-router.WaitForEndpoint(subscriptions.NewEndpointID("GET", "/httpresponse")):
183-
case <-time.After(10 * time.Second):
184-
panic("timed out waiting for endpoint to be configured!")
185-
}
186-
187-
statusCode, headers, body := get(testRouterServer.URL + "/httpresponse")
188-
assert.Equal(t, statusCode, 201)
189-
assert.Equal(t, headers.Get("content-type"), "text/html")
190-
assert.Equal(t, body, "<head></head>")
191-
192-
router.Drain()
193-
shutdownGuard.ShutdownAndWait()
194-
}
195-
196147
func wait10Seconds(ch <-chan struct{}, errMsg string) {
197148
select {
198149
case <-ch:

router/router.go

-14
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,6 @@ func (router *Router) handleSyncEvent(name string, payload []byte, w http.Respon
207207
zap.String("functionId", string(functionID)), zap.String("event", string(payload)),
208208
zap.String("response", string(resp)))
209209

210-
if name == eventHTTP {
211-
httpResponse := &HTTPResponse{StatusCode: http.StatusOK}
212-
err = json.Unmarshal(resp, httpResponse)
213-
if err == nil {
214-
for key, value := range httpResponse.Headers {
215-
w.Header().Set(key, value)
216-
}
217-
218-
w.WriteHeader(httpResponse.StatusCode)
219-
220-
resp = []byte(httpResponse.Body)
221-
}
222-
}
223-
224210
_, err = w.Write(resp)
225211
if err != nil {
226212
http.Error(w, err.Error(), http.StatusInternalServerError)

0 commit comments

Comments
 (0)