@@ -112,9 +112,10 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
112
112
resp .sendError (HttpServletResponse .SC_BAD_REQUEST );
113
113
return ;
114
114
}
115
- String type = req .getParameter (SimplePipeRequest .FORM_PIPE_TYPE );
116
- if (type == null ) {
117
- type = SimplePipeRequest .PIPE_TYPE_CONTINUUM ;
115
+ char type = SimplePipeRequest .PIPE_TYPE_CONTINUUM ;
116
+ String typeStr = req .getParameter (SimplePipeRequest .FORM_PIPE_TYPE );
117
+ if (typeStr != null && typeStr .length () > 0 ) {
118
+ type = typeStr .charAt (0 );
118
119
}
119
120
String domain = req .getParameter (SimplePipeRequest .FORM_PIPE_DOMAIN );
120
121
doPipe (resp , key , type , domain );
@@ -139,14 +140,14 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
139
140
* type = notify
140
141
* Notify that client (browser) still keeps the pipe connection.
141
142
*/
142
- protected void doPipe (final HttpServletResponse resp , String key , String type , String domain )
143
+ protected void doPipe (final HttpServletResponse resp , String key , char type , String domain )
143
144
throws IOException {
144
145
PrintWriter writer = null ;
145
146
resp .setHeader ("Pragma" , "no-cache" );
146
147
resp .setHeader ("Cache-Control" , "no-cache" );
147
148
resp .setDateHeader ("Expires" , 0 );
148
149
149
- if (SimplePipeRequest .PIPE_TYPE_NOTIFY . equals ( type ) ) {
150
+ if (SimplePipeRequest .PIPE_TYPE_NOTIFY == type ) {
150
151
/*
151
152
* Client send in "notify" request to execute #notifyPipeStatus, see below comments
152
153
*/
@@ -160,7 +161,7 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
160
161
writer .write ("\" );" );
161
162
return ;
162
163
}
163
- if (SimplePipeRequest .PIPE_TYPE_SUBDOMAIN_QUERY . equals ( type ) ) { // subdomain query
164
+ if (SimplePipeRequest .PIPE_TYPE_SUBDOMAIN_QUERY == type ) { // subdomain query
164
165
resp .setContentType ("text/html; charset=utf-8" );
165
166
writer = resp .getWriter ();
166
167
StringBuffer buffer = new StringBuffer ();
@@ -189,11 +190,11 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
189
190
writer .write (buffer .toString ());
190
191
return ;
191
192
}
192
- boolean isContinuum = SimplePipeRequest .PIPE_TYPE_CONTINUUM . equals ( type ) ;
193
+ boolean isContinuum = SimplePipeRequest .PIPE_TYPE_CONTINUUM == type ;
193
194
if (isContinuum ) {
194
195
resp .setHeader ("Transfer-Encoding" , "chunked" );
195
196
}
196
- boolean isScripting = SimplePipeRequest .PIPE_TYPE_SCRIPT . equals ( type ) ;
197
+ boolean isScripting = SimplePipeRequest .PIPE_TYPE_SCRIPT == type ;
197
198
if (isScripting ) { // iframe
198
199
resp .setContentType ("text/html; charset=utf-8" );
199
200
writer = resp .getWriter ();
@@ -211,8 +212,7 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
211
212
writer .write (buffer .toString ());
212
213
writer .flush ();
213
214
} else {
214
- if (SimplePipeRequest .PIPE_TYPE_QUERY .equals (type )
215
- || isContinuum ) {
215
+ if (SimplePipeRequest .PIPE_TYPE_QUERY == type || isContinuum ) {
216
216
resp .setContentType ("text/plain; charset=utf-8" );
217
217
} else {
218
218
resp .setContentType ("text/javascript; charset=utf-8" );
@@ -345,28 +345,27 @@ protected void doPipe(final HttpServletResponse resp, String key, String type, S
345
345
}
346
346
}
347
347
348
- protected static String output (String type , String key ,
349
- String str ) {
348
+ protected static String output (char type , String key , String str ) {
350
349
StringBuffer buffer = new StringBuffer ();
351
- if (SimplePipeRequest .PIPE_TYPE_SCRIPT . equals ( type ) ) {
350
+ if (SimplePipeRequest .PIPE_TYPE_SCRIPT == type ) {
352
351
// iframe, so $ is a safe method identifier
353
352
buffer .append ("<script type=\" text/javascript\" >$ (\" " );
354
- } else if (SimplePipeRequest .PIPE_TYPE_XSS . equals ( type ) ) {
353
+ } else if (SimplePipeRequest .PIPE_TYPE_XSS == type ) {
355
354
buffer .append ("$p1p3p$ (\" " ); // $p1p3p$
356
355
}
357
356
buffer .append (key );
358
- if (SimplePipeRequest .PIPE_TYPE_SCRIPT . equals ( type )
359
- || SimplePipeRequest .PIPE_TYPE_XSS . equals ( type ) ) {
357
+ if (SimplePipeRequest .PIPE_TYPE_SCRIPT == type
358
+ || SimplePipeRequest .PIPE_TYPE_XSS == type ) {
360
359
str = str .replaceAll ("\\ \\ " , "\\ \\ \\ \\ " ).replaceAll ("\r " , "\\ \\ r" )
361
360
.replaceAll ("\n " , "\\ \\ n" ).replaceAll ("\" " , "\\ \\ \" " );
362
- if (SimplePipeRequest .PIPE_TYPE_SCRIPT . equals ( type ) ) {
361
+ if (SimplePipeRequest .PIPE_TYPE_SCRIPT == type ) {
363
362
str = str .replaceAll ("<\\ /script>" , "<\\ /scr\" + \" ipt>" );
364
363
}
365
364
}
366
365
buffer .append (str );
367
- if (SimplePipeRequest .PIPE_TYPE_SCRIPT . equals ( type ) ) { // iframe
366
+ if (SimplePipeRequest .PIPE_TYPE_SCRIPT == type ) { // iframe
368
367
buffer .append ("\" );</script>\r \n " );
369
- } else if (SimplePipeRequest .PIPE_TYPE_XSS . equals ( type ) ) {
368
+ } else if (SimplePipeRequest .PIPE_TYPE_XSS == type ) {
370
369
buffer .append ("\" );\r \n " );
371
370
}
372
371
return buffer .toString ();
0 commit comments