You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Marcin Lepicki <ma...@smartapp.pl> on 2009/09/29 11:10:51 UTC

External process for httpd_global_handlers

Hi,

I am developing Flex application with CouchDB backend (only GET
requests, for images). Flash/flex apps must pass security rules for
flash player (more info on
http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html),
but all I want to get special text file crossdomain.xml at
/crossdomain.xml, for example http://localhost:5984/crossdomain.xml.
Now we are using apache proxy with rewrite rule to achieve it.
I have looked at http://wiki.apache.org/couchdb/ExternalProcesses, but
only [httpd_db_handlers] are described there. In this case I want to
use external process for [httpd_global_handlers], but I can't get it
work.

I am using Python script described at
http://wiki.apache.org/couchdb/ExternalProcesses.In local.ini
configuration file I have added:

[external]
cross = python /path/bin/test.py
[httpd_global_handlers]
crossdomain.xml = {couch_httpd_external, handle_external_req, <<"cross">>}

When pointing to http://localhost:5984/crossdomain.xml I get:
{"error":"external_server_error","reason":"Broken assumption"}

When changing [httpd_global_handlers] to [httpd_db_handlers] it works
perfectly, but only for databases, like
http://localhost:5984/mydb/crossdomain.xml.

Is there any chance to get per-node external handler?

Best,
Marcin Lepicki

Re: External process for httpd_global_handlers

Posted by marek <ma...@ecn.cz>.
Dennis Geurts <de...@...> writes:

> 
> Hi Edward,
> 
> I guess from your message that you would like to accomplish the following:
> 
> - use flash to access data from a CouchDB.
> 
> This requires for the CouchDB to serve a file called 'crossdomain.xml' which 
your flash application will
> load first
> to verify it's allowed to do so. Flash requires that this file is located at 
the root of your HTTP server ( e.g. http://flash.example.org/crossdomain.xml).

After having spent several hours implementing the above, I came to realize that 
my Flash actually never sends GET request for /crossdomain.xml anyway, instead 
it tries to get this file from a standalone server running on port 843 by 
sending somewhat obscure  <policy-file-request/>\0. So the final remedy was 
Apache module mod_socket_policy_server - An AdobeĀ® Socket Policy Server

http://socketpolicyserver.com/


Hope it helps someone. 


Re: External process for httpd_global_handlers

Posted by Dennis Geurts <de...@luminis.eu>.
Hi Edward,

I guess from your message that you would like to accomplish the following:

- use flash to access data from a CouchDB.

This requires for the CouchDB to serve a file called 'crossdomain.xml' which your flash application will load first
to verify it's allowed to do so. Flash requires that this file is located at the root of your HTTP server ( e.g. http://flash.example.org/crossdomain.xml).

This can be accomplished using the virtualhost + url rewrite options CouchDB offers. This has been described earlier by Nicolas (Orr) for blitz.io (neat app!):

He describes it as follows (I tried it, and it works beautifully):

<quote>

edit your domain.com<http://domain.com/> zone and add an A record for blitz.domain.com<http://blitz.domain.com/>
edit local.ini add a vhost
===
[vhosts]
blitz.domain.com:port = /blitz/_design/blitz/_rewrite
===
restart couchdb
create a blitz database
create a new document
===
{
  "_id": "_design/blitz",
  "rewrites": [
      {
          "from": "/mu-blitz-url",
          "to": "blitz.txt",
          "method": "GET",
          "query": {
          }
      }
  ]
}
===
save the document
create a blitz.txt file and put the content blitz told you put in it
upload blitz.txt as an attachment to the design document
goto blitz.domain.com:port/mu-blitz-url
you should get the content of the blitz.txt attachment

happy days :)

ok so now to test couchdb, i did want to hit the root of couchdb where it
reports the version however if you put "../../../" in the to of the rewrite
couchdb complains too many .. as a security issue, fair enough. so did 2x ..
and thus my design doc looks like this now
===
{
  "_id": "_design/blitz",
  "_rev": "7-0b8cf881f0dc8d26198703eb86e93eb1",
  "rewrites": [
      {
          "from": "/mu-blitz-url",
          "to": "blitz.txt",
          "method": "GET",
          "query": {
          }
      },
      {
          "from": "/",
          "to": "../../",
          "method": "GET",
          "query": {
          }
      }
  ]
}
===

<unquote>

