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

Rewrite HTTP Get options #482

Merged
merged 19 commits into from
Mar 30, 2023
Merged

Rewrite HTTP Get options #482

merged 19 commits into from
Mar 30, 2023

Conversation

jchadwick-buf
Copy link
Contributor

@jchadwick-buf jchadwick-buf commented Mar 21, 2023

  • No longer a requirement to specify URL size limit
  • Separate URL size limit option adds fallback parameter

Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

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

I have some line-level comments, but looking at this diff overall it seems that we may have overcomplicated the exported API. (That's probably my fault.)

We want a simple way for clients to opt into GETs. We also want a way to cap the size of GETs, with the default being "send any size request." Finally, we want clients to be able to require GETs, with no POST fallback (primarily for tests).

I think we can get away with just WithHTTPGet() and WithMaxGetURLSize(bytes int, fallback bool). This is super-simple to opt into, and defaults to unlimited URL size. Clients can configure a max size if necessary, and they can indicate whether they'd like to fall back to POST or not when they exceed the max. I think colocating the max and fallback will also clarify the docs and guide the user a bit more effectively.

get_policy.go Outdated Show resolved Hide resolved
get_policy.go Outdated Show resolved Hide resolved
get_policy.go Outdated Show resolved Hide resolved
client_ext_test.go Show resolved Hide resolved
option.go Outdated Show resolved Hide resolved
option.go Outdated Show resolved Hide resolved
protocol_connect.go Outdated Show resolved Hide resolved
protocol_connect.go Outdated Show resolved Hide resolved
@jchadwick-buf jchadwick-buf changed the title Add GetPolicy to control fallback of Get requests Rewrite HTTP Get options Mar 27, 2023
jchadwick-buf and others added 10 commits March 28, 2023 10:06
Along with a bit of copy-editing, clarify that all the GET-related
options apply only to the Connect protocol.
Minor nit - this is part of the house style guide.
Reverse the conditional to reduce nesting.
Make three small readability improvements to `marshalWithGet`:

- Factor out a named `isTooBig` bool.
- Add inline comments for `buildGetURL`'s naked bool param.
- For users, add some guidance on how to resolve message-too-big errors.
We should assume that compressed messages are binary and need
base64-encoding.
Responses to GET requests differ depending on the client's
Accept-Encoding header, so we should help the user out and automatically
set Vary on responses.
Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for bearing with me through some irritating changes of direction, @jchadwick-buf. I pushed some copy edits and Go nit fixes, along with two small-but-substantive changes:

  • In bufbuild@a552844, I made buildGetURL base64-encode all compressed messages (since they're probably binary).
  • In bufbuild@432894f, I had unary Connect-protocol handlers automatically set the Vary response header (since the response content changes depending on the client's Accept-Encoding). This felt like a nice quality-of-life improvement - if users want to enable HTTP caching, they should now only need to worry about the request headers they're using in their application logic.

If the commits I've added look good to you, this PR is ready to merge.

protocol_connect.go Outdated Show resolved Hide resolved
@jchadwick-buf
Copy link
Contributor Author

@akshayjshah I wound up adding a couple more changes:

  • Added a case of the test to make sure the nil client send branch is covered.
  • Fixed our use of base64; in the confusion of trying to clean up the base64 code, I accidentally forgot that the headers use standard base64, not URL-safe base64. This commit might be of interest for style check; maybe the resulting code in header.go should finally be split into its own file.

Otherwise, it's good to go from my end.

@akshayjshah
Copy link
Member

Nice final catches, John! The base64 dialect is a big one :)

This commit might be of interest for style check; maybe the resulting code in header.go should finally be split into its own file.

Good point. They're only used in the connect protocol implementation, so I moved the query param stuff to the bottom of protocol_connect.go.

@akshayjshah akshayjshah merged commit 439ad37 into get-support Mar 30, 2023
@akshayjshah akshayjshah deleted the get-policy branch March 30, 2023 14:48
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