Browse Source

Merge branch 'ileler-master'

pull/407/merge
Spencer Gibb 6 years ago
parent
commit
696206593d
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 4
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Route.java
  2. 14
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/RouteTests.java

4
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/Route.java

@ -114,7 +114,9 @@ public class Route implements Ordered { @@ -114,7 +114,9 @@ public class Route implements Ordered {
public B uri(URI uri) {
this.uri = uri;
if (this.uri.getPort() < 0 && this.uri.getScheme().startsWith("http")) {
String scheme = this.uri.getScheme();
Assert.hasText(scheme, "The parameter [" + this.uri + "] format is incorrect, scheme can not be empty");
if (this.uri.getPort() < 0 && scheme.startsWith("http")) {
// default known http ports
int port = this.uri.getScheme().equals("https") ? 443 : 80;
this.uri = UriComponentsBuilder.fromUri(this.uri)

14
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/route/RouteTests.java

@ -17,12 +17,17 @@ @@ -17,12 +17,17 @@
package org.springframework.cloud.gateway.route;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.assertj.core.api.Assertions.assertThat;
public class RouteTests {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void defeaultHttpPort() {
Route route = Route.async().id("1")
@ -47,7 +52,6 @@ public class RouteTests { @@ -47,7 +52,6 @@ public class RouteTests {
.hasPort(443);
}
@Test
public void fullUri() {
Route route = Route.async().id("1")
@ -59,4 +63,12 @@ public class RouteTests { @@ -59,4 +63,12 @@ public class RouteTests {
.hasScheme("http")
.hasPort(8080);
}
@Test
public void nullScheme() {
exception.expect(IllegalArgumentException.class);
Route.async().id("1")
.predicate(exchange -> true)
.uri("/pathonly");
}
}

Loading…
Cancel
Save