Skip to content

Commit

Permalink
fix(sdk): cloud.ApiRequest.body is an empty string for GET requests (
Browse files Browse the repository at this point in the history
…#6572)

Fixes #6565

## Checklist

- [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
eladcon authored May 28, 2024
1 parent 31ba2e0 commit 1d09a8b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion examples/tests/sdk_tests/api/get.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let body = "ok!";
api.get("/path", inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
assert(req.method == cloud.HttpMethod.GET);
assert(req.path == "/path");
assert(req.body?.length == 0);
assert(req.body == nil);
assert(req.headers?.get("content-type") == "application/json");

return cloud.ApiResponse {
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/sdk_tests/api/options.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let path = "/path";
api.options(path, inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
assert(req.method == cloud.HttpMethod.OPTIONS);
assert(req.path == path);
assert(req.body?.length == 0);
assert(req.body == nil);

return cloud.ApiResponse {
status: 204
Expand All @@ -19,7 +19,7 @@ api.options(path, inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
api.head(path, inflight (req: cloud.ApiRequest): cloud.ApiResponse => {
assert(req.method == cloud.HttpMethod.HEAD);
assert(req.path == path);
assert(req.body?.length == 0);
assert(req.body == nil);

return cloud.ApiResponse {
status: 204
Expand Down
2 changes: 1 addition & 1 deletion libs/wingsdk/src/target-sim/api.inflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class Api
function transformRequest(req: express.Request): ApiRequest {
return {
headers: sanitizeParamLikeObject(req.headers),
body: Object.keys(req.body).length > 0 ? req.body : "",
body: Object.keys(req.body).length > 0 ? req.body : undefined,
method: parseHttpMethod(req.method),
path: req.path,
query: sanitizeParamLikeObject(req.query as any),
Expand Down
Loading

0 comments on commit 1d09a8b

Please sign in to comment.