Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ package uws;
* You should have received a copy of the GNU Lesser General Public License
* 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)
*/
......@@ -34,7 +34,7 @@ import java.util.Set;
* 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)
* @version 4.2 (09/2017)
* @version 4.4 (04/2019)
*/
public class AcceptHeader {
......@@ -58,8 +58,14 @@ public class AcceptHeader {
Float quality = new Float(1);
String[] split = mimeType.split(";");
if (split.length > 1){
if (split[1].matches("q=[0-9.]+")){
try{
String[] qualitySplit = split[1].split("=");
quality = Float.parseFloat(qualitySplit[1]);
}catch(NumberFormatException nfe){
// just ignore this incorrect quality value!
}
}
}
mMimeTypes.put(split[0], quality);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment