sporkmonger / addressable

Addressable is an alternative implementation to the URI implementation that is part of Ruby's standard library. It is flexible, offers heuristic parsing, and additionally provides extensive support for IRIs and URI templates.
Apache License 2.0
1.55k stars 265 forks source link

add 'naked' or 'apex_domain' output. #54

Closed maxwell closed 12 years ago

maxwell commented 12 years ago

This would be a 'nice to have' feature of addressable.

http://blog.cloudflare.com/zone-apex-naked-domain-root-domain-cname-supp

(see my first comment, as I wasn't very clear when first submitting this Feature request)

sporkmonger commented 12 years ago

Sure... uhm, if it were possible or in any way in-scope for the library. This is something that really needs to be solved at the DNS / web server level. Addressable can't really help here.

maxwell commented 12 years ago

Hi, sorry, I guess I was not clear enough.

For example say I have some sort of SSL requirement which requires 'www' in my url. (ie I am using EC2 or Heroku).

However, in the case that people are Webfingering my domain, these requests are going to my 'apex' domain.

a = Addressable::URI.parse('https://www.myssldomain.com')
a.authority  #=> www.myssldomain.com
a.host #=> www.myssldomain.com

#what I am trying to propose would be kind of nice

a.apex_domain #=> myssldomain.com

As you mentioned, I realize this is not hard to do by gsubing out the 'www.', but it feels dirty and something Addressable or URI should accomplish, given that Addressable has other nice to haves in the library.

sporkmonger commented 12 years ago

Ok, I see what you mean. That's fair. Low priority at the moment though.

sporkmonger commented 12 years ago

Started thinking about trying to implement this today. After about 15 minutes I realized that this isn't actually possible to build correctly without rather extensive tables of TLDs and second level domains that I'm not inclined to introduce.

uri = Addressable::URI.parse('https://www.example.com/')
uri.zone_apex # => 'example.com'
uri = Addressable::URI.parse('https://www.example.co.ke/')
uri.zone_apex # => 'example.co.ke'

If it could be done with a simple regular expression, that'd be one thing, but as far as I can tell, the zone apex can exist at several different levels depending on where and how the domain was registered.