Commit 8af5a319 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[UWS] Fix the parsing of the HTTP header `Accept`.

In case a MIME-type parameter was not `q` set to a floating point value
(e.g. correct is `q=0.8` ; incorrect is `q=abc`), the library was throwing an
ugly NumberFormatException. This exception is now caught (and ignored) if it
occurs.

The same exception was also thrown for any other parameter whose value is not a
floating point. Since only the quality flag (i.e. `q`) is used in UWS-Lib,
parameters are now only parsed if it is `q` ; all others are now ignored.
parent 9a83b201
Loading
Loading
Loading
Loading
+28 −22
Original line number Original line Diff line number Diff line
@@ -16,7 +16,7 @@ package uws;
 * You should have received a copy of the GNU Lesser General Public License
 * You should have received a copy of the GNU Lesser General Public License
 * along with UWSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 * along with UWSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2019 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 *                       Astronomisches Rechen Institut (ARI)
 */
 */


@@ -34,7 +34,7 @@ import java.util.Set;
 * It takes into account the order of the different MIME types and their respective quality.
 * It takes into account the order of the different MIME types and their respective quality.
 *
 *
 * @author Brice Gassmann (CDS) & modified by Gr&eacute;gory Mantelet (CDS)
 * @author Brice Gassmann (CDS) & modified by Gr&eacute;gory Mantelet (CDS)
 * @version 4.2 (09/2017)
 * @version 4.4 (04/2019)
 */
 */
public class AcceptHeader {
public class AcceptHeader {


@@ -58,8 +58,14 @@ public class AcceptHeader {
			Float quality = new Float(1);
			Float quality = new Float(1);
			String[] split = mimeType.split(";");
			String[] split = mimeType.split(";");
			if (split.length > 1){
			if (split.length > 1){
				if (split[1].matches("q=[0-9.]+")){
					try{
						String[] qualitySplit = split[1].split("=");
						String[] qualitySplit = split[1].split("=");
						quality = Float.parseFloat(qualitySplit[1]);
						quality = Float.parseFloat(qualitySplit[1]);
					}catch(NumberFormatException nfe){
						// just ignore this incorrect quality value!
					}
				}
			}
			}
			mMimeTypes.put(split[0], quality);
			mMimeTypes.put(split[0], quality);
		}
		}