-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend ReturnOverrides #763
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but worried about no test. Maybe it's time we add coprocess tests? The more logic we add without tests, the worse off we'll be in the long run.
} | ||
w.WriteHeader(int(returnObject.Request.ReturnOverrides.ResponseCode)) | ||
w.Write([]byte(returnObject.Request.ReturnOverrides.ResponseError)) | ||
return nil, 666 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does 666
mean here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
666 is a magic return code that makes the gateway halt MW processing and respond
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see we have 1666
also - we should use constants for these to make them more obvious, like return nil, mwStatusRespond
. I'll ticket that up to do once this is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fantastic idea, let's do that! So much clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me, but I'm not very familiar with this code so I'd have another set of eyes on it before merging.
coprocess_test.go
Outdated
|
||
recorder := httptest.NewRecorder() | ||
|
||
req, err := http.NewRequest("GET", "/headers", strings.NewReader("")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use a nil
body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nil
body panics 😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is buggy somewhere... forget I said anything for now :)
coprocess_test_helpers.go
Outdated
@@ -125,6 +125,7 @@ func TestTykTriggerEvent(eventName, eventPayload string) { | |||
|
|||
//export applyTestHooks | |||
func applyTestHooks(objectPtr unsafe.Pointer) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rogue empty line?
c2803f0
to
7fc4a40
Compare
@matiasinsaurralde can we fix tests? |
b3c635b
to
0867e60
Compare
@buger tests are fixed, FYI |
I'm right that this is similar to what we have now with Virtual Endpoints in our JS middleware? Also, does it affect only Coprocess (Lua, Python) plugins, or gRPC ones too (because I see that you changed protobuffers files as well)? |
I'm not very familiar with the virtual endpoint feature. Yes, basically it's possible to take control of the request flow and return a custom body. |
See #762.
As a sample plugin (test_app.py)
With manifest:
Curl output: