@@ -634,8 +634,7 @@ public T setConnectionPoolKeyStrategy(ConnectionPoolKeyStrategy connectionPoolKe
634
634
return derived .cast (this );
635
635
}
636
636
637
- public Request build () {
638
-
637
+ private void executeSignatureCalculator () {
639
638
/* Let's first calculate and inject signature, before finalizing actual build
640
639
* (order does not matter with current implementation but may in future)
641
640
*/
@@ -647,8 +646,28 @@ public Request build() {
647
646
url = url .substring (0 , i );
648
647
}
649
648
signatureCalculator .calculateAndAddSignature (url , request , this );
649
+ }
650
+ }
651
+
652
+ private void computeRequestCharset () {
653
+ if (request .charset != null ) {
654
+ try {
655
+ final String contentType = request .headers .getFirstValue ("Content-Type" );
656
+ if (contentType != null ) {
657
+ final String charset = AsyncHttpProviderUtils .parseCharset (contentType );
658
+ if (charset != null ) {
659
+ // ensure that if charset is provided with the Content-Type header,
660
+ // we propagate that down to the charset of the Request object
661
+ request .charset = charset ;
662
+ }
663
+ }
664
+ } catch (Throwable e ) {
665
+ // NoOp -- we can't fix the Content-Type or charset from here
666
+ }
650
667
}
651
-
668
+ }
669
+
670
+ private void computeRequestContentLength () {
652
671
if (request .length < 0 && request .streamData == null ) {
653
672
// can't concatenate content-length
654
673
String contentLength = null ;
@@ -664,6 +683,14 @@ public Request build() {
664
683
}
665
684
}
666
685
}
686
+ }
687
+
688
+ public Request build () {
689
+
690
+ executeSignatureCalculator ();
691
+ computeRequestCharset ();
692
+ computeRequestContentLength ();
693
+
667
694
if (request .cookies != null ) {
668
695
request .cookies = Collections .unmodifiableCollection (request .cookies );
669
696
}
0 commit comments