The Insert module should not insert CDN URLs, because that prevents users from switching from one CDN to another.

Also see #1844786: Document that old CDN Far Future URLs fail to work if the Drupal site's private key or hash salt have changed.

Not sure yet how we're supposed to solve this, but it definitely needs to be solved. The Insert module should always insert either root-relative or protocol-relative, non-CDN URLs.

CommentFileSizeAuthor
#8 1863530-8.patch843 bytesWim Leers
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kmonty’s picture

Thanks for taking on this issue, Wim!

I think one of the more obvious (but potentially less-sexy) solutions is to use an input filter when inserting an image. If there was something like [img:/sites/default/files/imagecache/preset/image.jpg,alt=this is alt text\, escape all commas yada yada] inserted into the node body, the CDN module could process that and ensure the image URL was always correct. Potentially, there could even be a hook_uninstall to manually recreate HTML img tags if the CDN module was not enabled.

The drawback here is that the image wouldn't appear in WSYIWYG editors (unless we wrote a plugin for each editor).

Wim Leers’s picture

That wouldn't solve the problem.

The root cause for the problem is that we have no contextual information in file_create_url(), and thus also not in hook_file_url_alter(). i.e. the purpose of the insert module is different from the typical purpose: instead of serving production traffic, you're generating "canonical content". (I hope that makes sense, I can't think of a better explanation right now.)

So, the question is: how can we know that we're generating "canonical content" (or even simpler by being narrower: how can we know the Insert module is calling file_create_url())?

iamEAP’s picture

Extremely dirty, but you could call debug_backtrace() to find the caller of file_create_url(). I believe the Memcache module uses this trick to get around some limitations of Core.

ttkaminski’s picture

A workaround for this insert issue is to include an exception for authenticated users. In the blacklist, add: node/*/edit

Or you can add the patch to the insert.module. See: #2001284: Absolute urls inserted with CDN module enabled

Vacilando’s picture

Just also been bitten by this nasty problem... as usual, in hurry, switching off the CDN module quickly solved the problem. But I would love to see a solution so that I can use the module again.

EDIT: Tried entering */edit under Exceptions -> "DRUPAL PATH FOR AUTHENTICATED USERS" in CDN config screen but that did not help.

plopesc’s picture

Issue summary: View changes

Hello

Looks like I fixed this bug in my project adding both node/*/edit and file/ajax/* URLs to the blacklist DRUPAL PATH FOR AUTHENTICATED USERS

Now, when uploading images, hook_file_url_alter() does not rewrite the URL and everything works fine for me.

Regards

Wim Leers’s picture

Status: Active » Reviewed & tested by the community

Hrm, that makes total sense. In fact, I think just file/ajax/* would do the trick. It's still a hack, but it's a reasonable one.

Will test that some more before committing, just to make sure.

Wim Leers’s picture

Title: Don't generate CDN URLs when using the Insert module » Don't generate CDN URLs when using the Insert module by blacklisting file/ajax/*
FileSize
843 bytes

Confirmed to be working.

  • Wim Leers committed 40c0d3e on
    Issue #1863530 by Wim Leers: Don't generate CDN URLs when using the...
Wim Leers’s picture

Priority: Critical » Normal
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.