Instead of blitz, of course, you need to figure out a hostname for the CouchDB database you would like to access (e.g. flash.example.org<http://flash.example.org>)
make sure this hostname actually resolves to the machine you want to access (i.e. that runs your CouchDB)

Then edit the virtual host part in your couchdb to reflect your choice (e.g.)
===
[vhosts]
flash.example.org:5984 = /flash/_design/flash/_rewrite
===
restart couchdb afterwards (i don't think this is even necessary if you add this entry through Futon)


Use CouchApp (or any other way you like) to create a design document called _design/flash that contains the crossdomain.xml file as attachment and a rewrite
statements much like mentioned above:

  "rewrites": [
      {
          "from": "/crossdomain.xml",
          "to": "crossdomain.xml",
          "method": "GET",
          "query": {
          }
      },
      {
          "from": "/:path",
          "to": "../../:path",
          "method": "GET",
          "query": {
          }
      }
]


curl 'http://flash.example.org/crossdomain.xml' should now provide you with the crossdomain.xml you added as attachment.

The second rewrite points to the root of the database in question, allowing you to get documents in the database:

http://yourserver:5984/flash/doc1 is now accessible through: http://flash.example.org:5984/doc1

This setup should allow your flash application to connect to the CouchDB without any problems.

Hope this helps,

Dennis

On 18 mrt 2011, at 23:03, edward de jong wrote:

I have the same problem; I am trying to access couch from the same machine as
myself, and actionscript (flash) is balking because it can't get the
crossdomain.xml file from root on that socket. I have tried copying
crossdomain.xml all over the place but no go. clearly it has to be inside couch,
but I have no idea how to stuff a crossdomain.xml file into couch; it isn't a
database, but just a text file that couch is being expected to spit up when
requested.... any help would be appreciate, every single person using
actionscript + couch will have the same problem!




Re: External process for httpd_global_handlers

Posted by Kai Griffin <ka...@griffinbyteworks.com>.
I developed an early prototype of my current project with Flex (Flash), 
and ran into this issue early on.  At first, I resolved it by actually 
modifying my copy of CouchDB and recompiling it, so that it would handle 
a request for the  crossdomain file in the same way that it handles the 
welcome response.  That worked fine until I upgraded CouchDB, and 
realised I'd forever be patching the thing and it was unlikely to 
something that deserved to go into Trunk.

Ultimately, I resolved it in a way that wouldn't break or require 
frivolously hacking into the Couch source.  I put the entire Flex/Flash 
application into my CouchDB database.  It had quite a number of modules, 
images, etc... so I created a script that uploaded all these files, - 
including the home index.html - all as attachments to a single Couch 
document called "MyApp" (replace with the real name of your 
application).   In this way, Flash never bothered to ask for a 
crossdomain file, because the domain/port serving the app is the same as 
the one serving the data.   My application then became accessible using 
a URL like this:

http://www.mydomain.com:5984/MyApp/

(because the webbrowser will automatically try "index.html", that's what 
you'll get).

Cheers,
Kai

On 18/03/2011 23:03, edward de jong wrote:
> I have the same problem; I am trying to access couch from the same machine as
> myself, and actionscript (flash) is balking because it can't get the
> crossdomain.xml file from root on that socket. I have tried copying
> crossdomain.xml all over the place but no go. clearly it has to be inside couch,
> but I have no idea how to stuff a crossdomain.xml file into couch; it isn't a
> database, but just a text file that couch is being expected to spit up when
> requested.... any help would be appreciate, every single person using
> actionscript + couch will have the same problem!
>
>
>
>

Re: External process for httpd_global_handlers

Posted by edward de jong <ed...@magicmouse.com>.
I have the same problem; I am trying to access couch from the same machine as
myself, and actionscript (flash) is balking because it can't get the
crossdomain.xml file from root on that socket. I have tried copying
crossdomain.xml all over the place but no go. clearly it has to be inside couch,
but I have no idea how to stuff a crossdomain.xml file into couch; it isn't a
database, but just a text file that couch is being expected to spit up when
requested.... any help would be appreciate, every single person using
actionscript + couch will have the same problem!



Re: External process for httpd_global_handlers

Posted by Jan Lehnardt <ja...@apache.org>.
On 29 Sep 2009, at 11:10, Marcin Lepicki wrote:

> Hi,
>
> I am developing Flex application with CouchDB backend (only GET
> requests, for images). Flash/flex apps must pass security rules for
> flash player (more info on
> http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html 
> ),
> but all I want to get special text file crossdomain.xml at
> /crossdomain.xml, for example http://localhost:5984/crossdomain.xml.
> Now we are using apache proxy with rewrite rule to achieve it.
> I have looked at http://wiki.apache.org/couchdb/ExternalProcesses, but
> only [httpd_db_handlers] are described there. In this case I want to
> use external process for [httpd_global_handlers], but I can't get it
> work.
>
> I am using Python script described at
> http://wiki.apache.org/couchdb/ExternalProcesses.In local.ini
> configuration file I have added:
>
> [external]
> cross = python /path/bin/test.py
> [httpd_global_handlers]
> crossdomain.xml = {couch_httpd_external, handle_external_req,  
> <<"cross">>}
>
> When pointing to http://localhost:5984/crossdomain.xml I get:
> {"error":"external_server_error","reason":"Broken assumption"}
>
> When changing [httpd_global_handlers] to [httpd_db_handlers] it works
> perfectly, but only for databases, like
> http://localhost:5984/mydb/crossdomain.xml.
>
> Is there any chance to get per-node external handler?


You could try to use the file handler we use for Futon (/_utils) to  
serve
the global /crossdomain.xml from Erlang, without the need for
maintaining an external.

Cheers
Jan
--