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;
|
88095d | 2015-09-08 | Henrik Grubbström (Grubba) | | constant HTTP_MISDIRECTED_REQ = 421;
|
9e8057 | 2004-03-02 | Martin Stjernholm | | 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",
|
88095d | 2015-09-08 | Henrik Grubbström (Grubba) | | 421:"421 Misdirected Request",
|
da11cf | 2011-11-05 | Bill Welliver | | 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 | |
|
2b036a | 2019-09-25 | Henrik Grubbström (Grubba) | | mapping(string:string|array(string)) proxy_headers = ([]);
|
14ab9a | 2010-08-31 | Martin Nilsson | |
if( user || password )
{
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | proxy_headers["Proxy-Authorization"] = "Basic "
|
4180e4 | 2018-04-12 | Stefan Gluszek | | + MIME.encode_base64((user || "") + ":" + (password || ""), 1);
|
2b036a | 2019-09-25 | Henrik Grubbström (Grubba) | | }
if (has_value(proxy->host, ":")) {
proxy_headers["host"] = "[" + proxy->host + "]:" + proxy->port;
} else {
proxy_headers["host"] = proxy->host + ":" + proxy->port;
|
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;
|
be0944 | 2017-02-21 | Henrik Grubbström (Grubba) | | url->scheme = proxy->scheme;
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | url->host = proxy->host;
url->port = proxy->port;
query_variables = url->query = 0;
url->path = web_url;
|
2b036a | 2019-09-25 | Henrik Grubbström (Grubba) | |
if (request_headers) {
proxy_headers = request_headers + proxy_headers;
}
|
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;
proxy_headers->connection = "keep-alive";
con = do_method("CONNECT", proxy, 0, proxy_headers);
con->data(0);
|
f75ba4 | 2019-08-07 | Henrik Grubbström (Grubba) | | if (con->status >= 300) {
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | 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;
} 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();
|
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;
|
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__,
|
352471 | 2015-05-26 | Martin Nilsson | | "host" : url->host +
|
14ec7d | 2003-12-04 | Mirar (Pontus Hagland) | | (url->port!=(url->scheme=="https"?443:80)?":"+url->port:"")]);
|
78d9e8 | 2001-04-02 | Johan Sundström | |
|
5728e9 | 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 + ":" +
|
4180e4 | 2018-04-12 | Stefan Gluszek | | (url->password || ""),
1);
|
5728e9 | 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)
|
51f1ce | 2015-09-06 | Martin Nilsson | | error ("I/O error: %s.\n", strerror (con->errno));
|
831212 | 2004-11-30 | Martin Stjernholm | | 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) {
|
f5dc04 | 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");
}
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;
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__,
|
352471 | 2015-05-26 | Martin Nilsson | | "host" : url->host +
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | (url->port!=(url->scheme=="https"?443:80)?":"+url->port:"")]);
|
3b479c | 2015-02-18 | Aleksandra Berjak | | if(url->user || url->password)
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | default_headers->authorization = "Basic "
+ MIME.encode_base64(url->user + ":" +
|
4180e4 | 2018-04-12 | Stefan Gluszek | | (url->password || ""),
1);
|
9924f4 | 2005-08-30 | Henrik Grubbström (Grubba) | | 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="/";
|
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)
{
|
1a1e5b | 2019-08-09 | Henrik Grubbström (Grubba) | | con->set_callbacks(@orig_cb_info);
|
f75ba4 | 2019-08-07 | Henrik Grubbström (Grubba) | | if (con->status >= 300) {
|
1a1e5b | 2019-08-09 | Henrik Grubbström (Grubba) | |
if (con->request_ok) {
con->request_ok(con, @con->extra_args);
}
|
f75ba4 | 2019-08-07 | Henrik Grubbström (Grubba) | | return;
}
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | |
|
9666ec | 2017-02-22 | Henrik Grubbström (Grubba) | |
con->init_async_timeout();
|
201ceb | 2019-09-20 | Henrik Grubbström (Grubba) | |
con->headers["connection"] = "keep-alive";
con->headers["content-length"] = "0";
con->host = url->host;
con->port = url->port;
con->https = 1;
con->start_tls(0);
|
d472e5 | 2011-04-20 | Henrik Grubbström (Grubba) | | con->con->set_nonblocking(0,
lambda() {
|
9666ec | 2017-02-22 | Henrik Grubbström (Grubba) | |
con->remove_async_timeout();
|
d472e5 | 2011-04-20 | Henrik Grubbström (Grubba) | | do_async_method(method, url, query_variables,
request_headers, con, data);
}, con->async_failed);
|
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");
}
|
2b036a | 2019-09-25 | Henrik Grubbström (Grubba) | | mapping(string:string|array(string)) proxy_headers = ([]);
|
8937f3 | 2011-04-20 | Henrik Grubbström (Grubba) | |
if( user || password )
{
proxy_headers["Proxy-Authorization"] = "Basic "
|
4180e4 | 2018-04-12 | Stefan Gluszek | | + MIME.encode_base64((user || "") + ":" + (password || ""), 1);
|
2b036a | 2019-09-25 | Henrik Grubbström (Grubba) | | }
if (has_value(proxy->host, ":")) {
proxy_headers["host"] = "[" + proxy->host + "]:" + proxy->port;
} else {
proxy_headers["host"] = proxy->host + ":" + proxy->port;
|
8937f3 | 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;
|
be0944 | 2017-02-21 | Henrik Grubbström (Grubba) | | url->scheme = proxy->scheme;
|
8937f3 | 2011-04-20 | Henrik Grubbström (Grubba) | | url->host = proxy->host;
url->port = proxy->port;
query_variables = url->query = 0;
url->path = web_url;
|
2b036a | 2019-09-25 | Henrik Grubbström (Grubba) | |
if (request_headers) {
proxy_headers = request_headers + proxy_headers;
}
|
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";
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,
|
2b036a | 2019-09-25 | Henrik Grubbström (Grubba) | | request_headers,
|
0c808b | 2011-04-20 | Henrik Grubbström (Grubba) | | data);
method = "CONNECT";
url = proxy;
data = 0;
} else {
proxy_headers = request_headers;
}
|
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 | |
|
352471 | 2015-05-26 | Martin Nilsson | |
|
9fc89e | 2000-04-15 | Mirar (Pontus Hagland) | |
|
352471 | 2015-05-26 | Martin Nilsson | |
|
956a9d | 2015-05-06 | Chris Angelico | |
|
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) | | {
|
b07dc6 | 2015-12-14 | Per Hedbor | | return map((array)variables,
lambda(array(string|int|array(string)) v)
{
if (intp(v[1]))
return uri_encode(v[0]);
if (arrayp(v[1]))
return map(v[1], lambda (string val) {
return
uri_encode(v[0])+"="+
uri_encode(val);
})*"&";
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)
|
0c4ea5 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
|
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)
|
0c4ea5 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
|
0c4ea5 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
{
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)
|
dc9373 | 2015-08-22 | Martin Nilsson | |
|
0c4ea5 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
|
0c4ea5 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
{
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)
{
|
abbd40 | 2019-07-05 | Martin Nilsson | | s = _Roxen.http_decode_string (s);
catch { s = utf8_to_string (s); };
return s;
|
d905ec | 2008-07-25 | Martin Stjernholm | | }
string iri_encode (string s)
|
dc9373 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
{
constant replace_chars = gen_delims + sub_delims + other_chars;
return replace (s,
sprintf ("%c", ((array(int)) replace_chars)[*]),
sprintf ("%%%02X", ((array(int)) replace_chars)[*]));
}
string quoted_string_encode (string s)
|
0c4ea5 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
|
dc9373 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
{
return replace (s, (["\"": "\\\"", "\\": "\\\\"]));
}
string quoted_string_decode (string s)
|
0c4ea5 | 2015-08-22 | Martin Nilsson | |
|
d905ec | 2008-07-25 | Martin Stjernholm | |
{
return map (s / "\\\\", replace, "\\", "") * "\\";
}
|
233a9e | 2020-05-24 | Stephen R. van den Berg | |
#define ST_KEY 1
#define ST_VALUE 2
#define ST_QUOTEDVALUE 3
#define ST_ESCAPEVALUE 4
array(ADT.OrderedMapping) params_decode (string s)
{
array(mapping(string:string)|ADT.OrderedMapping) totres = ({});
ADT.OrderedMapping mapres = ADT.OrderedMapping();
String.Buffer word = String.Buffer();
int(ST_KEY..ST_ESCAPEVALUE) state = ST_KEY;
string key;
int i;
for (i = 0;; i++) {
int c;
if (i < sizeof(s))
c = s[i];
else if (i == sizeof(s)) {
c = ',';
if (state > ST_VALUE)
state = ST_VALUE;
} else
break;
if (state >= ST_QUOTEDVALUE) {
if (state == ST_ESCAPEVALUE)
state = ST_QUOTEDVALUE;
else
switch (c) {
case '"':
state = ST_VALUE;
continue;
case '\\':
state = ST_ESCAPEVALUE;
continue;
}
word->putchar(c);
} else {
switch (c) {
case '=':
key = word->get();
state = ST_VALUE;
continue;
case '"':
state = ST_QUOTEDVALUE;
continue;
case ',':
case ';':
if (state == ST_KEY) {
if (!sizeof(word))
break;
key = word->get();
}
mapres[key] = state >= ST_VALUE && word->get();
state = ST_KEY;
break;
default:
word->putchar(c);
case ' ': case '\t': case '\n': case '\r': case '\f': case '\v':
continue;
}
if (c == ',' && sizeof(mapres))
totres += ({ mapres }), mapres = ADT.OrderedMapping();
}
}
return totres;
}
Regexp toescape = Regexp("[;,\" \t\n\r\f\v]");
string params_encode (array(mapping(string:string)|ADT.OrderedMapping) params)
{
String.Buffer res = String.Buffer();
string sep = "";
foreach (params; ; mapping(string:string)|ADT.OrderedMapping m) {
foreach (m; string key; string value) {
res->add(sep, key);
if (value)
res->add("=",
toescape->match(value)
? "\"" + quoted_string_encode(value) + "\""
: value);
sep = ";";
}
sep = ",";
}
return res->get();
}
|