7 ms·
What is the maximum length of a URL?
- jpswade 14y agoAs of 2012, they are as long as the platform will support because of the Data URI scheme.
- cek 14y agoThe title of the post & the underlying SO article discuss URLs. A data: URI is not a URL, but a URI. People get confused about this all the time, but a URI is not necessarily a URL. A URL is always a URI. A URN is also a URI and might be a URL as well.[0] Interesting side note is how, in 1997, with the original uuid: draft[1] I goofed and didn't recognize uuid: was really a URN. This was corrected in RFC 4122 in 2005[2]. [0] http://en.wikipedia.org/wiki/Uniform_resource_identifier http://en.wikipedia.org/wiki/Uniform_resource_identifier [1] http://tools.ietf.org/html/draft-kindel-uuid-uri-00 http://tools.ietf.org/html/draft-kindel-uuid-uri-00 [2] http://www.ietf.org/rfc/rfc4122.txt http://www.ietf.org/rfc/rfc4122.txt
- jpswade 14y agoThe data URI scheme is defined in RFC 2397. See: http://tools.ietf.org/html/rfc2397 http://tools.ietf.org/html/rfc2397 Entitled as 'The "data" URL scheme'. Either way, it doesn't matter, because the OP has provided such limited details as to why this is required knowledge that the question is as irrelevant as the accepted answer.
- lucb1e 14y agoI still think you should try not to exceed 255 characters, at least for the part before the hash sign. A good URL should not change, and anything this large is almost bound to change rather soon. The data URI scheme does not really apply here since it's never sent to any server. If a browser understands data URIs, it should logically also allow such long URLs.
- Frozenlock 14y agoI use long URL because I want unique URL that will never change. Specifying what item(s) should be targeted in a pool of possibly millions, with endless possible combinations is bound to require some kind of precise pointer. Here is an example URL I use: https://bacnethelp.com/vis/overview/KHs6cHJvamVjdC1pZCAiNTA1YTEyNWU0NGFlNDJlMDVhNzUwYzk3IiwgOm9iamVjdC1pbnN0YW5jZSAiMiIsIDpvYmplY3QtdHlwZSAiMCIsIDpkZXZpY2UtaWQgIjEyMzQifSB7OnByb2plY3QtaWQgIjUwNWExMjVlNDRhZTQyZTA1YTc1MGM5NyIsIDpvYmplY3QtaW5zdGFuY2UgIjEiLCA6b2JqZWN0LXR5cGUgIjAiLCA6ZGV2aWNlLWlkICIxMjM0In0gezpwcm9qZWN0LWlkICI1MDVhMTI1ZTQ0YWU0MmUwNWE3NTBjOTciLCA6b2JqZWN0LWluc3RhbmNlICIwIiwgOm9iamVjdC10eXBlICIwIiwgOmRldmljZS1pZCAiMTIzNCJ9KQ. https://bacnethelp.com/vis/overview/KHs6cHJvamVjdC1pZCAiNTA1.... What I could do, however, is use some kind of shortening url scheme, kinda like google maps: http://goo.gl/maps/3uP8y http://goo.gl/maps/3uP8y. I'm still uncertain about which way is better. EDIT: Of course I mean a local shortening url, pointing to my own databases.
- dorianj 14y agoIn the example URL you gave, the content of the URL (base64): ({:project-id "505a125e44ae42e05a750c97", :object-instance "2", :object-type "0", :device-id "1234"} {:project-id "505a125e44ae42e05a750c97", :object-instance "1", :object-type "0", :device-id "1234"} {:project-id "505a125e44ae42e05a750c97", :object-instance "0", :object-type "0", :device-id "1234"}) seems like it would be better stored on the server in redis or something (or, at least if leaving it in the URL, a more compact deduplicated format might be worthwhile)
- mnarayan01 14y agoPart of me wonders what would happen if someone where to Base64 encode something like ({:project-id {:conditions "true); DELETE FROM projects WHERE (true"}})
- Frozenlock 14y agoNothing, it's not sql. It's a clojure map with all the necessary info to find the different components. But nice reflex! ;-)
- ojiikun 14y agoNo matter how long you think they can get, take care if you are going thru a load balancer - many, (those by Citrix come to mind) can mysteriously truncate URLs and cause all manner of weird bugs. And, of course, insert here a long-winded rant about how broken your data model is if you need more than about 1000 chars. ;)
- afandian 14y agoWhat about lots of GET params? Doesn't seem like lots of those means you have a broken data model.
- mistercow 14y agoI think if you have nearly 1KB of GET data, something is definitely wrong.
- waitwhat 14y ago1KB of GET data is ~25 UUIDs. That doesn't seem excessive.
- mistercow 14y agoThat seems like a lot of UUIDs to be passing via GET. If you send your UUIDs in base 64, you can fit 125 into 1KB.
- mnarayan01 14y agoEven 125 is not all that much if the resources are not being directly shown to the user (e.g. automated services, etc).
- mistercow 14y agoI'm trying to understand why you wouldn't use POST in that case.
- asiermarques 14y agoDepends on your web server configuration http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestline http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestl...
- adamauckland 14y agoWhat about a RESTful API where you pass in a list of IDs to retrieve from the server? You'd want to use a GET so it's idempotent but I can't see how you'd make an exceedingly long list of IDs without using a data payload underneath the GET statement.
- darrhiggs 14y agoDon't do it that way then. How about a using /queries collection? You could create a query there and have the server return a link to the results using the 'location' header.
- mnarayan01 14y agoOr you could just use a PUT request with the ids in the request body. I get the reasoning behind doing it with a POST -> GET, but doing that as a default case would be nuts. If nothing else either I can a) DOS you trivially or b) you might as well use PUT because the result URI is going to be far from permanent.
- adamauckland 14y agoThis is probably the most correct response. It still bothers me that because GET can't take bulk parameters I either have to use a PUT or spool many GETs (which still isn't as fast as one GET)
- Dylan16807 14y agoI'm looking at this suggestion and somehow it seems like the exact opposite of the intent of REST. You're looking at a query that doesn't make any changes on the server and trying to figure out how to do it. Then you run into the fact that GET is incapable of passing bulk data the way the other verbs can. And instead of being slightly misleading by wrapping what is a GET at heart inside a POST, you would rather make the query cause changes on the server just so that it uses 'POST' correctly. You're taking a clean, standalone query and perverting it into a dirtying one.
- philjohn 14y ago
- martinced 14y agoIf you control both the client and the server you can have quite long URLs. I don't agree that a long URLs necessarily indicates a broken design. I've done it and configure my web server (Tomcat) to accept longer GET requests (so +1 to 'asiermarques' here, who pointed out that it depends on how the web server is configured too). There are services out there, like Google Charts if I'm not mistaken (but I may be mistaking it with something else) which, by the way they work, forces you to create quite long URLs. It generates a graph on the fly and nothing is modified on the server, so a GET is used, not a POST (which, IMHO, makes sense). From the thread I seem to understand that the Data URI scheme implies that company should start to upgrade or replace their broken load balancer that "mysteriously" truncate URLs and cause all manner of weird bugs ; )
- danielweber 14y agoIf you control both the client and the server . . . and all proxies that may be in-between. I've debugged more than one client issue where people were doing something really weird over port 80.
- Dylan16807 14y agoThe thing is, if you put raw data in a URL it's no longer really a URL. If you're transforming data it makes sense to put the data somewhere else, and somewhere else means POST. Even if the data doesn't get stored permanently. REST never really considered requests that don't involve resources..
- bmuon 14y agoMany comments seem to focus on traditional GET requests in which case long URLs are usually a smell. But there's a rather new requirement in the web that conflicts with limits on URL length: the use of modules for front-end JavaScript code. The best practice for modules is usually expressed as: 1) Write small modules 2) Concatenate scripts If you try to automate module concatenation then you'll get URLs like http://example.com/combo?foo.js&bar.js&baz.js http://example.com/combo?foo.js&bar.js&baz.js, which combined with "write small modules" can mean a long list of small modules that easily reaches 2000 characters.
- grncdr 14y agoWhat is the use case for concatenating scripts on request rather than as a build step?
- maw 14y agoNot having a build step at all. That's worth aiming for if you can do it without hamstringing yourself, but it isn't how I would go about it.
- jap 14y agoOne use case is if the scripts are part of a large framework on a 3rd party server. See e.g. the YUI 3 library configurator: http://yuilibrary.com/yui/configurator/ http://yuilibrary.com/yui/configurator/
- gcb0 14y agoIt all boils down to the server/client. as in: does it matter if the http spec says X if the most used browser only sends X/2? back in 90-something i had to research that for url and cookies. msdn specs said something like "[url|cookies] should be at least [some size]" mozilla's and w3c specs said: "[url|cookies] should be at most [some size]" for everything. url lenght. cookie lenght. number of cookies per domain. number of cookies per subdomain... it was like that for ALL items. one said 'at least' the other 'at most', and for added fun, all the values where exactly the same on both.
- jacques_chester 14y agoThe thing is that the RFCs use MAY and SHOULD for these things. Not MUST or SHALL. So it's implementation-defined from the get-go. I presume that the people writing HTTP servers and clients usually found it easier to allocate a fixed-length char array.
- gcb0 14y agoMay vs Should i can take. but At least vs At most I sincerely can't.
- ry0ohki 14y agoAnother practical limit, I tried to register a 60ish character URL, and neither GoDaddy nor NameCheap would allow it.
- jonknee 14y agoYou tried to register a domain, not a URL.
- mistercow 14y agoThat's a hard standardized limit, not merely a practical limit. Each label in a domain name (the parts after the :// and before the first slash, which are separated by dots) has a limit of 63 characters, and the full length of the domain name is limited to 253 characters.
- bodhi 14y agoIn case you were curious, from Wikipedia[1]: > Each label may contain up to 63 characters. The full domain name may not exceed a total length of 253 characters in its external dotted-label specification. In this context "label" means a segment of the name, so in "www.example.com." "www", "example", and "com" are all labels. The next sentence: > In practice, some domain registries may have shorter limits. alludes to your problem somewhat ;) [1]: http://en.wikipedia.org/wiki/Domain_Name_System http://en.wikipedia.org/wiki/Domain_Name_System
- Dylan16807 14y agoBy character do you mean unicode or ascii?
- skwosh 14y agoOther applications of long URLs: - Unique and unforgeable references for capability-based security (e.g. the Waterken Server) - Serialized continuations, or unforgeable references to server-side continuations (as in continuation-based web servers)