Batching - safeguard for max url length
See original GitHub issue👋 Do you want to pick this up? See https://github.com/trpc/trpc/issues/506#issuecomment-1016626260
Challenge described:
- Max characters for a url is ~2k characters (I think)
- Currently the batching lumps everything in a request as
/api/trpc/posts.byId,posts.byId.query,posts.byId?batch=1&input=${encodeURIComponent(JSON.stringify(input))}
This could potentially lead to situations where the client constructs a url that is too long.
A few things we could do to prevent this
- Change the way we build the query
- Given query, this could be built like like
/api/trpc/3*posts.byId?batch=x
- Given query, this could be built like like
- Make sure the data loader splits up the queries into separate requests when exceeding limit of
x
- What I don’t want to do is to use anything but
GET
for queries
Refs in the code
- https://github.com/trpc/trpc/blob/main/packages/client/src/internals/dataLoader.ts
- https://github.com/trpc/trpc/blob/main/packages/client/src/internals/httpRequest.ts
I think the best interface way of handling this is to allow doing httpBatchLink({ maxURILength: 2048 })
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Maximum length of HTTP GET request - Stack Overflow
Most web servers have a limit of 8192 bytes (8 KB), which is usually configurable somewhere in the server configuration.
Read more >Long HTTP GET requests and a Uri max length constraint
Hello,. We've got a requirement on our project (where we use WCF Data Services 5.0) to allow consumers to send OData requests with...
Read more >Enforcement of URL length limit for Web API requests
Enforcement of URL length limit for Web API requests ... Requests to the Web API are subject to a 16,000-character limit for the...
Read more >Configuring the maximum allowed URL length for an HTTP ...
The BIG-IP ASM system checks the URL length of HTTP requests as part of HTTP protocol compliant enforcement. The system uses the ecard_max_http...
Read more >SharePoint Online: Find All Files Exceeding Maximum URL ...
This PowerShell script scans Excel files in all document libraries in a given site collection, checks if any file URL length exceeds the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/trpc/trpc/releases/tag/v9.18.0
Yes! Here’s some rough steps:
maxBatchSize?: number
tohttpBatchLink
interface HTTPBatchLinkOptions extends HTTPLinkOptions { maxBatchSize?: number }
opts?: { maxBatchSize?: number }
to https://github.com/trpc/trpc/blob/main/packages/client/src/internals/dataLoader.ts#L23httpBatchLink
todataLoader
(https://github.com/trpc/trpc/blob/71568822249cfd9178b2ca63d5dbb376e8bbf1de/packages/client/src/links/httpBatchLink.ts#L40-L42)dispatch()
if length exceedsmaxBatchSize
here: https://github.com/trpc/trpc/blob/main/packages/client/src/internals/dataLoader.ts#L71