Skip to content
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

feature: allow setting custom HTTP response headers and status code in scripts #4745

Open
vzhemchuzhnikov opened this issue Nov 19, 2024 · 2 comments
Assignees

Comments

@vzhemchuzhnikov
Copy link

Note: this is only relevant for sync executions.

Currently when script executes, either through webhook or http route, we cannot control the headers and status codes that a client will receive. All responses are sent with 200 status code and the json body.

I propose to add more control to developers, so we could change the response as we need. For example, we could use it to set cookies, redirect and so on.

Ideally, it could be implemented with a special object for every programming language (except shells), which, if being returned, would be converted to a native response for the framework that the API itself uses. However, I understand that could be too much work and will make adding a new language support harder.

As a simpler alternative, it could be implemented just by adding a pre-defined key into the response object, that the API would interpret when returning the response. This could cause collisions with existing responses, so we could name it something like _windmill_http_response_metadata (it would be even better if we could change the name in the settings).
So, to customize the response, a script should:

  1. Return an object (dict, struct, etc...)
  2. That will contain a pre-defined key

For example, if a python script returns a dict

{
    "_windmill_http_response_metadata": {
        "status_code": 201,
        "headers": {
            "set-cookies": "<your cookies>"
        }
    },
    "message": "Hello world"
}

API should send an http response with the 201 code and set-cookies headers, keeping the default application/json content type and the body, if called through webhook or http route.

@HugoCasa
Copy link
Contributor

it's already possible for status code: https://www.windmill.dev/docs/script_editor/custom_response_code
We can add something similar for headers

@vzhemchuzhnikov
Copy link
Author

@HugoCasa cool! I somehow missed the status code. If you could add the same thing for headers, that'd be really great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants