Validate and encode query parameters#21296
Conversation
|
I get that we can ship this much faster than a codegen update, but it's odd that callers would be responsible for encoding everything except query params. Shouldn't azcore encode everything or nothing? |
|
I was (am) struggling with that too. I agree that ideally it should be all or nothing. These are the points that swayed me to go down this path.
Totally open to other suggestions. |
|
In some ways, you could make the argument that this is how the https://play.golang.com/p/4d17WGIC452 Here, |
|
If we need to support path segments containing |
|
You've convinced me. I will retool this such that the caller encodes the query parameters (just like we do for path segments). |
|
I've moved this to be specific to pagers by adding a helper when creating a Fetcher: func(ctx context.Context, page *PagingClientGetMultiplePagesResponse) (PagingClientGetMultiplePagesResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "PagingClient.NewGetMultiplePagesPager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherHelper(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.getMultiplePagesCreateRequest(ctx, options)
})
if err != nil {
return PagingClientGetMultiplePagesResponse{}, err
}
return client.getMultiplePagesHandleResponse(resp)
}, |
d4f0a7c to
e676afe
Compare
|
Unfortunately this falls apart for paged methods that use a next link operation instead of calling |
If the endpoint passed to runtime.NewRequest contains query parameters they must be validated and encoded. The typical case is when a paged operation's nextLink value contains query parameters.
e676afe to
c71012c
Compare
|
Thinking more on the next link problem, we can relegate to solving that part via codegen and keep the consolidated helper. |
If the endpoint passed to runtime.NewRequest contains query parameters they must be validated and encoded. The typical case is when a paged operation's nextLink value contains query parameters.
|
Hi @jhendrixMSFT, it seems the fix was made in azcore v1.8.0, though we still experience the same issue with azcore v1.11.1. I see the server returned nextLink was not escaped in the second page's request. In the example below. The first response is truncated for brevity, at the end, you can see it returns For the VM client, I am still using the armcompute v4.2.0, same as when the issue was first reported. I have the assumption that the bug fix is in azcore package. Could you let us know if this is expected? We have many VMs in a resource group, if we are not able to query by VMSS, we will have to get all VMs of the entire resource group and filter by VMSS ourselves, this will consume much more API quota. Thank you. |
|
The fix is comprised of a helper in |
|
@jhendrixMSFT the latest VM client armconpute is v4.2.1, which is released in 2023 April before your fix. Do you have another version I can try? |
If the endpoint passed to runtime.NewRequest contains query parameters they must be validated and encoded. The typical case is when a paged operation's nextLink value contains query parameters.
Fixes #21291