couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Smith (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COUCHDB-981) req.path and req.requested_path both show the path after rewrites
Date Mon, 31 Oct 2011 01:12:32 GMT

    [ 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

        

Mime
View raw message