1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.support;
14
15 import com.eviware.soapui.support.StringUtils;
16
17 public class HttpUtils
18 {
19 public static boolean isErrorStatus( int statusCode )
20 {
21 return statusCode >= 400;
22 }
23
24 public static String extractHttpHeaderParameter( String headerString, String parameterName )
25 {
26 if( !StringUtils.hasContent( headerString ) || !StringUtils.hasContent( parameterName ) )
27 return null;
28
29 int ix = headerString.indexOf( parameterName + "=\"" );
30 if( ix > 0 )
31 {
32 int ix2 = headerString.indexOf( '"', ix + parameterName.length() + 2 );
33 if( ix2 > ix )
34 return headerString.substring( ix + parameterName.length() + 2, ix2 );
35 }
36
37 return null;
38 }
39
40 public static String ensureEndpointStartsWithProtocol( String endpoint )
41 {
42 if( StringUtils.isNullOrEmpty( endpoint ) )
43 return endpoint;
44
45 String ep = endpoint.toLowerCase().trim();
46 if( !ep.startsWith( "http://" ) && !ep.startsWith( "https://" ) && !ep.startsWith( "$" ) )
47 return "http://" + endpoint;
48
49 return endpoint;
50 }
51 }