001package ca.uhn.fhir.rest.server.servlet; 002 003/* 004 * #%L 005 * HAPI FHIR - Server Framework 006 * %% 007 * Copyright (C) 2014 - 2019 University Health Network 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import java.util.ArrayList; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027 028public class ServletSubRequestDetails extends ServletRequestDetails { 029 030 private Map<String, List<String>> myHeaders = new HashMap<>(); 031 032 /** 033 * Constructor 034 * 035 * @param theRequestDetails The parent request details 036 */ 037 public ServletSubRequestDetails(ServletRequestDetails theRequestDetails) { 038 super(theRequestDetails.getInterceptorBroadcaster()); 039 if (theRequestDetails != null) { 040 Map<String, List<String>> headers = theRequestDetails.getHeaders(); 041 for (Map.Entry<String, List<String>> next : headers.entrySet()) { 042 myHeaders.put(next.getKey().toLowerCase(), next.getValue()); 043 } 044 } 045 } 046 047 public void addHeader(String theName, String theValue) { 048 String lowerCase = theName.toLowerCase(); 049 List<String> list = myHeaders.get(lowerCase); 050 if (list == null) { 051 list = new ArrayList<>(); 052 myHeaders.put(lowerCase, list); 053 } 054 list.add(theValue); 055 } 056 057 @Override 058 public String getHeader(String theName) { 059 List<String> list = myHeaders.get(theName.toLowerCase()); 060 if (list == null || list.isEmpty()) { 061 return null; 062 } 063 return list.get(0); 064 } 065 066 @Override 067 public List<String> getHeaders(String theName) { 068 List<String> list = myHeaders.get(theName.toLowerCase()); 069 if (list == null || list.isEmpty()) { 070 return null; 071 } 072 return list; 073 } 074 075 @Override 076 public boolean isSubRequest() { 077 return true; 078 } 079 080}