Alanxtl commented on code in PR #3277: URL: https://github.com/apache/dubbo-go/pull/3277#discussion_r2972954844
########## protocol/triple/server.go: ########## Review Comment: 再加一个 streaming method 的 case,确认 server-stream / bidi 这类 handler 注册路径也能通过 fallback 命中 ########## protocol/triple/triple_protocol/method_route_mux.go: ########## @@ -0,0 +1,118 @@ +/* + * 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 triple_protocol + +import ( + "net/http" + "sync" + "unicode" + "unicode/utf8" +) + +// methodRouteMux wraps http.ServeMux to provide case-insensitive procedure +// routing without duplicating method metadata in higher layers. +// +// Lookup order: +// 1. exact match via http.ServeMux +// 2. lowercase-first-method fallback via an internal index +type methodRouteMux struct { + exact *http.ServeMux + + mu sync.RWMutex + lower map[string]methodRouteEntry +} + +type methodRouteEntry struct { + pattern string + handler http.Handler +} + +func newMethodRouteMux() *methodRouteMux { + return &methodRouteMux{ + exact: http.NewServeMux(), + lower: make(map[string]methodRouteEntry), + } +} + +// Handle registers the handler in the exact mux and the lowercase-first-method +// fallback index. If two patterns collide after fallback normalization, the +// first registration wins while exact matching keeps the original behavior. +func (m *methodRouteMux) Handle(pattern string, handler http.Handler) { + m.exact.Handle(pattern, handler) + + lowerKey := normalizeMethodRouteKey(pattern) + m.mu.Lock() + if _, exists := m.lower[lowerKey]; !exists { + m.lower[lowerKey] = methodRouteEntry{ + pattern: pattern, + handler: handler, + } + } + m.mu.Unlock() Review Comment: ```suggestion m.mu.Lock() defer m.mu.Unlock() if _, exists := m.lower[lowerKey]; !exists { m.lower[lowerKey] = methodRouteEntry{ pattern: pattern, handler: handler, } } ``` ########## protocol/triple/server.go: ########## Review Comment: 对 handleServiceWithInfo / registerMethodHandler 那条真实注册链路的测试覆盖还不够。 -- 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]
