@Override public ContentType getContentType() { if(headers != null) { return HttpUtil.getContentType(headers); } return null; }
@Override public String toString() { return HttpUtil.getFormattedContentType(contentType, charset); } }
@Override public String getContentTypeString() { return HttpUtil.getMimeFromContentType(jtf_content_type_charset.getText()); }
public static boolean isTextContentType(final String contentType) { final String ct = getContentTypeBeforeSemiColon(contentType); return ct.startsWith("text/") || isXmlContentType(ct) || isJsonContentType(ct) || isFormUrlEncodedContentType(ct) || TEXT_CT.contains(ct); }
final boolean isXml = HttpUtil.isXmlContentType(type.getContentType()); final boolean isJson = HttpUtil.isJsonContentType(type.getContentType()); final boolean isHTML = HttpUtil.isHTMLContentType(type.getContentType()); se_response.setSyntax(TextEditorSyntax.JSON); if(HttpUtil.isJsContentType(type.getContentType())) { se_response.setSyntax(TextEditorSyntax.JS); if(HttpUtil.isCssContentType(type.getContentType())) { se_response.setSyntax(TextEditorSyntax.CSS); final String responseBody = new String(getBody(), HttpUtil.getCharsetDefault(type)); if(options.isPropertyTrue("response.body.indent")) { if(isXml){
public static boolean isFormUrlEncodedContentType(final String contentType) { final String ct = getContentTypeBeforeSemiColon(contentType); return ct.startsWith("application/x-www-form-urlencoded"); }
/** * Test of getCharsetFromContentType method, of class Util. */ @Test public void testGetCharsetFromContentType() { System.out.println("getCharsetFromContentType"); String contentType = "Content-type: text/html; charset=UTF-8"; String expResult = "UTF-8"; String result = HttpUtil.getCharsetFromContentType(contentType); assertEquals(expResult, result); // when charset is not available, return null: contentType = "Content-type: text/html"; expResult = null; result = HttpUtil.getCharsetFromContentType(contentType); assertEquals(expResult, result); }
@Override public Response getResponseFromUI(){ ResponseBean response = new ResponseBean(); response.setResponseBody(jp_res_body.getBody()); String statusLine = jp_res_status.getStatus(); response.setStatusLine(statusLine); response.setStatusCode(HttpUtil.getStatusCodeFromStatusLine(statusLine)); MultiValueMap<String, String> headers = jp_res_headers.getHeaders(); headers.keySet().stream().forEach((String key) -> { headers.get(key).stream().forEach((value) -> { response.addHeader(key, value); }); }); response.setTestResult(jp_res_test.getTestResult()); response.setExecutionTime(jp_res_stats.getExecutionTime()); return response; }
jd_req_paramDialog.setData(HttpUtil.getXWwwFormUrlEncoded2Map(se_req_body.getText())); break;
public static boolean isCssContentType(final String contentType) { final String ct = getContentTypeBeforeSemiColon(contentType); return ct.startsWith("text/css"); }
@Override public String getContentTypeCharsetFormatted() { return HttpUtil.getFormattedContentType(contentType); }
public static ContentType getContentType(MultiValueMap<String, String> headers) { for(String key: headers.keySet()) { if("content-type".equalsIgnoreCase(key.trim())) { return getContentType(headers.get(key).iterator().next()); } } return null; }
@Test public void testGetMimeFromContentType() { System.out.println("getMimeFromContentType"); String contentType = "application/xml;charset=UTF-8"; String expResult = "application/xml"; String result = HttpUtil.getMimeFromContentType(contentType); assertEquals(expResult, result); } }
public static boolean isJsonContentType(final String contentType) { final String ct = getContentTypeBeforeSemiColon(contentType); return ct.startsWith("application/json") || ct.endsWith("+json"); }
@Override public void changed(String contentType, String charset) { final String formatted = HttpUtil.getFormattedContentType(contentType, charset); jtf_content_type_charset.setText(formatted); } });
/** * Test of getContentType method, of class HttpUtil. */ @Test public void testGetContentType_String() { System.out.println("getContentType"); String header = "application/vnd.mnet.staticwebspaces+xml;version=1;charset=UTF-8"; ContentType expResult = new ContentTypeBean("application/vnd.mnet.staticwebspaces+xml", Charsets.UTF_8); ContentType result = HttpUtil.getContentType(header); assertEquals(expResult, result); } }
public static boolean isHTMLContentType(final String contentType) { final String ct = getContentTypeBeforeSemiColon(contentType); return ct.startsWith("text/html") || ct.endsWith("+html"); }
public static String getFormattedContentType(final String contentType, final Charset charset){ return getFormattedContentType(contentType, (charset!=null? charset.name(): null)); }
public static boolean isWebImageContentType(final String contentType) { final String ct = getContentTypeBeforeSemiColon(contentType); return ct.equals("image/jpeg") || ct.equals("image/png") || ct.equals("image/gif"); }
@Override public void setContentTypeCharset(String contentType, Charset charset) { jd.setContentType(contentType); if(charset != null) { jd.setCharset(charset); } jtf_content_type_charset.setText( HttpUtil.getFormattedContentType(contentType, charset)); }