forked from geoserver/geoserver
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEOS-9816] Download links from the result of an asynch process will …
…not honor the proxy base URL, if it uses HTTP header variables
- Loading branch information
Showing
5 changed files
with
162 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/src/main/java/org/geoserver/ows/HTTPHeadersCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* (c) 2020 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.ows; | ||
|
||
import java.util.Enumeration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.geoserver.ows.util.CaseInsensitiveMap; | ||
|
||
/** | ||
* Collects headers on behalf of {@link ProxifyingURLMangler}, so that they can be used also for | ||
* asynchronoous executions happening outside of request threads. Given the specific usage, only the | ||
* first value of headers is collected. | ||
*/ | ||
public class HTTPHeadersCollector extends AbstractDispatcherCallback { | ||
|
||
public static final ThreadLocal<Map<String, String>> HEADERS = new ThreadLocal<>(); | ||
|
||
@Override | ||
public Request init(Request request) { | ||
HttpServletRequest hr = request.getHttpRequest(); | ||
Enumeration<String> names = hr.getHeaderNames(); | ||
Map<String, String> headers = new CaseInsensitiveMap(new HashMap<>()); | ||
while (names.hasMoreElements()) { | ||
String header = names.nextElement(); | ||
String value = hr.getHeader(header); | ||
headers.put(header, value); | ||
} | ||
HEADERS.set(headers); | ||
|
||
return request; | ||
} | ||
|
||
@Override | ||
public void finished(Request request) { | ||
HEADERS.remove(); | ||
} | ||
|
||
/** | ||
* Returns the value for the specified header, if the {@link #HEADERS} thread local is loaded, | ||
* and contains one, null otherwise. | ||
*/ | ||
public static String getHeader(String header) { | ||
Map<String, String> headers = HEADERS.get(); | ||
if (headers == null) return null; | ||
return headers.get(header); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters