private Properties getRequestProperties ( final ICommandLine cl , final String method ) throws UnsupportedEncodingException { Properties props = new Properties ( ) ; if ( cl . hasOption ( "useragent" ) ) { props . setProperty ( "User-Agent" , cl . getOptionValue ( "useragent" ) ) ; } else { props . setProperty ( "User-Agent" , DEFAULT_USER_AGENT ) ; } if ( cl . hasOption ( "content-type" ) && "POST" . equalsIgnoreCase ( method ) ) { props . setProperty ( "Content-Type" , cl . getOptionValue ( "content-type" ) ) ; } if ( cl . hasOption ( "header" ) ) { List headers = cl . getOptionValues ( "header" ) ; for ( Object obj : headers ) { String header = ( String ) obj ; String key = header . split ( ":" ) [ 0 ] . trim ( ) ; String value = header . split ( ":" ) [ 1 ] . trim ( ) ; props . setProperty ( key , value ) ; } } String auth = null ; String encoded = null ; if ( cl . hasOption ( "authorization" ) ) { encoded = Base64 . encodeBase64String ( cl . getOptionValue ( "authorization" ) . getBytes ( CHARSET ) ) ; auth = "Authorization" ; } else if ( cl . hasOption ( "proxy-authorization" ) ) { encoded = Base64 . encodeBase64String ( cl . getOptionValue ( "proxy-authorization" ) . getBytes ( CHARSET ) ) ; auth = "Proxy-Authorization" ; } if ( auth != null && encoded != null ) { props . setProperty ( auth , "Basic " + encoded ) ; } return props ; }
Set the http request properties and headers .