1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -79,39 +79,37 @@ public interface UriBuilder {
79
79
80
80
/**
81
81
* Append to the path of this builder.
82
- * <p>The given value is appended as-is without any checks for slashes other
83
- * than to clean up duplicates . For example:
82
+ * <p>The given value is appended as-is to previous {@link #path(String) path}
83
+ * values without inserting any additional slashes . For example:
84
84
* <pre class="code">
85
85
*
86
86
* builder.path("/first-").path("value/").path("/{id}").build("123")
87
87
*
88
88
* // Results is "/first-value/123"
89
89
* </pre>
90
- * <p>By contrast {@link #pathSegment(String...)} builds the path from
91
- * individual path segments and in that case slashes are inserted transparently.
92
- * In some cases you may use a combination of both {@code pathSegment} and
93
- * {@code path}. For example:
90
+ * <p>By contrast {@link #pathSegment(String...) pathSegment} does insert
91
+ * slashes between individual path segments. For example:
94
92
* <pre class="code">
95
93
*
96
94
* builder.pathSegment("first-value", "second-value").path("/")
97
95
*
98
96
* // Results is "/first-value/second-value/"
99
- *
100
97
* </pre>
101
- * <p>If a URI variable value contains slashes, whether those are encoded or
102
- * not depends on the configured encoding mode. See
103
- * {@link UriComponentsBuilder#encode()}, or if using
104
- * {@code UriComponentsBuilder} via {@link DefaultUriBuilderFactory}
105
- * (e.g. {@code WebClient} or {@code RestTemplate}) see its
106
- * {@link DefaultUriBuilderFactory#setEncodingMode encodingMode} property.
98
+ * <p>The resulting full path is normalized to eliminate duplicate slashes.
99
+ * <p><strong>Note:</strong> When inserting a URI variable value that
100
+ * contains slashes in a {@link #path(String) path}, whether those are
101
+ * encoded depends on the configured encoding mode. For more details, see
102
+ * {@link UriComponentsBuilder#encode()}, or otherwise if building URIs
103
+ * indirectly via {@code WebClient} or {@code RestTemplate}, see its
104
+ * {@link DefaultUriBuilderFactory#setEncodingMode encodingMode}.
107
105
* Also see the <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#web-uri-encoding">
108
106
* URI Encoding</a> section of the reference docs.
109
107
* @param path the URI path
110
108
*/
111
109
UriBuilder path (String path );
112
110
113
111
/**
114
- * Override the existing path.
112
+ * Override the current path.
115
113
* @param path the URI path, or {@code null} for an empty path
116
114
*/
117
115
UriBuilder replacePath (@ Nullable String path );
@@ -123,24 +121,23 @@ public interface UriBuilder {
123
121
* builder.pathSegment("first-value", "second-value", "{id}").build("123")
124
122
*
125
123
* // Results is "/first-value/second-value/123"
126
- *
127
124
* </pre>
128
125
* <p>If slashes are present in a path segment, they are encoded:
129
126
* <pre class="code">
130
127
*
131
128
* builder.pathSegment("ba/z", "{id}").build("a/b")
132
129
*
133
130
* // Results is "/ba%2Fz/a%2Fb"
134
- *
135
131
* </pre>
136
132
* To insert a trailing slash, use the {@link #path} builder method:
137
133
* <pre class="code">
138
134
*
139
135
* builder.pathSegment("first-value", "second-value").path("/")
140
136
*
141
137
* // Results is "/first-value/second-value/"
142
- *
143
138
* </pre>
139
+ * <p>Empty path segments are ignored and therefore duplicate slashes do not
140
+ * appear in the resulting full path.
144
141
* @param pathSegments the URI path segments
145
142
*/
146
143
UriBuilder pathSegment (String ... pathSegments ) throws IllegalArgumentException ;
0 commit comments