Skip to content

Commit

Permalink
Don't cache requests with Accept: text/event-stream by default.
Browse files Browse the repository at this point in the history
The eventstream requests is typically not directly invoked by the browser.
And even more unfortunately the Browser-Api doesn't allow the set additional headers as `XMLHttpRequest`..
  • Loading branch information
joshiste authored and fhanik committed Jan 17, 2020
1 parent 29182ab commit cc956a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ private RequestMatcher createDefaultSavedRequestMatcher(H http) {
matchers.add(notMatchingMediaType(http, MediaType.APPLICATION_JSON));
matchers.add(notXRequestedWith);
matchers.add(notMatchingMediaType(http, MediaType.MULTIPART_FORM_DATA));
matchers.add(notMatchingMediaType(http, MediaType.TEXT_EVENT_STREAM));

return new AndRequestMatcher(matchers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ public void getWhenBookmarkedRequestIsXRequestedWithThenPostAuthenticationRedire

// This is desirable since XHR requests are typically not invoked directly from the browser and we don't want the browser to replay them
}
@Test
public void getWhenBookmarkedRequestIsTextEventStreamThenPostAuthenticationRedirectsToRoot() throws Exception {
this.spring.register(RequestCacheDefaultsConfig.class, DefaultSecurityConfig.class).autowire();

MockHttpSession session = (MockHttpSession)
this.mvc.perform(get("/messages")
.header(HttpHeaders.ACCEPT, MediaType.TEXT_EVENT_STREAM))
.andExpect(redirectedUrl("http://localhost/login"))
.andReturn().getRequest().getSession();

this.mvc.perform(formLogin(session))
.andExpect(redirectedUrl("/")); // ignores text/event-stream

// This is desirable since event-stream requests are typically not invoked directly from the browser and we don't want the browser to replay them
}

@Test
public void getWhenBookmarkedRequestIsAllMediaTypeThenPostAuthenticationRemembers() throws Exception {
Expand Down

0 comments on commit cc956a6

Please sign in to comment.