Dart架子和rpc包装之间不兼容? ('access-control-request-method'标题)

时间:2015-05-05 08:36:20

标签: dart dart-shelf dart-rpc

架子和rpc包之间似乎不兼容。

在rpc [0.4.1] config / api.dart中:handleHttpOptionsRequest需要 'access-control-request-method'标题为List:

    Future<HttpApiResponse> handleHttpOptionsRequest(
          ParsedHttpApiRequest request) async {
        var requestedHttpMethods = request.headers['access-control-request-method'];
        List<String> allowed = [];
        assert('OPTIONS'.allMatches(request.methodKey).length == 1);
        if (requestedHttpMethods != null) {
          requestedHttpMethods.forEach((httpMethod) {
            var methodKey =
                request.methodKey.replaceFirst('OPTIONS', httpMethod);
            final List<ApiConfigMethod> methods = _methodMap[methodKey];
            if (methods != null) {
              for (var method in methods) {
                if (method.matches(request)) {
                  allowed.add(httpMethod);
                  break;
               }
              }
            }
          });
        }

使用货架[0.5.7]包装时, 传递给此方法的ParsedHttpApiRequest包含一个 'access-control-request-method'标头,它是一个字符串。

这会产生异常......

当使用rpc和dart.io HttpServer时,代码工作正常并且ParsedHttpApiRequest 有一个字符串列表(单个元素)作为值的值 'access-control-request-method'标题。

是否有人成功使用dart rpc + shelf?如果是这样,任何关于如何避免的想法 异常?

=== [更新]在rpc修复之后,前面提到的问题似乎已修复。感谢那! 我现在遇到另一个问题,但我还没有详细调查。 堆栈跟踪是:

shelf [0.5.7] shelf_rpc [0.0.3] rpc [0.4.2]:

     Error thrown by handler.
     type 'List' is not a subtype of type 'String' of 'value'.
     package:collection/src/canonicalized_map.dart 66:30  CanonicalizedMap.[]=
     package:collection/src/canonicalized_map.dart 71:39  CanonicalizedMap.addAll.<fn>
     dart:collection                                      _CompactLinkedHashMap.forEach
     package:collection/src/canonicalized_map.dart 71:18  CanonicalizedMap.addAll
     package:collection/src/canonicalized_map.dart 57:11  CanonicalizedMap.CanonicalizedMap.from
     package:shelf/src/response.dart 215:9                Response.Response
     package:shelf_rpc/shelf_rpc.dart 18:24               createRpcHandler.<fn>.<fn>

=&GT;见incompatibility when running dart rpc and shelf (with shelf_rpc) related to headers which are lists (and not Strings)

1 个答案:

答案 0 :(得分:4)

这是RPC包中的错误。我将修复此ASAP并发布新版本的RPC包。

欢迎您在github下提交此类问题:

https://github.com/dart-lang/rpc/issues

干杯, /古斯塔夫