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

[fix] fix bug of creating request body #100

Merged
merged 1 commit into from
Jan 26, 2024
Merged

Conversation

Rcyyy
Copy link
Contributor

@Rcyyy Rcyyy commented Jan 26, 2024

No description provided.

@Rcyyy Rcyyy force-pushed the fix-body-generate branch from e9efb4a to cd49e0b Compare January 26, 2024 02:24
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@Tieske
Copy link
Member

Tieske commented Jan 26, 2024

Thx @Rcyyy !

@Tieske Tieske merged commit 4ee1209 into Kong:main Jan 26, 2024
6 checks passed
@Rcyyy
Copy link
Contributor Author

Rcyyy commented Jan 26, 2024

@Tieske You're welcome.
BTW I also encountered an issue when calling the API of cloudfront. I called a POST API and got a 400 http error code. I print the log of request body in the execute.lua:

<?xml version="1.0" encoding="UTF-8"?>
<input>
  <ResponseHeadersPolicyConfig xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/">
    <Name>cdn_test</Name>
    <CorsConfig>
      <AccessControlAllowMethods>
        <Items>
          <Method>GET</Method>
          <Method>POST</Method>
        </Items>
        <Quantity>2</Quantity>
      </AccessControlAllowMethods>
      <AccessControlAllowCredentials>false</AccessControlAllowCredentials>
      <AccessControlMaxAgeSec>600</AccessControlMaxAgeSec>
      <AccessControlAllowHeaders>
        <Items>
          <Header>*</Header>
        </Items>
        <Quantity>1</Quantity>
      </AccessControlAllowHeaders>
      <OriginOverride>true</OriginOverride>
      <AccessControlAllowOrigins>
        <Items>
          <Origin>*</Origin>
        </Items>
        <Quantity>1</Quantity>
      </AccessControlAllowOrigins>
    </CorsConfig>
    <CustomHeadersConfig>
      <Items>
        <ResponseHeadersPolicyCustomHeader>
          <Override>true</Override>
          <Value>rcy</Value>
          <Header>name</Header>
        </ResponseHeadersPolicyCustomHeader>
      </Items>
      <Quantity>1</Quantity>
    </CustomHeadersConfig>
  </ResponseHeadersPolicyConfig>
</input>

And the response body returned by AWS server:

<?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/">
    <Error>
        <Type>Sender</Type>
        <Code>MalformedInput</Code>
        <Message>input is not valid, expected ResponseHeadersPolicyConfig</Message>
    </Error>
    <RequestId>cd10f090-22eb-41b3-94df-4264f9d45402</RequestId>
</ErrorResponse>

Then I checked the AWS REST API document, just found that request body shouldn't have the root input tag.
After I changed the code to cut off the input tag, the call succeed.

--build.lua
    -- encode rest of the body data here
    -- poor_mans_xml_encoding(xml_data, operation.input, "input", body_tbl)

    for name, member in pairs(operation.input.members) do
      if body_tbl[name] then
        poor_mans_xml_encoding(xml_data, member, name, body_tbl[name], 0)
      end
    end

But I'm not sure if I missed something.

@Rcyyy Rcyyy deleted the fix-body-generate branch January 29, 2024 01:35
@Tieske
Copy link
Member

Tieske commented Jan 29, 2024

since this is an unrelated issue, can you please create a new github-issue?

@Tieske
Copy link
Member

Tieske commented Jan 29, 2024

nvm, just saw you already did.

@Rcyyy
Copy link
Contributor Author

Rcyyy commented Jan 29, 2024

YES, I created one issue and we can discuss there.

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

Successfully merging this pull request may close these issues.

2 participants