001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.util; 020 021import java.io.IOException; 022import java.io.UnsupportedEncodingException; 023import java.net.MalformedURLException; 024import java.net.URI; 025import java.net.URISyntaxException; 026import java.net.URL; 027 028import lucee.commons.net.http.HTTPResponse; 029import lucee.commons.net.http.Header; 030 031public interface HTTPUtil { 032 033 /** 034 * Field <code>ACTION_POST</code> 035 */ 036 public static final short ACTION_POST=0; 037 038 /** 039 * Field <code>ACTION_GET</code> 040 */ 041 public static final short ACTION_GET=1; 042 043 /** 044 * Field <code>STATUS_OK</code> 045 */ 046 public static final int STATUS_OK=200; 047 //private static final String NO_MIMETYPE="Unable to determine MIME type of file."; 048 049 /** 050 * make a http requst to given url 051 * @param url 052 * @param username 053 * @param password 054 * @param timeout 055 * @param charset 056 * @param useragent 057 * @param proxyserver 058 * @param proxyport 059 * @param proxyuser 060 * @param proxypassword 061 * @return resulting inputstream 062 * @throws IOException 063 */ 064 public HTTPResponse get(URL url, String username, String password, int timeout, 065 String charset, String useragent, 066 String proxyserver, int proxyport, String proxyuser, 067 String proxypassword, Header[] headers) throws IOException; 068 069 070 public HTTPResponse put(URL url, String username, String password, int timeout, 071 String charset, String useragent, 072 String proxyserver, int proxyport, String proxyuser, 073 String proxypassword, Header[] headers, Object body) throws IOException ; 074 075 public HTTPResponse delete(URL url, String username, String password, int timeout, 076 String charset, String useragent, 077 String proxyserver, int proxyport, String proxyuser, 078 String proxypassword, Header[] headers) throws IOException ; 079 080 public HTTPResponse head(URL url, String username, String password, int timeout, 081 String charset, String useragent, 082 String proxyserver, int proxyport, String proxyuser, 083 String proxypassword, Header[] headers) throws IOException ; 084 085 086 //public RequestEntity toRequestEntity(Object value) throws PageException; 087 088 /** 089 * cast a string to a url 090 * @param strUrl string represent a url 091 * @return url from string 092 * @throws MalformedURLException 093 */ 094 public URL toURL(String strUrl, int port) throws MalformedURLException; // FUTURE deprecated use method <code>toURL(String strUrl, int port, boolean encodeIfNecessary)</code> instead 095 096 // FUTURE public URL toURL(String strUrl, int port, boolean encodeIfNecessary) throws MalformedURLException; 097 098 099 /** 100 * cast a string to a url 101 * @param strUrl string represent a url 102 * @return url from string 103 * @throws MalformedURLException 104 */ 105 public URL toURL(String strUrl) throws MalformedURLException; 106 107 public URI toURI(String strUrl) throws URISyntaxException; 108 109 public URI toURI(String strUrl, int port) throws URISyntaxException; 110 111 /** 112 * translate a string in the URLEncoded Format 113 * @param str String to translate 114 * @param charset charset used for translation 115 * @return encoded String 116 * @throws UnsupportedEncodingException 117 */ 118 public String encode(String str, String charset) throws UnsupportedEncodingException; 119 120 /** 121 * translate a url encoded string to a regular string 122 * @param str encoded string 123 * @param charset charset used 124 * @return raw string 125 * @throws UnsupportedEncodingException 126 */ 127 public String decode(String str, String charset) throws UnsupportedEncodingException; 128}