Uploaded image for project: 'Jackrabbit Oak'
  1. Jackrabbit Oak
  2. OAK-8135

HTTP service may not select correct media type if multiple are specified in Accept header field

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.12.0, 1.10.3, 1.6.18, 1.8.14
    • Component/s: oak-http
    • Labels:
      None

      Description

      Steps to reproduce:
      With HTTPie

      > http -j -b -a admin:admin localhost:8080

      or with cUrl

      > curl -u admin:admin http://localhost:8080 --header "Accept: application/json, */*"

      In both of the above cases http service selects the first available representation (aka HTML) based on "*/*" instead of more specific JSON.

      I think one possible fix is to by default assign higher weight to more specific mime types when Accept header is parsed in org.apache.jackrabbit.oak.http.MediaRange.parse

      For example replacing return statement in above method with the following fixed this bug in my testing:

      double defaultQ = 3.0;
      if("*/*".equals(type.getType())) {
          defaultQ = 1.0;
      } else if("*".equals(type.getSubtype())) {
          defaultQ = 2.0;
      }
              
      return new MediaRange(type, defaultQ);
      

        Attachments

        1. MediaRange.patch
          0.8 kB
          Henry Saginor
        2. OAK-8135.diff
          5 kB
          Julian Reschke

          Activity

            People

            • Assignee:
              reschke Julian Reschke
              Reporter:
              hsaginor@gmail.com Henry Saginor
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: