[fixed] Invalid Range header Exception logged by ResourceAccessModule is bogus (1 Viewer)

McGoober

Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Low Priority, aesthetic enhancement only.
    Found when attempting to allow other programs access to the resources provided by ResourceAccessModule.

    I expose valid resource URL's to devices for DLNA/UPNP access. However the "Range" http header isn't always provided by the client.

    System/MediaPortal.Core/Services/MediaManagement/ResourceAccessModule.cs in method Process().

    The following code is always executed on every access, however if the "Range" header isn't provided, ParseRange will write a benign exception to the log.

    Code:
             string byteRangesSpecifier = request.Headers["Range"];
             IList<Range> ranges = ParseRanges(byteRangesSpecifier, resourceStream.Length);

    Although this doesn't affect execution it's annoying to see the exception in the log.
    My code change does the following...

    Code:
              string byteRangesSpecifier = request.Headers["Range"];
              IList<Range> ranges = null;
              if (byteRangesSpecifier != null)
              {
                  ranges = ParseRanges(byteRangesSpecifier, resourceStream.Length);
              }
              bool onlyHeaders = request.Method == "Headers" || response.Status == HttpStatusCode.NotModified;
              if (ranges != null && ranges.Count == 1)
                // We only support one range
                SendRange(response, resourceStream, ranges[0], onlyHeaders);
              else
                SendWholeFile(response, resourceStream, onlyHeaders);

    Only ParseRanges when a range exists and also since ranges is initialised to null, extra check in if for null.
     

    morpheus_xx

    Retired Team Member
  • Team MediaPortal
  • March 24, 2007
    12,070
    7,459
    Home Country
    Germany Germany
    AW: Invalid Range header Exception logged by ResourceAccessModule is bogus

    If I understand you correctly, the issue here is that there is a "false exception" logged?

    In this case we should simply remove the debug message in ResourceAccessModule.cs line 228:
    Code:
     catch (Exception e)
          {
            ServiceRegistration.Get<ILogger>().Debug("ResourceAccessModule: Received illegal Range header", e);
            // As specified in RFC2616, section 14.35.1, ignore invalid range header
          }
    And also in a higher loglevel this would not be seen. I can live with both...
     

    McGoober

    Retired Team Member
  • Premium Supporter
  • August 13, 2006
    122
    105
    Cambridge, UK
    Home Country
    United Kingdom United Kingdom
    Thanks morpheus_xx,

    The exception is correctly logged if the code does indeed encounter a badly formed range header. I would expect to see something in the debug log, but only if one is provided.
     

    Users who are viewing this thread

    Top Bottom