This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch dropwizard-5
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 7760ea214b8af5e35c47bffcc09b8f6a31d90e40
Author: Robert Newson <[email protected]>
AuthorDate: Sat Nov 14 08:09:22 2026 +0000

    Pass index/path as query param
    
    Also use openapi introspection to determine how to communicate with
    a nouveau server that hasn't been updated yet.
---
 .../couchdb/nouveau/resources/IndexResource.java   | 16 ++++++------
 src/nouveau/src/nouveau_api.erl                    | 29 +++++++++++++++++-----
 src/nouveau/src/nouveau_gun.erl                    | 17 +++++++++++++
 3 files changed, 48 insertions(+), 14 deletions(-)

diff --git 
a/extra/nouveau/src/main/java/org/apache/couchdb/nouveau/resources/IndexResource.java
 
b/extra/nouveau/src/main/java/org/apache/couchdb/nouveau/resources/IndexResource.java
index be93b2151..bd9d038af 100644
--- 
a/extra/nouveau/src/main/java/org/apache/couchdb/nouveau/resources/IndexResource.java
+++ 
b/extra/nouveau/src/main/java/org/apache/couchdb/nouveau/resources/IndexResource.java
@@ -24,8 +24,8 @@ import jakarta.ws.rs.GET;
 import jakarta.ws.rs.POST;
 import jakarta.ws.rs.PUT;
 import jakarta.ws.rs.Path;
-import jakarta.ws.rs.PathParam;
 import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
 import jakarta.ws.rs.WebApplicationException;
 import jakarta.ws.rs.core.MediaType;
 import jakarta.ws.rs.core.Response.Status;
@@ -43,7 +43,7 @@ import org.apache.couchdb.nouveau.api.SearchRequest;
 import org.apache.couchdb.nouveau.api.SearchResults;
 import org.apache.couchdb.nouveau.core.IndexManager;
 
-@Path("/index/{name}")
+@Path("/index")
 @Metered
 @ResponseMetered
 @ExceptionMetered(cause = IOException.class)
@@ -58,7 +58,7 @@ public final class IndexResource {
     }
 
     @PUT
