CouchDB
  1. CouchDB
  2. COUCHDB-472

handle custom CouchdDB welcome page

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.10
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Skill Level:
      New Contributors Level (Easy)

      Description

      This change modify behaviour of Welcome handler by allowing admin to customize the welcome page. If content is "application/json" it will send current json object, if not, it will send an html page or redirect to another path.

      This patch change the confugration string to a tupple

      {WelcomeMsg, WelcomePage}

      . WelcomePage could be a string for DocumentRoot where it will find welcome.html page or a tupple

      {redirect, Url}

      Ex if in config you have:
      / = {couch_httpd_misc_handlers, handle_welcome_req, {<<"Welcome">>, "/usr/local/share/couchdb/www"}}

      If Accept content is application/json Couchdb will send :
      "couchdb":"Welcome","version":"0.10.0a"}

      If other it will send welcome.html.

      if you replace "/usr/local/share/couchdb/www" by

      {redirect, <<"/_utils">>}

       user will be redirected on futon.

      1. couchdb_welcome.patch
        5 kB
        Benoit Chesneau
      2. screenshot.png
        118 kB
        Benoit Chesneau
      3. couchdb_welcome2.patch
        9 kB
        Benoit Chesneau
      4. couchdb_welcome3.patch
        4 kB
        Benoit Chesneau
      5. COUCHDB-472.patch
        6 kB
        Benoit Chesneau
      6. Welcome page screenshot.jpg
        64 kB
        Benoit Chesneau
      7. COUCHDB-472-2.patch
        6 kB
        Benoit Chesneau

        Issue Links

          Activity

          Hide
          Joan Touzet added a comment -

          Propose pushing this out and repurposing this task:

          1. I propose closing COUCHDB-348 as WONTFIX due to what Benoit says above, browsers and clients are bugged so not much that can be done here
          2. Fauxton / new Futon work could subsumesome of this work, in terms of supporting plugins and new dashboard functionality.
          3. This could then morph into a new homepage for Fauxton/new Futon which is user-editable in a friendlier way than this.

          Show
          Joan Touzet added a comment - Propose pushing this out and repurposing this task: 1. I propose closing COUCHDB-348 as WONTFIX due to what Benoit says above, browsers and clients are bugged so not much that can be done here 2. Fauxton / new Futon work could subsumesome of this work, in terms of supporting plugins and new dashboard functionality. 3. This could then morph into a new homepage for Fauxton/new Futon which is user-editable in a friendlier way than this.
          Hide
          Jan Lehnardt added a comment -

          Bump to 1.3.x

          Show
          Jan Lehnardt added a comment - Bump to 1.3.x
          Hide
          Benoit Chesneau added a comment -

          Some browser clients are bugged and sedn ., so not sure if we should detect text/html to send html page or not. Nothing against though.

          Show
          Benoit Chesneau added a comment - Some browser clients are bugged and sedn . , so not sure if we should detect text/html to send html page or not. Nothing against though.
          Hide
          Filipe Manana added a comment -

          Agreed. However the mochiweb function would not imply adding a new dependency . This is the only reason I opt for mochiweb.

          Show
          Filipe Manana added a comment - Agreed. However the mochiweb function would not imply adding a new dependency . This is the only reason I opt for mochiweb.
          Hide
          Noah Slater added a comment -

          We should use the mimeparse library for Erlang here:

          http://code.google.com/p/mimeparse/

          Then we can handle it properly.

          Show
          Noah Slater added a comment - We should use the mimeparse library for Erlang here: http://code.google.com/p/mimeparse/ Then we can handle it properly.
          Hide
          Filipe Manana added a comment -

          Yeah, but doesn't make sense that we get an html page when the sent Accept header doesn't list application/json.

          Either way, if a user agent says something like "Accept: application/json;q=0.5, etc..." the code will not give the expected response. And specifying a Q values list is often common.

          Show
          Filipe Manana added a comment - Yeah, but doesn't make sense that we get an html page when the sent Accept header doesn't list application/json. Either way, if a user agent says something like "Accept: application/json;q=0.5, etc..." the code will not give the expected response. And specifying a Q values list is often common.
          Hide
          Noah Slater added a comment -

          I think that's fine. It's a pretty weird user agent that doesn't know how to handle text/html. The Accepts header is only a guide, there's no requirement to stick to it.

          Show
          Noah Slater added a comment - I think that's fine. It's a pretty weird user agent that doesn't know how to handle text/html. The Accepts header is only a guide, there's no requirement to stick to it.
          Hide
          Filipe Manana added a comment -

          Hi Benoit,

          Shouldn't the web page be served only if the client accepts text/html? The patch seems to send the page when the client doesn't explicitely list "application/json" as acceptable.

          Also, there's something missing when parsing the Accept header.
          You grab its value and then split it based on commas. But the Accept header can be a Q values list.

          If you have "Accept: application/json; q = 0.5, *; q = 0.3", your code will serve the html page anyway, ignoring the q = 0.5.

          Look at http://github.com/mochi/mochiweb/blob/master/src/mochiweb_util.erl#L416 for parsing a Q values list.

          Show
          Filipe Manana added a comment - Hi Benoit, Shouldn't the web page be served only if the client accepts text/html? The patch seems to send the page when the client doesn't explicitely list "application/json" as acceptable. Also, there's something missing when parsing the Accept header. You grab its value and then split it based on commas. But the Accept header can be a Q values list. If you have "Accept: application/json; q = 0.5, *; q = 0.3", your code will serve the html page anyway, ignoring the q = 0.5. Look at http://github.com/mochi/mochiweb/blob/master/src/mochiweb_util.erl#L416 for parsing a Q values list.
          Hide
          Benoit Chesneau added a comment -

          forgot a fix.

          Show
          Benoit Chesneau added a comment - forgot a fix.
          Hide
          Benoit Chesneau added a comment -

          oups forgot a fix

          Show
          Benoit Chesneau added a comment - oups forgot a fix
          Hide
          Benoit Chesneau added a comment -

          updated screenshot

          Show
          Benoit Chesneau added a comment - updated screenshot
          Hide
          Benoit Chesneau added a comment -

          patch against latest trunk. I also added some useful links on the welcome page + the copyright.

          Show
          Benoit Chesneau added a comment - patch against latest trunk. I also added some useful links on the welcome page + the copyright.
          Hide
          Benoit Chesneau added a comment -

          bump. Any reason we couldnot have in couchdb upstream ?

          Show
          Benoit Chesneau added a comment - bump. Any reason we couldnot have in couchdb upstream ?
          Hide
          Adam Kocoloski added a comment -

          0.10.0 is out the door, adjusting FixFor on all remaining unresolved issues to 0.11 by default

          Show
          Adam Kocoloski added a comment - 0.10.0 is out the door, adjusting FixFor on all remaining unresolved issues to 0.11 by default
          Hide
          Benoit Chesneau added a comment -

          mmm better patch. I mixed two changes in last one. sorry.

          Show
          Benoit Chesneau added a comment - mmm better patch. I mixed two changes in last one. sorry.
          Hide
          Benoit Chesneau added a comment -

          New version of the patch. It put back the old behaviour (json on frontpage) as default while keeping new feature.

          So config could be :

          / =

          {couch_httpd_misc_handlers, handle_welcome_req, <<"Welcome">>}

          , the default

          or

          / = {couch_httpd_misc_handlers, handle_welcome_req, {<<"Welcome">>, "/Users/benoitc/work/couchdb/share/www"}} , display an html page when Accept header isn't "application/json"

          or

          / = {couch_httpd_misc_handlers, handle_welcome_req, {<<"Welcome">>,

          {redirect "/somepath"}

          }} , to redirect to /somepath when Accept header isn't "application/json"

          Show
          Benoit Chesneau added a comment - New version of the patch. It put back the old behaviour (json on frontpage) as default while keeping new feature. So config could be : / = {couch_httpd_misc_handlers, handle_welcome_req, <<"Welcome">>} , the default or / = {couch_httpd_misc_handlers, handle_welcome_req, {<<"Welcome">>, "/Users/benoitc/work/couchdb/share/www"}} , display an html page when Accept header isn't "application/json" or / = {couch_httpd_misc_handlers, handle_welcome_req, {<<"Welcome">>, {redirect "/somepath"} }} , to redirect to /somepath when Accept header isn't "application/json"
          Hide
          Benoit Chesneau added a comment -

          screenshot of default html welcome page

          Show
          Benoit Chesneau added a comment - screenshot of default html welcome page
          Hide
          Benoit Chesneau added a comment -

          the patch

          Show
          Benoit Chesneau added a comment - the patch

            People

            • Assignee:
              Benoit Chesneau
              Reporter:
              Benoit Chesneau
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Development