private void adjustQualityFromAccept ( Map < String , Float > pFormatQuality , HttpServletRequest pRequest ) { // Multiply all q factors with qs factors // No q=.. should be interpreted as q=1.0 // Apache does some extras; if both explicit types and wildcards // (without qaulity factor) are present, */* is interpreted as // */*;q=0.01 and image/* is interpreted as image/*;q=0.02 // See: http://httpd.apache.org/docs-2.0/content-negotiation.html String accept = getAcceptedFormats ( pRequest ) ; //System.out.println("Accept: " + accept); float anyImageFactor = getQualityFactor ( accept , MIME_TYPE_IMAGE_ANY ) ; anyImageFactor = ( anyImageFactor == 1 ) ? 0.02f : anyImageFactor ; float anyFactor = getQualityFactor ( accept , MIME_TYPE_ANY ) ; anyFactor = ( anyFactor == 1 ) ? 0.01f : anyFactor ; for ( String format : pFormatQuality . keySet ( ) ) { //System.out.println("Trying format: " + format); String formatMIME = MIME_TYPE_IMAGE_PREFIX + format ; float qFactor = getQualityFactor ( accept , formatMIME ) ; qFactor = ( qFactor == 0f ) ? Math . max ( anyFactor , anyImageFactor ) : qFactor ; adjustQuality ( pFormatQuality , format , qFactor ) ; } }
Adjust quality from HTTP Accept header