Perhaps what you are asking for is some link verification rather than auto-expansion?
As others have noted auto-expanding shortened URLs is impractical due to the huge number of URL shorteners available and the ease of creating entirely custom ones.
Link verification could be a useful feature that would do a number of things:
- Verify that the link is actually valid i.e. check that it doesn't
404
- Verify that the link does not resolve to blacklisted sites
- Attempt to verify that the link is relevant
Whether SO would actually want to implement any of this is unclear since all the ideas here risk turning SO into a DDoS pathway since you require the platform to make some number of HTTP requests to every link posted. Obviously there are technological means to get around this such as request throttling, caching link verification results for some period of time etc. but I still have concerns about the feasibility of these techniques on a heavy traffic site like SO.
However I think the ideas at least warrant some discussion so I have attempted to detail what I mean by each and in vague terms how they would be achieved technologically.
1 - Link Validity
This is relatively easy to do, you simply send a HEAD
request (or OPTIONS
/GET
) to the given URL and see what HTTP response code comes back (likely ignoring the body where you have to use GET
). If you get a 2xx
code then you assume the link is valid.
Most of the time you want to use HEAD
but some servers won't allow HEAD
for whatever reason so you may need to use OPTIONS
or GET
as a fallback/double check that an error code a HEAD
request produced was indeed a genuine error. Of course getting a 406 Method Not Allowed
response to the HEAD
request is a clear sign you need to try a different verb
Now obviously this won't be perfect because some poorly configured sites will produce error pages with a 2xx code but there isn't much you can do about this. Also you can encounter transient errors with a site being temporarily down when you try and check it. Plus it will incorrectly flag links to content that the poster doesn't realise is behind paywalls/login gateways or as I've done in the past in this answer post despite this with a note to that effect.
Links that are checked and shown to return an error code should likely result in some visible notification to users that they've entered an apparently invalid link.
As noted in the comments there are a class of questions that are predominantly about URLs returning error codes e.g. REST, HTTP debugging etc hence why for this part of link verification I am suggesting that any errors are simply presented as a warning rather than being flagged for review in any way.
2 - Checking blacklist
Part of the point of the OP appears to be that people are using link shorteners to obscure links to undesirable content that should probably be on some blacklist e.g. lmgtfy.com
Here you probably want to check the raw link URL itself and also the response URL. Any good HTTP client will allow you to auto-follow 3xx redirects and provide you the means to retrieve the actual URL at the end of the redirect chain (because a really sneaky user could hide stuff behind multiple link shorteners). So you want to get and check both the raw and resolve URLs against the blacklist.
Links that appear in the blacklist should either be auto-removed from the post (likely with notification to the user) or cause posts to go into the low quality post review queue.
3 - Link Relevance
This is perhaps the hardest to implement and maybe not something that SO would actually want as a result since I suspect the false positive and negative rates would be too high.
What I am thinking here is that if you GET
the content at the end of the link you can apply standard term frequency analysis techniques to it and see if the terms mentioned in the linked content have some reasonable degree of correlation with terms in the question (and associated answers). The actual technical details of how you would decide what constitutes correlation are somewhat vague but I think this is at least in principal technically feasible.
Linked content with poor/zero correlation is likely to be spam though of course there are some legitimate cases where this might not be the case e.g. links to framed javadoc where the raw HTML returned at the root of the javadoc would likely have little term correlation to the question. Also posts with HTML/CSS/JS fragments would likely have high correlation with arbitrary content if you don't ignore the HTML tags in the retrieved content.
Posts where multiple links are flagged as potentially irrelevant should drop into the low quality post review queue
goo.gl
for example - it does view tracking which is useful if you link it to a specific github page for instance. Also, it does help save a few characters.