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: types related to message body should be bytes #132

Merged
merged 5 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,77 @@
# Table of Contents

- [v0.9.0](#v050)
- [v0.8.0](#v040)
- [v0.7.1](#v031)
- [v0.6.0](#v060)
- [v0.5.0](#v050)
- [v0.4.0](#v040)
- [v0.3.1](#v031)

## [v0.9.0]

> Released 2022/12/07

### Changes

- Fixed parameter type of `kong.service.request.set_raw_body`, return type of
`kong.service.response.get_raw_body`,
and body parameter type of `kong.response.exit` to `[]byte`.
Note that old version (before 3.0.1, or commits before cd2bcf9) of kong is incompatible after this change.
[#132](https://github.com/Kong/go-pdk/pull/132)
[kong/kong#9526](https://github.com/Kong/kong/pull/9526)

## [v0.8.0]

> Released 2021/06/09

### Changes

- fix kong.Request.GetRawBody() with buffered content by @javierguerragiraldez in [#91](https://github.com/Kong/go-pdk/pull/91)
- avoid pass-by-value of objects that contain locks. by @javierguerragiraldez in [#79](https://github.com/Kong/go-pdk/pull/79)
- bump go version by @fffonion in [#112](https://github.com/Kong/go-pdk/pull/112)

### Addtions

- chore(*) add dependabot by @mayocream in [#98](https://github.com/Kong/go-pdk/pull/98)

## [v0.7.1]

> Released 2021/10/16

### Changes

- fix testing: don't break when the plugin Exit()s [#73](https://github.com/Kong/go-pdk/pull/73)
- Ignore unexported struct fields in config struct by @ctrox [#69](https://github.com/Kong/go-pdk/pull/69)
- Start every Headers field empty but non-null [#74](https://github.com/Kong/go-pdk/pull/74)

### Additions

- Feat/plugin testing [#64](https://github.com/Kong/go-pdk/pull/64)
- Add godoc comments [#65](https://github.com/Kong/go-pdk/pull/65)

## [v0.7.0]

> Released 2021/10/16

New ProtoBuf-based communications with Kong. Requires Kong 2.4.

## [v0.6.1]

> Released 2021/04/14

### Changes

- API bugfix: port values were given as string instead of Int

## [v0.6.0]

> Released 2021/04/14

### Additions

- New Embedded Server to replace the go-pluginserver. Requires Kong v2.3.

## [v0.5.0]

> Released 2020/05/27
Expand Down Expand Up @@ -52,6 +120,10 @@

[Back to TOC](#table-of-contents)

[v0.9.0]: https://github.com/Kong/kong/compare/v0.8.0..v0.9.0
[v0.8.0]: https://github.com/Kong/kong/compare/v0.7.0..v0.8.0
[v0.7.0]: https://github.com/Kong/kong/compare/v0.6.1..v0.7.0
[v0.6.0]: https://github.com/Kong/kong/compare/v0.5.0..v0.6.0
[v0.5.0]: https://github.com/Kong/kong/compare/v0.4.0..v0.5.0
[v0.4.0]: https://github.com/Kong/kong/compare/v0.3.1..v0.4.0
[v0.3.1]: https://github.com/Kong/kong/compare/v0.3.0..v0.3.1
Expand Down
4 changes: 4 additions & 0 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func WrapString(s string) *kong_plugin_protocol.String {
return &kong_plugin_protocol.String{V: s}
}

func WrapByteString(s []byte) *kong_plugin_protocol.ByteString {
return &kong_plugin_protocol.ByteString{V: s}
}

func WrapHeaders(h map[string][]string) (*structpb.Struct, error) {
h2 := make(map[string]interface{}, len(h))
for k, v := range h {
Expand Down
2 changes: 1 addition & 1 deletion response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (r Response) SetHeaders(headers map[string][]string) error {
// Unless manually specified, this method will automatically set the
// Content-Length header in the produced response for convenience.

func (r Response) Exit(status int, body string, headers map[string][]string) {
func (r Response) Exit(status int, body []byte, headers map[string][]string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change? I know it’s expected to be the bytes type, but someone may rely on the string type already.
Should we confirm that which version should this be?

Or can we make it more smarter: accept a interface and transform string to bytes instead internally.

Copy link
Contributor Author

@StarlightIbuki StarlightIbuki Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. In this way, we gain the ability to use the new interface but also keep the old code working. But we also have some functions that are returning string, which we want to change to bytes. The trick does not work with returning values, and if we only do this to parameters, it will be inconsistent.

We do need to inform users about this breaking change.

h, _ := bridge.WrapHeaders(headers)
arg := kong_plugin_protocol.ExitArgs{
Status: int32(status),
Expand Down
Loading