Skip to content

Documentation misleading: req.accepts() does not return a boolean #957

Closed

Description

@kmudrick

The implementation of req.accepts(type) actually returns a type string, not a boolean like the docs seem to indicate. I'm wondering if the behavior changed at some point and the documentation was just never updated to reflect that?

FWIW, the express docs seem better from this perspective: http://expressjs.com/api.html#req.accepts

Activity

  1. DonutEspresso commented on Dec 3, 2015

    @DonutEspresso
    Member

    Looks like the documentation is indeed out of date. We'll fix that up as soon as we can. Thanks!

  2. Khez commented on Feb 3, 2016

    @Khez

    I'm uncertain if the documentation or implementation is broke...
    I did some tests and things seem worrying.

    Accept: text/html

    type request.is request.accepts
    html false text/html
    json true undefined

    Accept: text/*; application/json

    type request.is request.accepts
    html false text/html
    json true undefined

    Accept: application/json; text/*

    type request.is request.accepts
    html false undefined
    json true application/json

    Accept: /

    type request.is request.accepts
    html false text/html
    text/html false text/html
    text/plain false text/plain
    json true application/json
    application/json true application/json
    png false image/png
    image/png false image/png

    Can anyone confirm the desired behaviour ?
    I could try to do a pull request after some further investigation...

  3. added a commit that references this issue on Apr 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions