You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Caolan McMahon (JIRA)" <ji...@apache.org> on 2010/12/08 18:06:00 UTC

[jira] Created: (COUCHDB-981) req.path and req.requested_path both show the path after rewrites

req.path and req.requested_path both show the path after rewrites
-----------------------------------------------------------------

                 Key: COUCHDB-981
                 URL: https://issues.apache.org/jira/browse/COUCHDB-981
             Project: CouchDB
          Issue Type: Bug
          Components: JavaScript View Server
    Affects Versions: 1.1, 1.2
         Environment: Ubuntu 9.10 (karmic)
            Reporter: Caolan McMahon


The request object passed to show functions contains properties for 'path' and 'requested_path'. Both of these properties return the path *after* rewrites have taken place, it was my understanding (from talking to benoitc and others on #couchdb) that requested_path should show the path prior to the rewrite.

With the following design doc:

{
   "_id": "_design/test",
   "_rev": "1-be48afc903d2ca4b879efa211b354d88",
   "shows": {
       "testshow": "function(doc, req){log(req); return 'testshow';}"
   },
   "rewrites": [
       {
           "from": "/",
           "to": "_show/testshow"
       }
   ]
}

Requesting the _rewrite url:

$ curl http://localhost:5984/test/_design/test/_rewrite/
testshow

Shows the following in the couchdb log output:

[info] [<0.592.0>] OS Process #Port<0.2152> Log :: {"info":{"db_name":"test","doc_count":1,"doc_del_count":0,"update_seq":1,"purge_seq":0,"compact_running":false,"disk_size":4185,"instance_start_time":"1291827724231276","disk_format_version":5,"committed_update_seq":1},"id":null,"uuid":"b37350616734d6a48f6d63fefd00156c","method":"GET","requested_path":["test","_design","test","_show","testshow"],"path":["test","_design","test","_show","testshow"],"query":{},"headers":{"Accept":"*/*","Host":"localhost:5984","User-Agent":"curl/7.19.5 (x86_64-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15"},"body":"undefined","peer":"127.0.0.1","form":{},"cookie":{},"userCtx":{"db":"test","name":null,"roles":["_admin"]},"secObj":{}}
[info] [<0.574.0>] 127.0.0.1 - - 'GET' /test/_design/test/_show/testshow 200

You'll notice that both 'path' and 'requested_path' are set to: 
["test","_design","test","_show","testshow"]

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (COUCHDB-981) req.path and req.requested_path both show the path after rewrites

Posted by "Caolan McMahon (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-981?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12969393#action_12969393 ] 

Caolan McMahon commented on COUCHDB-981:
----------------------------------------

After experimenting further I've found that it will work if you set up a vhost.
I assume this was the original use-case, although I think it would make sense to populate it with the pre-rewrite url if not accessed through a virtual host.

> req.path and req.requested_path both show the path after rewrites
> -----------------------------------------------------------------
>
>                 Key: COUCHDB-981
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-981
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.1, 1.2
>         Environment: Ubuntu 9.10 (karmic)
>            Reporter: Caolan McMahon
>
> The request object passed to show functions contains properties for 'path' and 'requested_path'. Both of these properties return the path *after* rewrites have taken place, it was my understanding (from talking to benoitc and others on #couchdb) that requested_path should show the path prior to the rewrite.
> With the following design doc:
> {
>    "_id": "_design/test",
>    "_rev": "1-be48afc903d2ca4b879efa211b354d88",
>    "shows": {
>        "testshow": "function(doc, req){log(req); return 'testshow';}"
>    },
>    "rewrites": [
>        {
>            "from": "/",
>            "to": "_show/testshow"
>        }
>    ]
> }
> Requesting the _rewrite url:
> $ curl http://localhost:5984/test/_design/test/_rewrite/
> testshow
> Shows the following in the couchdb log output:
> [info] [<0.592.0>] OS Process #Port<0.2152> Log :: {"info":{"db_name":"test","doc_count":1,"doc_del_count":0,"update_seq":1,"purge_seq":0,"compact_running":false,"disk_size":4185,"instance_start_time":"1291827724231276","disk_format_version":5,"committed_update_seq":1},"id":null,"uuid":"b37350616734d6a48f6d63fefd00156c","method":"GET","requested_path":["test","_design","test","_show","testshow"],"path":["test","_design","test","_show","testshow"],"query":{},"headers":{"Accept":"*/*","Host":"localhost:5984","User-Agent":"curl/7.19.5 (x86_64-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15"},"body":"undefined","peer":"127.0.0.1","form":{},"cookie":{},"userCtx":{"db":"test","name":null,"roles":["_admin"]},"secObj":{}}
> [info] [<0.574.0>] 127.0.0.1 - - 'GET' /test/_design/test/_show/testshow 200
> You'll notice that both 'path' and 'requested_path' are set to: 
> ["test","_design","test","_show","testshow"]

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] [Commented] (COUCHDB-981) req.path and req.requested_path both show the path after rewrites

Posted by "Jan Lehnardt (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-981?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13139789#comment-13139789 ] 

Jan Lehnardt commented on COUCHDB-981:
--------------------------------------

Since you can combine ghosts and rewrites, I'm not sure what's the best step here.

maybe a new property that includes all permutations and doesn't break BC.

"paths": {
  "requested_path": {
    "raw": "/foo/bar/baz/",
    "segments": ["foo","bar","baz"]
  },
  "after_vhost_path": {
    "raw": "/foo/bar/baz/",
    "segments": ["foo","bar","baz"]
  },
  "after_rewrite_path": {
    "raw": "/foo/bar/baz/",
    "segments": ["foo","bar","baz"]
  }
}


                
> req.path and req.requested_path both show the path after rewrites
> -----------------------------------------------------------------
>
>                 Key: COUCHDB-981
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-981
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.1, 1.2
>         Environment: Ubuntu 9.10 (karmic)
>            Reporter: Caolan McMahon
>
> The request object passed to show functions contains properties for 'path' and 'requested_path'. Both of these properties return the path *after* rewrites have taken place, it was my understanding (from talking to benoitc and others on #couchdb) that requested_path should show the path prior to the rewrite.
> With the following design doc:
> {
>    "_id": "_design/test",
>    "_rev": "1-be48afc903d2ca4b879efa211b354d88",
>    "shows": {
>        "testshow": "function(doc, req){log(req); return 'testshow';}"
>    },
>    "rewrites": [
>        {
>            "from": "/",
>            "to": "_show/testshow"
>        }
>    ]
> }
> Requesting the _rewrite url:
> $ curl http://localhost:5984/test/_design/test/_rewrite/
> testshow
> Shows the following in the couchdb log output:
> [info] [<0.592.0>] OS Process #Port<0.2152> Log :: {"info":{"db_name":"test","doc_count":1,"doc_del_count":0,"update_seq":1,"purge_seq":0,"compact_running":false,"disk_size":4185,"instance_start_time":"1291827724231276","disk_format_version":5,"committed_update_seq":1},"id":null,"uuid":"b37350616734d6a48f6d63fefd00156c","method":"GET","requested_path":["test","_design","test","_show","testshow"],"path":["test","_design","test","_show","testshow"],"query":{},"headers":{"Accept":"*/*","Host":"localhost:5984","User-Agent":"curl/7.19.5 (x86_64-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15"},"body":"undefined","peer":"127.0.0.1","form":{},"cookie":{},"userCtx":{"db":"test","name":null,"roles":["_admin"]},"secObj":{}}
> [info] [<0.574.0>] 127.0.0.1 - - 'GET' /test/_design/test/_show/testshow 200
> You'll notice that both 'path' and 'requested_path' are set to: 
> ["test","_design","test","_show","testshow"]

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (COUCHDB-981) req.path and req.requested_path both show the path after rewrites

Posted by "Jason Smith (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-981?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13139846#comment-13139846 ] 

Jason Smith commented on COUCHDB-981:
-------------------------------------

Rewrites are scary. Combining them with ghosts is just terrifying. Must be Halloween.

tl;dr: I have a working patch set that fixes this specific bug but it is a bit invasive and a bit architecture astronautty, but I am happy to publish it if there is interest.

We needed this fixed at Iris Couch a long time ago, and the result is req.iris.requested_path with the real requested path. No tricks. No games. The real requested path. It works perfectly. Unfortunately, the patch set modifies mochiweb and I assume it would be unwelcome here.

The design of vhosts and rewrites is great! In both cases, a fresh #httpd or MochiReq object is created and processing completely restarts. For security and correctness, that is an excellent approach. Unfortunately, vhosts and rewrites discard the old MochiReq object (module) and create a new one. Information is lost.

The trick I used was to add an 'oob' (Out Of Band) parameter to the mochiweb_request constructor. It simply stores an arbitrary term there, and you can get it with MochiReq:get(oob). Couch uses this storage to note anything important. When request processing begins, it stores the original request path. Vhosts and rewrites simply copy this value. When it's time to build the JSON request object in couch_httpd_external/json_req_obj/3, the true and proper requested_path is there, safe and sound, in a MochiReq:get(oob) tagged tuple.

(I don't remember why I built this into the mochi_request object and not the couch #httpd{} but I think there was a a compelling reason to do it "the hard way.")

I mention all of this because I have subsequently found out-of-band storage in the MochiReq to be extremely useful for other features. For example, we ping the couch to monitor its health. Those requests are flagged no_log in the OOB, and when it's time to log them, the logger no-ops instead. That way, users' logs reflect only stuff that they care about.

                
> req.path and req.requested_path both show the path after rewrites
> -----------------------------------------------------------------
>
>                 Key: COUCHDB-981
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-981
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.1, 1.2
>         Environment: Ubuntu 9.10 (karmic)
>            Reporter: Caolan McMahon
>
> The request object passed to show functions contains properties for 'path' and 'requested_path'. Both of these properties return the path *after* rewrites have taken place, it was my understanding (from talking to benoitc and others on #couchdb) that requested_path should show the path prior to the rewrite.
> With the following design doc:
> {
>    "_id": "_design/test",
>    "_rev": "1-be48afc903d2ca4b879efa211b354d88",
>    "shows": {
>        "testshow": "function(doc, req){log(req); return 'testshow';}"
>    },
>    "rewrites": [
>        {
>            "from": "/",
>            "to": "_show/testshow"
>        }
>    ]
> }
> Requesting the _rewrite url:
> $ curl http://localhost:5984/test/_design/test/_rewrite/
> testshow
> Shows the following in the couchdb log output:
> [info] [<0.592.0>] OS Process #Port<0.2152> Log :: {"info":{"db_name":"test","doc_count":1,"doc_del_count":0,"update_seq":1,"purge_seq":0,"compact_running":false,"disk_size":4185,"instance_start_time":"1291827724231276","disk_format_version":5,"committed_update_seq":1},"id":null,"uuid":"b37350616734d6a48f6d63fefd00156c","method":"GET","requested_path":["test","_design","test","_show","testshow"],"path":["test","_design","test","_show","testshow"],"query":{},"headers":{"Accept":"*/*","Host":"localhost:5984","User-Agent":"curl/7.19.5 (x86_64-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15"},"body":"undefined","peer":"127.0.0.1","form":{},"cookie":{},"userCtx":{"db":"test","name":null,"roles":["_admin"]},"secObj":{}}
> [info] [<0.574.0>] 127.0.0.1 - - 'GET' /test/_design/test/_show/testshow 200
> You'll notice that both 'path' and 'requested_path' are set to: 
> ["test","_design","test","_show","testshow"]

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira