Skip to content

Commit

Permalink
Fixes #1321
Browse files Browse the repository at this point in the history
  • Loading branch information
jfarcand committed Oct 3, 2013
1 parent dedd5c2 commit 9e93884
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,8 @@ protected Map<String, String> configureQueryStringAsRequest(AtmosphereRequest re
request.contentType(s.length > 1 ? s[1] : "");
}
}
if (!s[0].toLowerCase().startsWith("x-atmo")
if (!s[0].isEmpty()
&& !s[0].toLowerCase().startsWith("x-atmo")
&& !s[0].equalsIgnoreCase("x-cache-date")
&& !s[0].equalsIgnoreCase("Content-Type")
&& !s[0].equalsIgnoreCase("_")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,13 @@ public AtmosphereRequest header(String name, String value) {
/**
* Set the query string.
*
* @param queryString
* @param qs
* @return this
*/
public AtmosphereRequest queryString(String queryString) {
public AtmosphereRequest queryString(String qs) {

if (queryString == null) return this;
if (qs == null) return this;

// Don't override the builder
String qs = queryString;
if (qs.isEmpty()) {
qs = b.queryString;
}
if (!qs.isEmpty()) {
QueryStringDecoder decoder = new QueryStringDecoder(getRequestURI() + "?" + qs);
Map<String, List<String>> m = decoder.getParameters();
Expand All @@ -435,8 +430,8 @@ public AtmosphereRequest queryString(String queryString) {
newM.put(q.getKey(), q.getValue().toArray(new String[q.getValue().size()]));
}
b.queryStrings(newM);
b.queryString = qs;
}
b.queryString = qs;
return this;
}

Expand Down
32 changes: 32 additions & 0 deletions modules/cpr/src/test/java/org/atmosphere/cpr/QueryStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,36 @@ public void destroy() {
assertNotNull(q.get());
assertEquals(q.get(), "b=d&c=f&a=b");
}

@Test
public void issue1321() throws IOException, ServletException, ExecutionException, InterruptedException {
final AtomicReference<AtmosphereResource> r = new AtomicReference<AtmosphereResource>();
final AtomicReference<String> q = new AtomicReference<String>();

framework.addAtmosphereHandler("/*", new AtmosphereHandler() {

@Override
public void onRequest(AtmosphereResource resource) throws IOException {
r.set(resource);
q.set(resource.getRequest().getQueryString());
resource.getBroadcaster().addAtmosphereResource(resource);
}

@Override
public void onStateChange(AtmosphereResourceEvent event) throws IOException {
}

@Override
public void destroy() {
}
});
String s = "&X-Atmosphere-tracking-id=c8834462-c46e-4dad-a22f-b86aabe3f883&X-Atmosphere-Framework=2.0.3-javascript&X-Atmosphere-Transport=long-polling&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&X-atmo-protocol=true&_=1380799455333";

AtmosphereRequest request = new AtmosphereRequest.Builder().queryString(s).pathInfo("/a").build();
framework.doCometSupport(request, AtmosphereResponse.newInstance());

r.get().getBroadcaster().broadcast("yo").get();
assertNotNull(q.get());
assertEquals(q.get(), "");
}
}

0 comments on commit 9e93884

Please sign in to comment.