oxsean commented on code in PR #14073:
URL: https://github.com/apache/dubbo/pull/14073#discussion_r1576518108
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/RestConstants.java:
##########
@@ -48,6 +48,24 @@ public final class RestConstants {
public static final String PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE =
"org.springframework.web.servlet.HandlerMapping.producibleMediaTypes";
+ /* Cors Config */
+ public static final String VARY = "Vary";
+ public static final String ORIGIN = "Origin";
+ public static final String ACCESS_CONTROL_REQUEST_HEADERS =
"Access-Control-Request-Headers";
+ public static final String ACCESS_CONTROL_REQUEST_METHOD =
"Access-Control-Request-Method";
+ public static final String ACCESS_CONTROL_ALLOW_CREDENTIALS =
"Access-Control-Allow-Credentials";
+ public static final String ACCESS_CONTROL_EXPOSE_HEADERS =
"Access-Control-Expose-Headers";
+ public static final String ACCESS_CONTROL_MAX_AGE =
"Access-Control-Max-Age";
+ public static final String ACCESS_CONTROL_ALLOW_HEADERS =
"Access-Control-Allow-Headers";
+ public static final String ACCESS_CONTROL_ALLOW_METHODS =
"Access-Control-Allow-Methods";
+ public static final String ACCESS_CONTROL_ALLOW_ORIGIN =
"Access-Control-Allow-Origin";
+ public static final String HTTP = "http";
+ public static final String HTTPS = "https";
+ public static final String WS = "ws";
Review Comment:
Unnecessary
##########
dubbo-common/src/main/java/org/apache/dubbo/config/CorsConfig.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.config;
+
+import java.io.Serializable;
+
+public class CorsConfig implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String allowedOrigins;
+
+ private String allowedMethods;
+
+ private String allowedHeaders;
+
+ private String exposedHeaders;
+
+ private Boolean allowCredentials;
+
+ private Boolean allowPrivateNetWork;
Review Comment:
For now, we don't need to support this.
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java:
##########
@@ -190,6 +215,9 @@ public HandlerMeta lookup(HttpRequest request) {
Candidate winner = candidates.get(0);
RequestMapping mapping = winner.mapping;
+
+ processCors(mapping, request, response);
Review Comment:
Implementing an extension for
org.apache.dubbo.rpc.protocol.tri.rest.filter.RestHeaderFilterAdapter and move
logic into it would likely be more appropriate(I didn't think about it before).
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/cors/CorsUtil.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.protocol.tri.rest.cors;
+
+import org.apache.dubbo.common.config.Configuration;
+import org.apache.dubbo.common.lang.Nullable;
+import org.apache.dubbo.rpc.protocol.tri.rest.RestConstants;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class CorsUtil {
Review Comment:
CorsUtils
##########
dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java:
##########
@@ -52,23 +62,26 @@ public final class DefaultRequestMappingRegistry implements
RequestMappingRegist
private final RadixTree<Registration> tree = new RadixTree<>();
private final ReadWriteLock lock = new ReentrantReadWriteLock();
+ private CorsMeta globalCorsMeta;
+ private final CorsProcessor corsProcessor;
public DefaultRequestMappingRegistry(FrameworkModel frameworkModel) {
resolvers =
frameworkModel.getActivateExtensions(RequestMappingResolver.class);
+ corsProcessor =
frameworkModel.getBeanFactory().getOrRegisterBean(CorsProcessor.class);
}
@Override
public void register(Invoker<?> invoker) {
Object service = invoker.getUrl().getServiceModel().getProxyObject();
new MethodWalker().walk(service.getClass(), (classes, consumer) -> {
- for (int i = 0, size = resolvers.size(); i < size; i++) {
- RequestMappingResolver resolver = resolvers.get(i);
+ for (RequestMappingResolver resolver : resolvers) {
RestToolKit toolKit = resolver.getRestToolKit();
ServiceMeta serviceMeta = new ServiceMeta(classes, service,
invoker.getUrl(), toolKit);
if (!resolver.accept(serviceMeta)) {
continue;
}
RequestMapping classMapping = resolver.resolve(serviceMeta);
+ mergeGlobalCorsMeta(classMapping);
Review Comment:
Move to RequestMappingResolver
##########
dubbo-common/src/main/java/org/apache/dubbo/config/CorsConfig.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.config;
+
+import java.io.Serializable;
+
+public class CorsConfig implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String allowedOrigins;
Review Comment:
It's better to use an array.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]