a580e1 | 2000-09-27 | Fredrik Hübinette (Hubbe) | | #pike __REAL_VERSION__
|
f4b01a | 1999-04-09 | Mirar (Pontus Hagland) | |
|
9e8057 | 2004-03-02 | Martin Stjernholm | |
constant HTTP_CONTINUE = 100;
constant HTTP_SWITCH_PROT = 101;
constant DAV_PROCESSING = 102;
constant HTTP_OK = 200;
constant HTTP_CREATED = 201;
constant HTTP_ACCEPTED = 202;
constant HTTP_NONAUTHORATIVE = 203;
constant HTTP_NO_CONTENT = 204;
constant HTTP_RESET_CONTENT = 205;
constant HTTP_PARTIAL_CONTENT = 206;
constant DAV_MULTISTATUS = 207;
constant DELTA_HTTP_IM_USED = 226;
constant HTTP_MULTIPLE = 300;
constant HTTP_MOVED_PERM = 301;
constant HTTP_FOUND = 302;
constant HTTP_SEE_OTHER = 303;
constant HTTP_NOT_MODIFIED = 304;
constant HTTP_USE_PROXY = 305;
constant HTTP_TEMP_REDIRECT = 307;
constant HTTP_BAD = 400;
constant HTTP_UNAUTH = 401;
constant HTTP_PAY = 402;
constant HTTP_FORBIDDEN = 403;
constant HTTP_NOT_FOUND = 404;
constant HTTP_METHOD_INVALID = 405;
constant HTTP_NOT_ACCEPTABLE = 406;
constant HTTP_PROXY_AUTH_REQ = 407;
constant HTTP_TIMEOUT = 408;
constant HTTP_CONFLICT = 409;
constant HTTP_GONE = 410;
constant HTTP_LENGTH_REQ = 411;
constant HTTP_PRECOND_FAILED = 412;
constant HTTP_REQ_TOO_LARGE = 413;
constant HTTP_URI_TOO_LONG = 414;
constant HTTP_UNSUPP_MEDIA = 415;
constant HTTP_BAD_RANGE = 416;
constant HTTP_EXPECT_FAILED = 417;
constant HTCPCP_TEAPOT = 418;
constant DAV_UNPROCESSABLE = 422;
constant DAV_LOCKED = 423;
constant DAV_FAILED_DEP = 424;
|
0cc1a5 | 2012-06-12 | Henrik Grubbström (Grubba) | | constant HTTP_LEGALLY_RESTRICTED= 451;
|
9e8057 | 2004-03-02 | Martin Stjernholm | |
constant HTTP_INTERNAL_ERR = 500;
constant HTTP_NOT_IMPL = 501;
constant HTTP_BAD_GW = 502;
constant HTTP_UNAVAIL = 503;
constant HTTP_GW_TIMEOUT = 504;
constant HTTP_UNSUPP_VERSION = 505;
|
72e1f8 | 2004-03-02 | Martin Stjernholm | | constant TCN_VARIANT_NEGOTIATES = 506;
|
9e8057 | 2004-03-02 | Martin Stjernholm | | constant DAV_STORAGE_FULL = 507;
|
da11cf | 2011-11-05 | Bill Welliver | | constant response_codes =
([
100:"100 Continue",
101:"101 Switching Protocols",
102:"102 Processing",
103:"103 Checkpoint",
122:"122 Request-URI too long",
200:"200 OK",
201:"201 Created, URI follows",
202:"202 Accepted",
203:"203 Non-Authoritative Information",
204:"204 No Content",
205:"205 Reset Content",
206:"206 Partial Content",
207:"207 Multi-Status",
226:"226 IM Used",
300:"300 Moved",
301:"301 Permanent Relocation",
302:"302 Found",
303:"303 See Other",
304:"304 Not Modified",
305:"305 Use Proxy",
306:"306 Switch Proxy",
307:"307 Temporary Redirect",
308:"308 Resume Incomplete",
400:"400 Bad Request",
401:"401 Access denied",
402:"402 Payment Required",
403:"403 Forbidden",
404:"404 No such file or directory.",
405:"405 Method not allowed",
406:"406 Not Acceptable",
407:"407 Proxy authorization needed",
408:"408 Request timeout",
409:"409 Conflict",
410:"410 Gone",
411:"411 Length Required",
412:"412 Precondition Failed",
413:"413 Request Entity Too Large",
414:"414 Request-URI Too Large",
415:"415 Unsupported Media Type",
416:"416 Requested range not statisfiable",
417:"417 Expectation Failed",
418:"418 I'm a teapot",
422:"422 Unprocessable Entity",
423:"423 Locked",
424:"424 Failed Dependency",
425:"425 Unordered Collection",
426:"426 Upgrade Required",
|
0cc1a5 | 2012-06-12 | Henrik Grubbström (Grubba) | | 451:"451 Unavailable for Legal Reasons",
|
da11cf | 2011-11-05 | Bill Welliver | |
500:"500 Internal Server Error.",
501:"501 Not Implemented",
502:"502 Bad Gateway",
503:"503 Service unavailable",
504:"504 Gateway Timeout",
505:"505 HTTP Version Not Supported",
506:"506 Variant Also Negotiates",
507:"507 Insufficient Storage",
509:"509 Bandwidth Limit Exceeded",
510:"510 Not Extended",
598:"598 Network read timeout error",
599:"599 Network connect timeout error",
]);
|
14ab9a | 2010-08-31 | Martin Nilsson | |
|
8630e8 | 2011-04-20 | Henrik Grubbström (Grubba) | |
|
14ab9a | 2010-08-31 | Martin Nilsson | | .Query do_proxied_method(string|Standards.URI proxy,
string user, string password,
string method,
string|Standards.URI url,
void|mapping(string:int|string|array(string)) query_variables,
void|mapping(string:string|array(string)) request_headers,
void|Protocols.HTTP.Query con, void|string data)
{
|
fd5f32 | 2011-04-27 | Henrik Grubbström (Grubba) | | if (!proxy || (proxy == "")) {
return do_method(method, url, query_variables, request_headers, con, data);
}
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | |
proxy = Standards.URI(proxy);
url = Standards.URI(url);
|
14ab9a | 2010-08-31 | Martin Nilsson | |
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | mapping(string:string|array(string)) proxy_headers;
|
14ab9a | 2010-08-31 | Martin Nilsson | |
if( user || password )
{
if( !request_headers )
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | proxy_headers = ([]);
else
proxy_headers = request_headers + ([]);
proxy_headers["Proxy-Authorization"] = "Basic "
+ MIME.encode_base64((user || "") + ":" + (password || ""));
|
14ab9a | 2010-08-31 | Martin Nilsson | | }
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | if (url->scheme == "http") {
if( query_variables )
url->set_query_variables( url->get_query_variables() +
query_variables );
string web_url = (string)url;
url->host = proxy->host;
url->port = proxy->port;
query_variables = url->query = 0;
url->path = web_url;
|
5c3202 | 2014-06-01 | Martin Nilsson | | #if constant(SSL.File)
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | } else if (url->scheme == "https") {
#ifdef HTTP_QUERY_DEBUG
werror("Proxied SSL request.\n");
#endif
if (!con || (con->host != url->host) || (con->port != url->port)) {
proxy->path = url->host + ":" + url->port;
if (!proxy_headers) proxy_headers = ([]);
proxy_headers->connection = "keep-alive";
m_delete(proxy_headers, "authorization");
con = do_method("CONNECT", proxy, 0, proxy_headers);
con->data(0);
if (con->status/100 > 2) {
return con;
}
|
3c2f57 | 2011-04-28 | Henrik Grubbström (Grubba) | | con->headers["connection"] = "keep-alive";
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | con->headers["content-length"] = "0";
con->host = url->host;
con->port = url->port;
con->https = 1;
con->start_tls(1);
}
proxy_headers = request_headers;
|
5c3202 | 2014-06-01 | Martin Nilsson | | #endif /* constant(SSL.File) */
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | } else {
error("Can't handle proxying of %O.\n", url->scheme);
}
return do_method(method, url, query_variables, proxy_headers, con, data);
|
14ab9a | 2010-08-31 | Martin Nilsson | | }
|
10b8b1 | 2004-03-08 | Martin Nilsson | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
3032b4 | 2011-03-06 | Henrik Grubbström (Grubba) | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | .Query do_method(string method,
|
b64885 | 2001-01-11 | Johan Schön | | string|Standards.URI url,
|
32f1ba | 2009-01-29 | Martin Nilsson | | void|mapping(string:int|string|array(string)) query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
b64885 | 2001-01-11 | Johan Schön | | void|Protocols.HTTP.Query con, void|string data)
{
if(stringp(url))
url=Standards.URI(url);
|
30dd0d | 2004-09-06 | Martin Nilsson | |
|
6a4fe1 | 2005-01-16 | Martin Nilsson | | if( (< "httpu", "httpmu" >)[url->scheme] ) {
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | return do_udp_method(method, url, query_variables, request_headers,
con, data);
|
6a4fe1 | 2005-01-16 | Martin Nilsson | | }
if(!con)
con = .Query();
|
5c3202 | 2014-06-01 | Martin Nilsson | | #if constant(SSL.File)
|
15c118 | 2001-04-18 | Pär Svensson | | if(url->scheme!="http" && url->scheme!="https")
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | error("Can't handle %O or any other protocols than HTTP or HTTPS.\n",
|
15c118 | 2001-04-18 | Pär Svensson | | url->scheme);
|
30dd0d | 2004-09-06 | Martin Nilsson | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | con->https = (url->scheme=="https")? 1 : 0;
|
15c118 | 2001-04-18 | Pär Svensson | | #else
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | if(url->scheme!="http")
|
f42a70 | 2009-04-25 | Martin Stjernholm | | error("Can't handle %O or any other protocol than HTTP "
"(HTTPS requires Nettle support).\n",
|
b64885 | 2001-01-11 | Johan Schön | | url->scheme);
|
5c3202 | 2014-06-01 | Martin Nilsson | | #endif /* constant(SSL.File) */
|
b64885 | 2001-01-11 | Johan Schön | |
|
85f904 | 2001-01-31 | Johan Sundström | | mapping default_headers = ([
|
6bbe93 | 2003-01-19 | Martin Nilsson | | "user-agent" : "Mozilla/5.0 (compatible; MSIE 6.0; Pike HTTP client)"
" Pike/" + __REAL_MAJOR__ + "." + __REAL_MINOR__ + "." + __REAL_BUILD__,
|
14ec7d | 2003-12-04 | Mirar (Pontus Hagland) | | "host" : url->host +
(url->port!=(url->scheme=="https"?443:80)?":"+url->port:"")]);
|
78d9e8 | 2001-04-02 | Johan Sundström | |
|
72807e | 2013-01-25 | Martin Nilsson | | if(url->user || url->password)
|
85f904 | 2001-01-31 | Johan Sundström | | default_headers->authorization = "Basic "
+ MIME.encode_base64(url->user + ":" +
(url->password || ""));
|
72807e | 2013-01-25 | Martin Nilsson | |
if(!request_headers)
request_headers = default_headers;
else
request_headers = default_headers |
mkmapping(lower_case(indices(request_headers)[*]),
values(request_headers));
|
85f904 | 2001-01-31 | Johan Sundström | |
|
b64885 | 2001-01-11 | Johan Schön | | string query=url->query;
if(query_variables && sizeof(query_variables))
{
if(query)
query+="&"+http_encode_query(query_variables);
else
query=http_encode_query(query_variables);
}
string path=url->path;
if(path=="") path="/";
con->sync_request(url->host,url->port,
method+" "+path+(query?("?"+query):"")+" HTTP/1.0",
|
85f904 | 2001-01-31 | Johan Sundström | | request_headers, data);
|
30dd0d | 2004-09-06 | Martin Nilsson | |
|
831212 | 2004-11-30 | Martin Stjernholm | | if (!con->ok) {
if (con->errno)
error ("I/O error: %s\n", strerror (con->errno));
return 0;
}
|
b64885 | 2001-01-11 | Johan Schön | | return con;
}
|
9eaf1d | 2008-06-28 | Martin Nilsson | | protected .Query do_udp_method(string method, Standards.URI url,
|
32f1ba | 2009-01-29 | Martin Nilsson | | void|mapping(string:int|string|array(string)) query_variables,
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | void|mapping(string:string|array(string))
request_headers, void|Protocols.HTTP.Query con,
void|string data)
|
6a4fe1 | 2005-01-16 | Martin Nilsson | | {
if(!request_headers)
request_headers = ([]);
string path = url->path;
if(path=="") {
if(url->method=="httpmu")
path = "*";
else
path = "/";
}
string msg = method + " " + path + " HTTP/1.1\r\n";
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | |
Stdio.UDP udp = Stdio.UDP();
int port = 10000 + random(1000);
int i;
while(1) {
|
4675a5 | 2013-09-03 | Tobias S. Josefowitz | | if( !catch( udp->bind(port++, 0, 1) ) ) break;
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | if( i++ > 1000 ) error("Could not open a UDP port.\n");
}
if(url->method=="httpmu") {
mapping ifs = Stdio.gethostip();
if(!sizeof(ifs)) error("No Internet interface found.\n");
foreach(ifs; string i; mapping data)
if(sizeof(data->ips)) {
udp->enable_multicast(data->ips[0]);
break;
}
udp->add_membership(url->host, 0, 0);
|
6a4fe1 | 2005-01-16 | Martin Nilsson | | }
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | udp->set_multicast_ttl(4);
|
6a4fe1 | 2005-01-16 | Martin Nilsson | | udp->send(url->host, url->port, msg);
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | if (!con) {
con = .Query();
}
con->con = udp;
return con;
}
|
3032b4 | 2011-03-06 | Henrik Grubbström (Grubba) | |
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | |
void do_async_method(string method,
string|Standards.URI url,
|
32f1ba | 2009-01-29 | Martin Nilsson | | void|mapping(string:int|string|array(string)) query_variables,
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | void|mapping(string:string|array(string)) request_headers,
Protocols.HTTP.Query con, void|string data)
{
if(stringp(url))
url=Standards.URI(url);
if( (< "httpu", "httpmu" >)[url->scheme] ) {
error("Asynchronous httpu or httpmu not yet supported.\n");
}
|
5c3202 | 2014-06-01 | Martin Nilsson | | #if constant(SSL.File)
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | if(url->scheme!="http" && url->scheme!="https")
error("Can't handle %O or any other protocols than HTTP or HTTPS.\n",
url->scheme);
con->https = (url->scheme=="https")? 1 : 0;
#else
if(url->scheme!="http")
error("Can't handle %O or any other protocol than HTTP.\n",
url->scheme);
|
5c3202 | 2014-06-01 | Martin Nilsson | | #endif /* constant(SSL.File) */
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | |
if(!request_headers)
request_headers = ([]);
mapping default_headers = ([
"user-agent" : "Mozilla/5.0 (compatible; MSIE 6.0; Pike HTTP client)"
" Pike/" + __REAL_MAJOR__ + "." + __REAL_MINOR__ + "." + __REAL_BUILD__,
"host" : url->host +
(url->port!=(url->scheme=="https"?443:80)?":"+url->port:"")]);
if(url->user || url->passwd)
default_headers->authorization = "Basic "
+ MIME.encode_base64(url->user + ":" +
(url->password || ""));
request_headers = default_headers | request_headers;
string query=url->query;
if(query_variables && sizeof(query_variables))
{
if(query)
query+="&"+http_encode_query(query_variables);
else
query=http_encode_query(query_variables);
}
string path=url->path;
if(path=="") path="/";
|
5cc3a4 | 2011-04-27 | Henrik Grubbström (Grubba) | | if (!con->headers ||
lower_case(con->headers["connection"]||"close") == "close") {
con->data_timeout = 120;
con->timeout = 120;
con->con = 0;
}
|
b907ad | 2005-12-29 | Henrik Grubbström (Grubba) | |
|
94dfb1 | 2005-12-29 | Henrik Grubbström (Grubba) | | con->async_request(url->host, url->port,
method+" "+path+(query?("?"+query):"")+" HTTP/1.0",
request_headers, data);
|
6a4fe1 | 2005-01-16 | Martin Nilsson | | }
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | protected void https_proxy_connect_fail(Protocols.HTTP.Query con,
array(mixed) orig_cb_info,
Standards.URI url, string method,
mapping(string:string) query_variables,
mapping(string:string) request_headers,
string data)
{
con->set_callbacks(@orig_cb_info);
con->request_fail(con, @con->extra_args);
}
protected void https_proxy_connect_ok(Protocols.HTTP.Query con,
array(mixed) orig_cb_info,
Standards.URI url, string method,
mapping(string:string) query_variables,
mapping(string:string) request_headers,
string data)
{
con->set_callbacks(@orig_cb_info);
|
d472e5 | 2011-04-20 | Henrik Grubbström (Grubba) | | con->con->set_nonblocking(0,
lambda() {
do_async_method(method, url, query_variables,
request_headers, con, data);
}, con->async_failed);
|
26a378 | 2011-04-27 | Henrik Grubbström (Grubba) | | con->headers["connection"] = "keep-alive";
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | con->headers["content-length"] = "0";
con->host = url->host;
con->port = url->port;
con->https = 1;
|
d472e5 | 2011-04-20 | Henrik Grubbström (Grubba) | | con->start_tls(0);
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | }
|
8937f3 | 2011-04-20 | Henrik Grubbström (Grubba) | |
void do_async_proxied_method(string|Standards.URI proxy,
string user, string password,
string method,
string|Standards.URI url,
void|mapping(string:int|string|array(string)) query_variables,
void|mapping(string:string|array(string)) request_headers,
Protocols.HTTP.Query con, void|string data)
{
|
fd5f32 | 2011-04-27 | Henrik Grubbström (Grubba) | | if (!proxy || (proxy == "")) {
do_async_method(method, url, query_variables, request_headers, con, data);
return;
}
|
8937f3 | 2011-04-20 | Henrik Grubbström (Grubba) | |
proxy = Standards.URI(proxy);
url = Standards.URI(url);
if( (< "httpu", "httpmu" >)[url->scheme] ) {
error("Asynchronous httpu or httpmu not yet supported.\n");
}
mapping(string:string|array(string)) proxy_headers;
if( user || password )
{
if( !request_headers )
proxy_headers = ([]);
else
proxy_headers = request_headers + ([]);
proxy_headers["Proxy-Authorization"] = "Basic "
+ MIME.encode_base64((user || "") + ":" + (password || ""));
}
if (url->scheme == "http") {
if( query_variables )
url->set_query_variables( url->get_query_variables() +
query_variables );
string web_url = (string)url;
url->host = proxy->host;
url->port = proxy->port;
query_variables = url->query = 0;
url->path = web_url;
|
5c3202 | 2014-06-01 | Martin Nilsson | | #if constant(SSL.File)
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | } else if(url->scheme == "https") {
#ifdef HTTP_QUERY_DEBUG
werror("Proxied SSL request.\n");
#endif
if (!con || (con->host != url->host) || (con->port != url->port)) {
proxy->path = url->host + ":" + url->port;
if (!proxy_headers) proxy_headers = ([]);
proxy_headers->connection = "keep-alive";
m_delete(proxy_headers, "authorization");
array(mixed) orig_cb_info = ({
con->request_ok,
con->request_fail,
@con->extra_args,
});
con->set_callbacks(https_proxy_connect_ok,
https_proxy_connect_fail,
orig_cb_info,
url, method,
query_variables,
request_headers && request_headers + ([]),
data);
method = "CONNECT";
url = proxy;
data = 0;
} else {
proxy_headers = request_headers;
}
#endif
|
8937f3 | 2011-04-20 | Henrik Grubbström (Grubba) | | } else {
error("Can't handle proxying of %O.\n", url->scheme);
}
do_async_method(method, url, query_variables, proxy_headers, con, data);
}
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
7dc316 | 2001-04-27 | Henrik Grubbström (Grubba) | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | .Query get_url(string|Standards.URI url,
|
32f1ba | 2009-01-29 | Martin Nilsson | | void|mapping(string:int|string|array(string)) query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
fdfa09 | 2000-11-26 | Johan Sundström | | void|Protocols.HTTP.Query con)
|
f4b01a | 1999-04-09 | Mirar (Pontus Hagland) | | {
|
b64885 | 2001-01-11 | Johan Schön | | return do_method("GET", url, query_variables, request_headers, con);
|
f4b01a | 1999-04-09 | Mirar (Pontus Hagland) | | }
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
7dc316 | 2001-04-27 | Henrik Grubbström (Grubba) | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | .Query put_url(string|Standards.URI url,
|
3f3b4e | 2000-08-04 | Johan Sundström | | void|string file,
|
32f1ba | 2009-01-29 | Martin Nilsson | | void|mapping(string:int|string|array(string)) query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
fdfa09 | 2000-11-26 | Johan Sundström | | void|Protocols.HTTP.Query con)
|
2ba20a | 2000-02-24 | Fredrik Noring | | {
|
4ff48d | 2002-11-08 | Anders Johansson | | return do_method("PUT", url, query_variables, request_headers, con, file);
|
2ba20a | 2000-02-24 | Fredrik Noring | | }
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
7dc316 | 2001-04-27 | Henrik Grubbström (Grubba) | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | .Query delete_url(string|Standards.URI url,
|
32f1ba | 2009-01-29 | Martin Nilsson | | void|mapping(string:int|string|array(string)) query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
fdfa09 | 2000-11-26 | Johan Sundström | | void|Protocols.HTTP.Query con)
|
2ba20a | 2000-02-24 | Fredrik Noring | | {
|
b64885 | 2001-01-11 | Johan Schön | | return do_method("DELETE", url, query_variables, request_headers, con);
|
2ba20a | 2000-02-24 | Fredrik Noring | | }
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
7dc316 | 2001-04-27 | Henrik Grubbström (Grubba) | |
|
b64885 | 2001-01-11 | Johan Schön | | array(string) get_url_nice(string|Standards.URI url,
|
32f1ba | 2009-01-29 | Martin Nilsson | | void|mapping(string:int|string|array(string)) query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
fdfa09 | 2000-11-26 | Johan Sundström | | void|Protocols.HTTP.Query con)
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | {
|
9eb487 | 2003-11-25 | Martin Nilsson | | .Query c;
multiset seen = (<>);
do {
if(!url) return 0;
if(seen[url] || sizeof(seen)>1000) return 0;
seen[url]=1;
c = get_url(url, query_variables, request_headers, con);
if(!c) return 0;
|
c72a29 | 2012-05-17 | Martin Nilsson | | if(c->status==302)
url = Standards.URI(c->headers->location, url);
|
9eb487 | 2003-11-25 | Martin Nilsson | | } while( c->status!=200 );
return ({ c->headers["content-type"], c->data() });
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | }
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
b64885 | 2001-01-11 | Johan Schön | | string get_url_data(string|Standards.URI url,
|
32f1ba | 2009-01-29 | Martin Nilsson | | void|mapping(string:int|string|array(string)) query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
fdfa09 | 2000-11-26 | Johan Sundström | | void|Protocols.HTTP.Query con)
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | {
|
9eb487 | 2003-11-25 | Martin Nilsson | | array(string) z = get_url_nice(url, query_variables, request_headers, con);
return z && z[1];
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | }
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
d175f6 | 2010-03-07 | Stephen R. van den Berg | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | .Query post_url(string|Standards.URI url,
|
d175f6 | 2010-03-07 | Stephen R. van den Berg | | mapping(string:int|string|array(string))|string query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
fdfa09 | 2000-11-26 | Johan Sundström | | void|Protocols.HTTP.Query con)
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | {
|
d175f6 | 2010-03-07 | Stephen R. van den Berg | | return do_method("POST", url, 0, stringp(query_variables) ? request_headers
: (request_headers||([]))|
|
b64885 | 2001-01-11 | Johan Schön | | (["content-type":
"application/x-www-form-urlencoded"]),
con,
|
d175f6 | 2010-03-07 | Stephen R. van den Berg | | stringp(query_variables) ? query_variables
: http_encode_query(query_variables));
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | }
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
b64885 | 2001-01-11 | Johan Schön | | array(string) post_url_nice(string|Standards.URI url,
|
d175f6 | 2010-03-07 | Stephen R. van den Berg | | mapping(string:int|string|array(string))|string query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
fdfa09 | 2000-11-26 | Johan Sundström | | void|Protocols.HTTP.Query con)
|
f4b01a | 1999-04-09 | Mirar (Pontus Hagland) | | {
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | .Query c = post_url(url, query_variables, request_headers, con);
|
fdfa09 | 2000-11-26 | Johan Sundström | | return c && ({ c->headers["content-type"], c->data() });
|
f4b01a | 1999-04-09 | Mirar (Pontus Hagland) | | }
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | |
|
f1b2f3 | 2004-03-31 | Martin Nilsson | |
|
b64885 | 2001-01-11 | Johan Schön | | string post_url_data(string|Standards.URI url,
|
d175f6 | 2010-03-07 | Stephen R. van den Berg | | mapping(string:int|string|array(string))|string query_variables,
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | void|mapping(string:string|array(string)) request_headers,
|
fdfa09 | 2000-11-26 | Johan Sundström | | void|Protocols.HTTP.Query con)
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | {
|
f1b2f3 | 2004-03-31 | Martin Nilsson | | .Query z = post_url(url, query_variables, request_headers, con);
|
fdfa09 | 2000-11-26 | Johan Sundström | | return z && z->data();
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | }
|
9fc89e | 2000-04-15 | Mirar (Pontus Hagland) | |
|
d0d3ec | 2001-07-17 | Martin Nilsson | |
|
7dc316 | 2001-04-27 | Henrik Grubbström (Grubba) | |
|
9fc89e | 2000-04-15 | Mirar (Pontus Hagland) | |
|
7dc316 | 2001-04-27 | Henrik Grubbström (Grubba) | |
|
9fc89e | 2000-04-15 | Mirar (Pontus Hagland) | |
|
7dc316 | 2001-04-27 | Henrik Grubbström (Grubba) | |
|
d905ec | 2008-07-25 | Martin Stjernholm | | string http_encode_query(mapping(string:int|string|array(string)) variables)
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | {
|
9fc89e | 2000-04-15 | Mirar (Pontus Hagland) | | return Array.map((array)variables,
|
06ba32 | 2001-11-12 | Anders Johansson | | lambda(array(string|int|array(string)) v)
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | {
|
9fc89e | 2000-04-15 | Mirar (Pontus Hagland) | | if (intp(v[1]))
|
d905ec | 2008-07-25 | Martin Stjernholm | | return uri_encode(v[0]);
|
06ba32 | 2001-11-12 | Anders Johansson | | if (arrayp(v[1]))
return map(v[1], lambda (string val) {
return
|
d905ec | 2008-07-25 | Martin Stjernholm | | uri_encode(v[0])+"="+
uri_encode(val);
|
06ba32 | 2001-11-12 | Anders Johansson | | })*"&";
|
d905ec | 2008-07-25 | Martin Stjernholm | | return uri_encode(v[0])+"="+ uri_encode(v[1]);
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | })*"&";
}
|
d905ec | 2008-07-25 | Martin Stjernholm | | protected local constant gen_delims = ":/?#[]@"
"%";
protected local constant sub_delims = "!$&'()*+,;=";
protected local constant other_chars =
(string) enumerate (0x20) + "\x7f"
" \"<>\\^`{|}";
protected local constant eight_bit_chars = (string) enumerate (0x80, 1, 0x80);
string percent_encode (string s)
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | {
|
d905ec | 2008-07-25 | Martin Stjernholm | | constant replace_chars = (gen_delims + sub_delims +
other_chars + eight_bit_chars);
return replace (s,
sprintf ("%c", ((array(int)) replace_chars)[*]),
sprintf ("%%%02X", ((array(int)) replace_chars)[*]));
}
string percent_decode (string s)
{
return _Roxen.http_decode_string (s);
}
string uri_encode (string s)
{
return percent_encode (string_to_utf8 (s));
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | }
|
d905ec | 2008-07-25 | Martin Stjernholm | | string uri_encode_invalids (string s)
{
constant replace_chars = other_chars + eight_bit_chars;
return replace (string_to_utf8 (s),
sprintf ("%c", ((array(int)) replace_chars)[*]),
sprintf ("%%%02X", ((array(int)) replace_chars)[*]));
}
string uri_decode (string s)
{
return utf8_to_string (_Roxen.http_decode_string (s));
}
string iri_encode (string s)
{
constant replace_chars = gen_delims + sub_delims + other_chars;
return replace (s,
sprintf ("%c", ((array(int)) replace_chars)[*]),
sprintf ("%%%02X", ((array(int)) replace_chars)[*]));
}
#if 0
string uri_normalize (string s)
{
}
string iri_normalize (string s)
{
}
#endif
string quoted_string_encode (string s)
{
return replace (s, (["\"": "\\\"", "\\": "\\\\"]));
}
string quoted_string_decode (string s)
{
return map (s / "\\\\", replace, "\\", "") * "\\";
}
__deprecated__ string http_encode_string(string in)
{
return uri_encode (in);
}
__deprecated__ string http_encode_cookie(string f)
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | {
return replace(
|
30dd0d | 2004-09-06 | Martin Nilsson | | f,
({ "\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
"\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017",
"\020", "\021", "\022", "\023", "\024", "\025", "\026", "\027",
"\030", "\031", "\032", "\033", "\034", "\035", "\036", "\037",
|
13bf15 | 2003-12-04 | Mirar (Pontus Hagland) | | "\177",
|
30dd0d | 2004-09-06 | Martin Nilsson | | "\200", "\201", "\202", "\203", "\204", "\205", "\206", "\207",
"\210", "\211", "\212", "\213", "\214", "\215", "\216", "\217",
"\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227",
"\230", "\231", "\232", "\233", "\234", "\235", "\236", "\237",
|
d21f9d | 2002-12-05 | Xavier Beaudouin | | " ", "%", "'", "\"", ",", ";", "=", ":" }),
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | ({
|
30dd0d | 2004-09-06 | Martin Nilsson | | "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
"%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
"%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
"%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",
|
13bf15 | 2003-12-04 | Mirar (Pontus Hagland) | | "%7f",
|
30dd0d | 2004-09-06 | Martin Nilsson | | "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
"%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
"%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
"%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f",
|
d21f9d | 2002-12-05 | Xavier Beaudouin | | "%20", "%25", "%27", "%22", "%2c", "%3b", "%3d", "%3a" }));
|
9a4675 | 1999-05-29 | Mirar (Pontus Hagland) | | }
|
30dd0d | 2004-09-06 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | | __deprecated__ string unentity(string s)
|
30dd0d | 2004-09-06 | Martin Nilsson | | {
return master()->resolv("Parser.parse_html_entities")(s,1);
}
|