Skip to content

Commit

Permalink
Added CORS header; #68
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Aug 22, 2024
1 parent 172945d commit 1b3db8a
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.helger.commons.datetime.PDTWebDateHelper;
import com.helger.commons.error.IError;
import com.helger.commons.http.CHttp;
import com.helger.commons.http.CHttpHeader;
import com.helger.commons.io.resource.ClassPathResource;
import com.helger.commons.mime.CMimeType;
import com.helger.commons.string.StringHelper;
Expand Down Expand Up @@ -140,10 +141,9 @@ public PublicSearchXServletHandler ()
public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope,
@Nonnull final UnifiedResponse aUnifiedResponse) throws Exception
{
final BiConsumer <UnifiedResponse, String> applyError = (ur,
msg) -> ur.setContentAndCharset (msg,
StandardCharsets.UTF_8)
.setMimeType (CMimeType.TEXT_PLAIN);
final BiConsumer <UnifiedResponse, String> applyError = (ur, msg) -> ur.setContentAndCharset (msg,
StandardCharsets.UTF_8)
.setMimeType (CMimeType.TEXT_PLAIN);

if (SearchRateLimit.INSTANCE.rateLimiter () != null)
{
Expand Down Expand Up @@ -325,7 +325,8 @@ public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aReque

// Filter by index/count
final int nEffectiveLastIndex = Math.min (nLastResultIndex, aResultDocs.size () - 1);
final List <PDStoredBusinessEntity> aResultView = nFirstResultIndex >= aResultDocs.size () ? Collections.emptyList ()
final List <PDStoredBusinessEntity> aResultView = nFirstResultIndex >= aResultDocs.size () ? Collections
.emptyList ()
: aResultDocs.subList (nFirstResultIndex,
nEffectiveLastIndex +
1);
Expand All @@ -334,6 +335,11 @@ public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aReque
final ICommonsMap <IParticipantIdentifier, ICommonsList <PDStoredBusinessEntity>> aGroupedDocs = PDStorageManager.getGroupedByParticipantID (aResultView);
final ZonedDateTime aNow = PDTFactory.getCurrentZonedDateTimeUTC ();

// See Directory issue #68
aUnifiedResponse.addCustomResponseHeader (CHttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
aUnifiedResponse.disableCaching ();
aUnifiedResponse.setMimeType (eOutputFormat.getMimeType ());

// build result
switch (eOutputFormat)
{
Expand Down Expand Up @@ -368,8 +374,7 @@ public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aReque
for (final IError aError : aErrHdl.getErrorList ())
LOGGER.error (aError.getAsString (AppCommonUI.DEFAULT_LOCALE));
}
aUnifiedResponse.disableCaching ();
aUnifiedResponse.setMimeType (eOutputFormat.getMimeType ());

aUnifiedResponse.setContent (MicroWriter.getNodeAsBytes (aDoc, aXWS));
break;
}
Expand All @@ -394,8 +399,6 @@ public void handleRequest (@Nonnull final IRequestWebScopeWithoutResponse aReque
}
aDoc.addJson ("matches", aMatches);

aUnifiedResponse.disableCaching ();
aUnifiedResponse.setMimeType (eOutputFormat.getMimeType ());
aUnifiedResponse.setContentAndCharset (aDoc.getAsJsonString (aJWS), StandardCharsets.UTF_8);
break;
default:
Expand Down

0 comments on commit 1b3db8a

Please sign in to comment.