@@ -22,19 +22,19 @@ public class HTTPRequestHeader {
2222
2323 public HTTPRequestHeader (final String requestHeader ) {
2424 this .rawRequest = requestHeader .trim ();
25- String [] tmp = requestHeader . trim () .split (" " );
25+ String [] tmp = rawRequest .split (" " );
2626 if (tmp .length != REQUIRED_REQUEST_ITEMS ) {
2727 throw new IllegalArgumentException ("HTTPRequestHeader can only have 3 arguments! :" +requestHeader );
2828 }
2929 requestType = tmp [0 ].trim ().toUpperCase ();
3030 String ptmp = tmp [1 ].trim ();
31- if ( ptmp .indexOf ("?" ) >= 0 ) {
32- int pos = tmp [ 1 ]. indexOf ( "?" );
33- requestPath = ptmp .substring (0 , pos );
34- requestQuery = HTTPUtils .queryToMap (ptmp .substring (pos +1 ));
31+ int queryParamPos = ptmp .indexOf ('?' );
32+ if ( queryParamPos >= 0 ) {
33+ requestPath = ptmp .substring (0 , queryParamPos );
34+ requestQuery = HTTPUtils .queryToMap (ptmp .substring (queryParamPos +1 ));
3535 } else {
3636 requestPath = ptmp ;
37- requestQuery = HTTPUtils . queryToMap ( "" );
37+ requestQuery = Collections . emptyMap ( );
3838 }
3939
4040 httpVersion = tmp [2 ].trim ().toUpperCase ();
@@ -50,31 +50,31 @@ public HTTPRequestHeader(HTTPRequestType requestType, String requestPath, Map<St
5050 public HTTPRequestHeader (String requestType , String requestPath , Map <String , String > requestQuery , String httpVersion ){
5151 this .requestType = requestType ;
5252 final HashMap <String , String > rqm = new HashMap <>();
53- if ( requestPath .contains ("?" )) {
54- int pos = requestPath . indexOf ( "?" );
55- this .requestPath = requestPath .substring (0 , pos );
56- rqm .putAll (HTTPUtils .queryToMap (requestPath .substring (pos +1 )));
53+ int queryParamPos = requestPath .indexOf ("?" );
54+ if ( queryParamPos >= 0 ) {
55+ this .requestPath = requestPath .substring (0 , queryParamPos );
56+ rqm .putAll (HTTPUtils .queryToMap (requestPath .substring (queryParamPos +1 )));
5757 } else {
5858 this .requestPath = requestPath ;
5959 }
6060 if (requestQuery != null ) {
6161 rqm .putAll (requestQuery );
6262 }
6363 this .requestQuery = Collections .unmodifiableMap (rqm );
64+ if (!HTTPConstants .HTTP_VERSION_1_1 .equals (httpVersion ) && !HTTPConstants .HTTP_VERSION_1_0 .equals (httpVersion )) {
65+ throw new UnsupportedOperationException ("Unknown HTTP Version!:" +httpVersion );
66+ }
6467 this .httpVersion = httpVersion .trim ().toUpperCase ();
6568 StringBuilder sb = new StringBuilder ();
6669 sb .append (requestType .toString ());
6770 sb .append (HTTPConstants .SPACE );
6871 sb .append (requestPath );
69- if (requestQuery != null && requestQuery .size () > 0 ) {
72+ if (requestQuery != null && ! requestQuery .isEmpty () ) {
7073 sb .append (HTTPUtils .queryToString (requestQuery ));
7174 }
7275 sb .append (HTTPConstants .SPACE );
7376 sb .append (this .httpVersion );
7477 rawRequest = sb .toString ();
75- if (!httpVersion .equals (HTTPConstants .HTTP_VERSION_1_1 ) && !httpVersion .equals (HTTPConstants .HTTP_VERSION_1_0 )) {
76- throw new UnsupportedOperationException ("Unknown HTTP Version!:" +httpVersion );
77- }
7878 }
7979
8080 public String getRequestType () {
@@ -113,13 +113,14 @@ public int hashCode() {
113113
114114 @ Override
115115 public boolean equals (Object o ) {
116- if (o instanceof HTTPRequestHeader ) {
116+ if (o == this ) {
117+ return true ;
118+ } else if (o instanceof HTTPRequestHeader ) {
117119 HTTPRequestHeader hrh = (HTTPRequestHeader )o ;
118120 if (hrh .toString ().equals (this .toString ())) {
119121 return true ;
120122 }
121123 }
122124 return false ;
123125 }
124-
125126}
0 commit comments