@@ -53,7 +53,7 @@ public final class RequestContent implements Serializable {
5353
5454 private static final List <String > SUPPORTED_DATE_FORMATS = Arrays .asList (DATE_FORMAT_RFC1123 , DATE_FORMAT );
5555
56- private static final long serialVersionUID = -2968642080214687631L ;
56+ private static final long serialVersionUID = -2968642080214687632L ;
5757
5858 @ Deprecated
5959 private final String requestLine ;
@@ -181,7 +181,10 @@ public RequestContent build() {
181181 * @param headers the list of headers to be included in the signed content
182182 * @param charset charset for decoding the content
183183 * @return the result of {@link #getContentString(java.util.List)} encoded using the provided {@link Charset}
184+ * @deprecated use {@link #getBytesToSign(List, Charset)} to include the {@link Constants#HEADER_REQUEST_TARGET}
185+ * prefix in signature content
184186 */
187+ @ Deprecated
185188 public byte [] getContent (List <String > headers , Charset charset ) {
186189 return getContentString (headers ).getBytes (charset );
187190 }
@@ -191,8 +194,42 @@ public byte[] getContent(List<String> headers, Charset charset) {
191194 *
192195 * @param headers the list of headers to be included in the signed content
193196 * @return formatted content to be signed
197+ * @deprecated use {@link #getStringToSign(List)} to include the {@link Constants#HEADER_REQUEST_TARGET}
198+ * prefix in signature content
194199 */
200+ @ Deprecated
195201 public String getContentString (List <String > headers ) {
202+ return getStringToSign (headers , true );
203+ }
204+
205+ /**
206+ * Returns the request content as a String for generating a signature.
207+ *
208+ * @param headers the list of headers to be included in the signed content
209+ * @return formatted content to be signed
210+ */
211+ public String getStringToSign (List <String > headers ) {
212+ return getStringToSign (headers , false );
213+ }
214+
215+ /**
216+ * Returns the request content as a byte array for generating a signature.
217+ *
218+ * @param headers the list of headers to be included in the signed content
219+ * @param charset charset for decoding the content
220+ * @return the result of {@link #getStringToSign(List)} encoded using the provided {@link Charset}
221+ */
222+ public byte [] getBytesToSign (List <String > headers , Charset charset ) {
223+ return getStringToSign (headers ).getBytes (charset );
224+ }
225+
226+ /**
227+ * Method created for backwards compatibility.
228+ * @param headers the list of headers to be included in the signed content.
229+ * @param suppressRequestTargetPrefix true to remove "(request-target): " from the content.
230+ * @return formatted content String to be signed.
231+ */
232+ private String getStringToSign (List <String > headers , boolean suppressRequestTargetPrefix ) {
196233 StringBuilder hashBuilder = new StringBuilder ();
197234 if (headers != null ) {
198235 for (String header : headers ) {
@@ -204,6 +241,9 @@ public String getContentString(List<String> headers) {
204241 }
205242 } else if (Constants .HEADER_REQUEST_TARGET .equals (_header )) {
206243 if (this .getRequestTarget () != null ) {
244+ if (!suppressRequestTargetPrefix ) {
245+ hashBuilder .append (Constants .HEADER_REQUEST_TARGET ).append (": " );
246+ }
207247 hashBuilder .append (this .getRequestTarget ()).append ('\n' );
208248 }
209249 } else {
@@ -219,7 +259,7 @@ public String getContentString(List<String> headers) {
219259
220260 @ Override
221261 public String toString () {
222- return getContentString (this .getHeaderNames ());
262+ return getStringToSign (this .getHeaderNames ());
223263 }
224264
225265 /**
0 commit comments