From 8fdca606cf92e06934da840c04045b2072e32fdf Mon Sep 17 00:00:00 2001 From: jfarcand Date: Thu, 5 Dec 2013 11:08:17 -0500 Subject: [PATCH] Fixes #1392 --- .../OldBrowserPaddingInterceptor.java | 29 +++++++++++++++++++ .../PaddingAtmosphereInterceptor.java | 21 ++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 modules/cpr/src/main/java/org/atmosphere/interceptor/OldBrowserPaddingInterceptor.java diff --git a/modules/cpr/src/main/java/org/atmosphere/interceptor/OldBrowserPaddingInterceptor.java b/modules/cpr/src/main/java/org/atmosphere/interceptor/OldBrowserPaddingInterceptor.java new file mode 100644 index 0000000000..06c992297c --- /dev/null +++ b/modules/cpr/src/main/java/org/atmosphere/interceptor/OldBrowserPaddingInterceptor.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013 Jeanfrancois Arcand + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.atmosphere.interceptor; + +/** + * Old 8k Padding interceptor for Browser that needs whitespace when streaming is used. + * + * @author Jeanfrancois Arcand + */ +public class OldBrowserPaddingInterceptor extends PaddingAtmosphereInterceptor { + + public OldBrowserPaddingInterceptor() { + super(8192); + } + +} diff --git a/modules/cpr/src/main/java/org/atmosphere/interceptor/PaddingAtmosphereInterceptor.java b/modules/cpr/src/main/java/org/atmosphere/interceptor/PaddingAtmosphereInterceptor.java index 3a6372c8f0..0c6444438c 100644 --- a/modules/cpr/src/main/java/org/atmosphere/interceptor/PaddingAtmosphereInterceptor.java +++ b/modules/cpr/src/main/java/org/atmosphere/interceptor/PaddingAtmosphereInterceptor.java @@ -44,17 +44,26 @@ public class PaddingAtmosphereInterceptor extends AtmosphereInterceptorAdapter { private static final Logger logger = LoggerFactory.getLogger(PaddingAtmosphereInterceptor.class); - private static final byte[] padding; - private static final String paddingText; + private final byte[] padding; + private final String paddingText; - static { + public PaddingAtmosphereInterceptor(){ + paddingText = confPadding(1024); + padding = paddingText.getBytes(); + } + + public PaddingAtmosphereInterceptor(int size){ + paddingText = confPadding(size); + padding = paddingText.getBytes(); + } + + protected final static String confPadding(int size) { StringBuilder whitespace = new StringBuilder(); - for (int i = 0; i < 8192; i++) { + for (int i = 0; i < size; i++) { whitespace.append(" "); } whitespace.append("\n"); - paddingText = whitespace.toString(); - padding = paddingText.getBytes(); + return whitespace.toString(); } private void writePadding(AtmosphereResponse response) {