Skip to content

Commit

Permalink
Merge pull request #87 from TAMULib/redirect-location-with-spaces
Browse files Browse the repository at this point in the history
decode encoded spaces in location header during redirect
  • Loading branch information
wwelling committed Jul 4, 2020
2 parents a7f8472 + 84a3d53 commit 501f466
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>edu.tamu</groupId>
<artifactId>ir-iiif-service</artifactId>
<version>0.5.0</version>
<version>0.5.1</version>
<packaging>war</packaging>

<name>IR IIIF Service</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package edu.tamu.iiif.service;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.util.Optional;

import org.apache.commons.validator.routines.UrlValidator;
Expand All @@ -24,13 +26,13 @@ public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContex
if (locationHeader.isPresent()) {
try {
URI origUri = new URI(request.getRequestLine().getUri());
String location = locationHeader.get().getValue().split("\\?")[0];
String location = URLDecoder.decode(locationHeader.get().getValue().split("\\?")[0], "UTF-8");
if (urlValidator.isValid(location)) {
return new URI(location);
} else {
return new URI(origUri.getScheme(), null, origUri.getHost(), origUri.getPort(), location, null, null);
}
} catch (URISyntaxException e) {
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new ProtocolException("Unable to reconstruct original URI!");
}
} else {
Expand Down

0 comments on commit 501f466

Please sign in to comment.