Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Fix HTTP Accept header for list query
Browse files Browse the repository at this point in the history
Given following list function
```
function(head, req) {
  provides('text', function(){
    start({
      'headers': {
        'Content-Type': 'text/plain'
      }
    });
    send('Hello list!');
  });
}
```

It will get HTTP 406 error, because the default
Accept header is set to `application/json`.

See Also: couchapp/couchapp#234
  • Loading branch information
iblislin committed May 12, 2016
1 parent 102e663 commit 9806ac9
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions jquery.couch.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,11 @@
url: this.uri + '_design/' + list[0] +
'/_list/' + list[1] + '/' + view + encodeOptions(options)
},
ajaxOptions, 'An error occurred accessing the list'
ajaxOptions,
'An error occurred accessing the list',
{
headers: {'Accept': '*/*'},
}
);
},

Expand Down Expand Up @@ -1009,25 +1013,36 @@
},
complete: function(req) {
var reqDuration = (new Date()).getTime() - timeStart;
try {
var resp = $.parseJSON(req.responseText);
} catch(e) {
if (options.error) {
options.error(req.status, req, e);
} else {
throw errorMessage + ': ' + e;

if (req.getResponseHeader('Content-Type') === 'application/json') {
try {
var resp = $.parseJSON(req.responseText);
} catch(e) {
if (options.error) {
options.error(req.status, req, e);
} else {
throw errorMessage + ': ' + e;
}
return;
}
return;
}
else {
/**
* i.e. In the case of the response of a list function,
* the content type can be various
*/
var resp = req.responseText;
}

if (options.ajaxStart) {
options.ajaxStart(resp);
}
if (req.status == options.successStatus) {
if (options.beforeSuccess) options.beforeSuccess(req, resp, reqDuration);
if (options.success) options.success(resp, reqDuration);
} else if (options.error) {
options.error(req.status, resp && resp.error ||
errorMessage, resp && resp.reason || "no response",
options.error(req.status, resp && resp.error || errorMessage,
resp && resp.reason || resp || "no response",
reqDuration);
} else {
throw errorMessage + ": " + resp.reason;
Expand Down

0 comments on commit 9806ac9

Please sign in to comment.