-    public Ok createIndex(@PathParam("name") String name, @NotNull @Valid 
IndexDefinition indexDefinition)
+    public Ok createIndex(@QueryParam("name") String name, @NotNull @Valid 
IndexDefinition indexDefinition)
             throws IOException {
         if (!indexDefinition.isLatestVersion()) {
             throw new WebApplicationException(
@@ -70,20 +70,20 @@ public final class IndexResource {
     }
 
     @DELETE
-    public Ok deletePath(@PathParam("name") String path, @Valid final 
List<String> exclusions) throws IOException {
+    public Ok deletePath(@QueryParam("name") String path, @Valid final 
List<String> exclusions) throws IOException {
         indexManager.deleteAll(path, exclusions);
         return Ok.INSTANCE;
     }
 
     @GET
-    public IndexInfoResponse getIndexInfo(@PathParam("name") String name) 
throws Exception {
+    public IndexInfoResponse getIndexInfo(@QueryParam("name") String name) 
throws Exception {
         return indexManager.with(name, (index) -> {
             return index.info();
         });
     }
 
     @POST
-    public Ok setIndexInfo(@PathParam("name") String name, @NotNull @Valid 
IndexInfoRequest request) throws Exception {
+    public Ok setIndexInfo(@QueryParam("name") String name, @NotNull @Valid 
IndexInfoRequest request) throws Exception {
         return indexManager.with(name, (index) -> {
             var shouldCommit = false;
             if (request.matchUpdateSeq().isPresent() && 
request.updateSeq().isPresent()) {
@@ -106,7 +106,7 @@ public final class IndexResource {
 
     @POST
     @Path("/search")
-    public SearchResults searchIndex(@PathParam("name") String name, @NotNull 
@Valid SearchRequest request)
+    public SearchResults searchIndex(@QueryParam("name") String name, @NotNull 
@Valid SearchRequest request)
             throws Exception {
         return indexManager.with(name, (index) -> {
             return index.search(request);
@@ -115,7 +115,7 @@ public final class IndexResource {
 
     @POST
     @Path("/update")
-    public Ok update(@PathParam("name") String name, @NotNull @Valid 
BulkUpdateRequest request) throws Exception {
+    public Ok update(@QueryParam("name") String name, @NotNull @Valid 
BulkUpdateRequest request) throws Exception {
         return indexManager.with(name, (index) -> {
             for (var update : request.updates()) {
                 if (update.update() instanceof DocumentUpdateRequest) {
diff --git a/src/nouveau/src/nouveau_api.erl b/src/nouveau/src/nouveau_api.erl
index e6bdb8cf9..a501d2e98 100644
--- a/src/nouveau/src/nouveau_api.erl
+++ b/src/nouveau/src/nouveau_api.erl
@@ -234,16 +234,33 @@ supported_lucene_versions() ->
 
 %% private functions
 
-index_path(Path) when is_binary(Path) ->
-    [<<"/index/">>, couch_util:url_encode(Path)];
-index_path(#index{} = Index) ->
-    [<<"/index/">>, couch_util:url_encode(nouveau_util:index_name(Index))].
+index_path(Arg) ->
+    index_path(nouveau_gun:server_flavour(), Arg).
+
+index_path(path, Path) when is_binary(Path) ->
+    [~"/index/", couch_util:url_encode(Path)];
+index_path(path, #index{} = Index) ->
+    [~"/index/", couch_util:url_encode(nouveau_util:index_name(Index))];
+index_path(query, Path) when is_binary(Path) ->
+    [~"/index?name=", couch_util:url_encode(Path)];
+index_path(query, #index{} = Index) ->
+    [~"/index?name=", couch_util:url_encode(nouveau_util:index_name(Index))].
 
 search_path(#index{} = Index) ->
-    [index_path(Index), <<"/search">>].
+    search_path(nouveau_gun:server_flavour(), Index).
+
+search_path(path, #index{} = Index) ->
+    [index_path(path, Index), ~"/search"];
+search_path(query, #index{} = Index) ->
+    [~"/index/search?name=", 
couch_util:url_encode(nouveau_util:index_name(Index))].
 
 update_path(#index{} = Index) ->
-    [index_path(Index), <<"/update">>].
+    update_path(nouveau_gun:server_flavour(), Index).
+
+update_path(path, #index{} = Index) ->
+    [index_path(path, Index), <<"/update">>];
+update_path(query, #index{} = Index) ->
+    [~"/index/update?name=", 
couch_util:url_encode(nouveau_util:index_name(Index))].
 
 jaxrs_error(400, Body) ->
     {bad_request, message(Body)};
diff --git a/src/nouveau/src/nouveau_gun.erl b/src/nouveau/src/nouveau_gun.erl
index 93bc3b845..c124a9138 100644
--- a/src/nouveau/src/nouveau_gun.erl
+++ b/src/nouveau/src/nouveau_gun.erl
@@ -23,6 +23,7 @@
 
 -export([start_link/0]).
 -export([request/4]).
+-export([server_flavour/0]).
 
 %%% gen_server callbacks
 -export([init/1]).
@@ -43,12 +44,17 @@
     openapi
 }).
 
+-define(NOUVEAU_SERVER_FLAVOUR, nouveau_server_flavour).
+
 start_link() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
 
 request(Method, Path, Headers, Body) ->
     gen_server:call(?MODULE, {request, Method, Path, Headers, Body, #{reply_to 
=> self()}}).
 
+server_flavour() ->
+    persistent_term:get(?NOUVEAU_SERVER_FLAVOUR, query).
+
 init(_) ->
     ok = config:listen_for_changes(?MODULE, nil),
     State = #state{enabled = false, url = nouveau_util:nouveau_url()},
@@ -83,6 +89,7 @@ handle_info({gun_down, GunPid, http2, Reason, KilledStreams}, 
#state{gun_pid = G
     couch_log:warning("Gun down for reason ~p (killed streams: ~p)", [Reason, 
KilledStreams]),
     {noreply, State};
 handle_info({openapi_ok, OpenAPI}, State) ->
+    set_server_flavour(OpenAPI),
     {noreply, State#state{openapi = OpenAPI}};
 handle_info({openapi_error, Reason}, State) ->
     {stop, {error, Reason}, State};
@@ -221,3 +228,13 @@ sync_request(GunPid, GunMRef, Method, Path, ReqHeaders, 
ReqBody) ->
         {error, Reason} ->
             {error, Reason}
     end.
+
+set_server_flavour(OpenAPI) ->
+    persistent_term:put(?NOUVEAU_SERVER_FLAVOUR, server_flavour(OpenAPI)).
+
+%% Nouveau switched to query parameter for passing the index name to avoid
+%% ambiguous URI restrictions in new version of Jetty.
+server_flavour(#{~"paths" := #{~"/index/update" := _, ~"/index/search" := _}}) 
->
+    query;
+server_flavour(#{~"paths" := #{~"/index/{name}/update" := _, 
~"/index/{name}/search" := _}}) ->
+    path.

Reply via email to