Add safe check for  XD0007 in px:mediatype-detect

When the same document appears more than once in the in-memory set,
`px:mediatype-detect` failed with XD0007 (sequence of doc not allowed
on a port).
This change adds a safe check for this case.