@@ -211,6 +211,10 @@ public final class HttpServerExchange extends AbstractAttachable {
211
211
* the query string
212
212
*/
213
213
private String queryString = "" ;
214
+ /**
215
+ * the non-decoded query string. Set only when query string goes through decoding
216
+ */
217
+ private String nonDecodedQueryString = null ;
214
218
215
219
private int requestWrapperCount = 0 ;
216
220
private ConduitWrapper <StreamSourceConduit >[] requestWrappers ; //we don't allocate these by default, as for get requests they are not used
@@ -466,6 +470,7 @@ public String getRequestId() {
466
470
* Examples:
467
471
* GET http://localhost:8080/myFile.jsf?foo=bar HTTP/1.1 -> 'http://localhost:8080/myFile.jsf'
468
472
* POST /my+File.jsf?foo=bar HTTP/1.1 -> '/my+File.jsf'
473
+ * For the query string, see {@link #getQueryString} and {@link #getNonDecodedQueryString} .
469
474
*/
470
475
public String getRequestURI () {
471
476
return requestURI ;
@@ -584,15 +589,45 @@ public String getQueryString() {
584
589
}
585
590
586
591
/**
587
- * Set query string. Leading ? char will be removed automatically.
592
+ * Set query string. Leading {@code '?'} char will be removed automatically.
593
+ *
594
+ * @return this http server exchange
588
595
*/
589
596
public HttpServerExchange setQueryString (final String queryString ) {
590
597
// Clean leading ?
591
598
if ( queryString .length () > 0 && queryString .charAt (0 ) == '?' ) {
592
- this .queryString = queryString .substring (1 );
593
- } else {
594
- this .queryString = queryString ;
595
- }
599
+ this .queryString = queryString .substring (1 );
600
+ } else {
601
+ this .queryString = queryString ;
602
+ }
603
+ return this ;
604
+ }
605
+
606
+ /**
607
+ * Returns the query string as originally contained in the request, without any decoding.
608
+ * The returned string does not contain the leading {@code '?'} char.
609
+ *
610
+ * @return The request query string, without the leading {@code '?'}, non-decoded.
611
+ */
612
+ public String getNonDecodedQueryString () {
613
+ return this .nonDecodedQueryString == null ? this .queryString : this .nonDecodedQueryString ;
614
+ }
615
+
616
+ /**
617
+ * Sets the non-decoded query string. Leading {@code '?'} char will be removed automatically.<p>
618
+ * Must be invoked only if the {@link #getQueryString() query string} has gone through decoding. In such case, we expect
619
+ * that both forms of the query string will be set in the exchange: {@link #setQueryString decoded} and non-decoded.
620
+ *
621
+ * @param nonDecodedQueryString the query string as originally contained in the request, without any decoding
622
+ * @return this http server exchange
623
+ */
624
+ public HttpServerExchange setNonDecodedQueryString (String nonDecodedQueryString ) {
625
+ // Clean leading ?
626
+ if ( nonDecodedQueryString .length () > 0 && nonDecodedQueryString .charAt (0 ) == '?' ) {
627
+ this .nonDecodedQueryString = nonDecodedQueryString .substring (1 );
628
+ } else {
629
+ this .nonDecodedQueryString = nonDecodedQueryString ;
630
+ }
596
631
return this ;
597
632
}
598
633
0 commit comments