60
60
import org .restlet .engine .header .WarningReader ;
61
61
import org .restlet .engine .security .AuthenticatorUtils ;
62
62
import org .restlet .engine .util .DateUtils ;
63
+ import org .restlet .engine .util .ReferenceUtils ;
63
64
import org .restlet .ext .nio .internal .connection .Connection ;
64
65
import org .restlet .util .Series ;
65
66
@@ -746,16 +747,16 @@ public void setHeaders(Series<Header> headers) {
746
747
} else {
747
748
// IPv6 address handling.
748
749
//
749
- // Two possible cases, host == "[::1]:8182" --using the 8182
750
- // port. host == "[::1]" ------ using the default port 80.
750
+ // Two possible cases:
751
+ // - host == "[::1]:8182" --using the 8182 port.
752
+ // - host == "[::1]" ------ using the default port 80.
751
753
//
752
754
// For IPv6 address, we use ']' to separate the domain and the
753
755
// port, because it's unique.
754
756
if (rightSquareBracketIndex + 1 < host .length ()) {
755
757
// Using specified port
756
758
hostDomain = host .substring (0 , rightSquareBracketIndex + 1 );
757
- hostPort = Integer .valueOf (host
758
- .substring (rightSquareBracketIndex + 2 ));
759
+ hostPort = Integer .valueOf (host .substring (rightSquareBracketIndex + 2 ));
759
760
} else if (rightSquareBracketIndex + 1 == host .length ()) {
760
761
// Must be using default port 80,
761
762
hostDomain = host ;
@@ -767,15 +768,11 @@ public void setHeaders(Series<Header> headers) {
767
768
+ hostDomain + ", hostPort: " + hostPort );
768
769
}
769
770
} else {
770
- Protocol serverProtocol = getConnection ().getHelper ().getHelped ()
771
- .getProtocols ().get (0 );
772
-
773
- if (!Protocol .SIP .getSchemeName ().equals (
774
- serverProtocol .getSchemeName ())
775
- && !Protocol .SIPS .getSchemeName ().equals (
776
- serverProtocol .getSchemeName ())) {
777
- Context .getCurrentLogger ()
778
- .info ("Couldn't find the mandatory \" Host\" HTTP header. Falling back to the IP address." );
771
+ Protocol serverProtocol = getConnection ().getHelper ().getHelped ().getProtocols ().get (0 );
772
+
773
+ if (!Protocol .SIP .getSchemeName ().equals (serverProtocol .getSchemeName ())
774
+ && !Protocol .SIPS .getSchemeName ().equals (serverProtocol .getSchemeName ())) {
775
+ Context .getCurrentLogger ().info ("Couldn't find the mandatory \" Host\" HTTP header. Falling back to the IP address." );
779
776
hostDomain = getConnection ().getAddress ();
780
777
hostPort = getConnection ().getPort ();
781
778
@@ -784,8 +781,7 @@ public void setHeaders(Series<Header> headers) {
784
781
}
785
782
786
783
if (hostPort == -1 ) {
787
- hostPort = getConnection ().getHelper ().getHelped ()
788
- .getActualPort ();
784
+ hostPort = getConnection ().getHelper ().getHelped ().getActualPort ();
789
785
}
790
786
791
787
if (hostPort == -1 ) {
@@ -795,8 +791,7 @@ public void setHeaders(Series<Header> headers) {
795
791
}
796
792
797
793
// Set the host reference
798
- Protocol protocol = getConnection ().getHelper ().getHelped ()
799
- .getProtocols ().get (0 );
794
+ Protocol protocol = getConnection ().getHelper ().getHelped ().getProtocols ().get (0 );
800
795
StringBuilder sb = new StringBuilder ();
801
796
sb .append (protocol .getSchemeName ()).append ("://" );
802
797
sb .append (hostDomain );
@@ -814,20 +809,18 @@ public void setHeaders(Series<Header> headers) {
814
809
if (getResourceRef ().isRelative ()) {
815
810
// Take care of the "/" between the host part and the segments.
816
811
if (!resourceUri .startsWith ("/" )) {
817
- setResourceRef (new Reference (getHostRef ().toString () + "/"
818
- + resourceUri ));
812
+ setResourceRef (new Reference (getHostRef ().toString () + "/" + resourceUri ));
819
813
} else {
820
- setResourceRef (new Reference (getHostRef ().toString ()
821
- + resourceUri ));
814
+ setResourceRef (new Reference (getHostRef ().toString () + resourceUri ));
822
815
}
823
816
}
824
817
825
- setOriginalRef (getResourceRef (). getTargetRef ( ));
818
+ setOriginalRef (ReferenceUtils . getOriginalRef ( getResourceRef (), headers ));
826
819
}
827
820
828
821
// Set the request date
829
- String dateHeader = (getHeaders () == null ) ? null : getHeaders ()
830
- .getFirstValue (HeaderConstants .HEADER_DATE , true );
822
+ String dateHeader = (getHeaders () == null ) ? null :
823
+ getHeaders () .getFirstValue (HeaderConstants .HEADER_DATE , true );
831
824
Date date = null ;
832
825
if (dateHeader != null ) {
833
826
date = DateUtils .parse (dateHeader );
@@ -840,8 +833,8 @@ public void setHeaders(Series<Header> headers) {
840
833
setDate (date );
841
834
842
835
// Set the max forwards
843
- String maxForwardsHeader = (getHeaders () == null ) ? null : getHeaders ()
844
- .getFirstValue (HeaderConstants .HEADER_MAX_FORWARDS , true );
836
+ String maxForwardsHeader = (getHeaders () == null ) ? null :
837
+ getHeaders () .getFirstValue (HeaderConstants .HEADER_MAX_FORWARDS , true );
845
838
if (maxForwardsHeader != null ) {
846
839
try {
847
840
setMaxForwards (Integer .parseInt (maxForwardsHeader ));
0 commit comments