GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — CORS: Correctly handle origin · netty/netty@afca14b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http/src
    • main/java/io/netty/handler/codec/http/cors
      • CorsHandler.java
    • test/java/io/netty/handler/codec/http/cors
      • CorsHandlerTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private CorsConfig getForOrigin(String requestOrigin) {
155155
if (corsConfig.origins().contains(requestOrigin)) {
156156
return corsConfig;
157157
}
158-
if (corsConfig.isNullOriginAllowed() || NULL_ORIGIN.equals(requestOrigin)) {
158+
if (corsConfig.isNullOriginAllowed() && NULL_ORIGIN.equals(requestOrigin)) {
159159
return corsConfig;
160160
}
161161
}
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java‎

Copy file name to clipboardExpand all lines: codec-http/src/test/java/io/netty/handler/codec/http/cors/CorsHandlerTest.java
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,24 @@ public void preflightEmptyLastDiscardedThenNewRequestForwarded() {
665665
assertFalse(ch.finish());
666666
}
667667

668+
@Test
669+
public void shortCircuitWithNullOriginNotAllowedShouldBeForbidden() {
670+
final CorsConfig config = forOrigin("http://localhost:8080").shortCircuit().build();
671+
final HttpResponse response = simpleRequest(config, "null");
672+
assertEquals(FORBIDDEN, response.status());
673+
assertEquals("0", response.headers().get(CONTENT_LENGTH));
674+
assertTrue(ReferenceCountUtil.release(response));
675+
}
676+
677+
@Test
678+
public void shortCircuitWithNullOriginAllowedShouldSucceed() {
679+
final CorsConfig config = forOrigin("http://localhost:8080").allowNullOrigin().shortCircuit().build();
680+
final HttpResponse response = simpleRequest(config, "null");
681+
assertEquals(OK, response.status());
682+
assertEquals("null", response.headers().get(ACCESS_CONTROL_ALLOW_ORIGIN));
683+
assertTrue(ReferenceCountUtil.release(response));
684+
}
685+
g
668686
private static HttpResponse simpleRequest(final CorsConfig config, final String origin) {
669687
return simpleRequest(config, origin, null);
670688
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.