e3bda3 | 2000-01-12 | Martin Nilsson | |
|
199d03 | 1999-09-05 | Francesco Chemolli | |
|
f41b98 | 2009-05-07 | Martin Stjernholm | |
|
6a409d | 1999-12-27 | Martin Nilsson | |
|
b24351 | 2010-10-18 | Martin Jonsson | | constant cvs_version = "$Id: http.pike,v 1.628 2010/10/18 07:42:38 marty Exp $";
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
86e77d | 1998-05-07 | Per Hedbor | | #define MAGIC_ERROR
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | #define REQUESTID this
|
86e77d | 1998-05-07 | Per Hedbor | | #ifdef MAGIC_ERROR
inherit "highlight_pike";
#endif
|
6a409d | 1999-12-27 | Martin Nilsson | |
|
2a2a5b | 1996-12-01 | Per Hedbor | |
|
1e6cb6 | 2008-11-05 | Martin Stjernholm | | #include <roxen.h>
|
9c1900 | 2001-02-27 | Per Hedbor | | #define TIMER_PREFIX "http:"
#include <timers.h>
|
26f44e | 2000-08-13 | Per Hedbor | |
|
3f6e4b | 2002-02-06 | Martin Stjernholm | | inherit RequestID;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | #ifdef PROFILE
|
c5e096 | 1999-10-04 | Per Hedbor | | #define HRTIME() gethrtime()
|
8afc81 | 1998-02-04 | Per Hedbor | | int req_time = HRTIME();
|
ebb1c5 | 1998-02-24 | Per Hedbor | | #endif
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | #ifdef REQUEST_DEBUG
|
41b77c | 1999-07-15 | David Hedbor | | int footime, bartime;
|
39202e | 2003-11-03 | Martin Stjernholm | | #define REQUEST_WERR(X) do {bartime = gethrtime()-footime; werror("%s (%d)\n", (X), bartime);footime=gethrtime();} while (0)
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | #else
|
39202e | 2003-11-03 | Martin Stjernholm | | #define REQUEST_WERR(X) do {} while (0)
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | #endif
|
323569 | 1998-03-26 | Per Hedbor | | #ifdef FD_DEBUG
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | | #ifdef REQUEST_DEBUG
#define FD_WERR(X) REQUEST_WERR(X)
#else
#define FD_WERR(X) werror("%s\n", (X))
#endif
|
39202e | 2003-11-03 | Martin Stjernholm | | #define MARK_FD(X) do { \
|
1139a1 | 2006-10-13 | Martin Stjernholm | | int _fd = -1; \
if (my_fd->query_fd) \
_fd = my_fd->query_fd(); \
if (my_fd->query_stream) \
if (object stream = my_fd->query_stream()) /* SSL */ \
if (stream->query_fd) \
_fd = stream->query_fd(); \
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | | FD_WERR("FD " + (_fd == -1 ? sprintf ("%O", my_fd) : _fd) + ": " + (X)); \
|
39202e | 2003-11-03 | Martin Stjernholm | | mark_fd(_fd, (X)+" "+remoteaddr); \
} while (0)
|
323569 | 1998-03-26 | Per Hedbor | | #else
|
39202e | 2003-11-03 | Martin Stjernholm | | #define MARK_FD(X) do {} while (0)
|
323569 | 1998-03-26 | Per Hedbor | | #endif
|
1139a1 | 2006-10-13 | Martin Stjernholm | | #ifdef CONNECTION_DEBUG
private string debug_fd_str;
private string debug_my_fd()
{
if (my_fd->query_fd)
return debug_fd_str = (string) my_fd->query_fd();
if (my_fd->query_stream)
if (object stream = my_fd->query_stream())
if (stream->query_fd)
return debug_fd_str = (string) stream->query_fd();
return debug_fd_str = sprintf ("%O", my_fd);
}
#define DEBUG_GET_FD \
(my_fd ? debug_fd_str || debug_my_fd() : \
debug_fd_str ? "ex " + debug_fd_str : "??")
#endif
|
bdd308 | 2000-05-14 | Francesco Chemolli | | #ifdef THROTTLING_DEBUG
#undef THROTTLING_DEBUG
#define THROTTLING_DEBUG(X) werror("Throttling: "+X+"\n")
#else
#define THROTTLING_DEBUG(X)
#endif
|
f49bd3 | 2000-01-20 | Martin Nilsson | | constant decode = MIME.decode_base64;
|
338ffa | 2000-02-15 | Martin Nilsson | | constant find_supports_and_vars = roxen.find_supports_and_vars;
|
f49bd3 | 2000-01-20 | Martin Nilsson | | constant version = roxen.version;
constant _query = roxen.query;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | private array(string) cache;
private int wanted_data, have_data;
private object(String.Buffer) data_buffer;
|
7ee565 | 1996-12-10 | Per Hedbor | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | private multiset(string) none_match;
|
29abe6 | 2004-04-13 | Henrik Grubbström (Grubba) | |
|
766c71 | 2003-02-03 | Henrik Grubbström (Grubba) | | int kept_alive;
|
5cf99d | 2005-11-18 | Henrik Grubbström (Grubba) | | #if defined(DEBUG) && defined(THREADS)
|
39202e | 2003-11-03 | Martin Stjernholm | | #define CHECK_FD_SAFE_USE do { \
|
4a9840 | 2004-08-18 | Martin Stjernholm | | if (this_thread() != roxen->backend_thread && \
|
39202e | 2003-11-03 | Martin Stjernholm | | (my_fd->query_read_callback() || my_fd->query_write_callback() || \
my_fd->query_close_callback() || \
!zero_type (find_call_out (do_timeout)))) \
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | | error ("Got callbacks but not called from backend thread.\n" \
|
5cf99d | 2005-11-18 | Henrik Grubbström (Grubba) | | "backend_thread:%O\n" \
"this thread:%O\n" \
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | | "rcb:%O\n" \
"wcb:%O\n" \
"ccb:%O\n" \
"timeout:%O\n", \
|
5cf99d | 2005-11-18 | Henrik Grubbström (Grubba) | | roxen->backend_thread, this_thread(), \
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | | my_fd->query_read_callback(), \
my_fd->query_write_callback(), \
my_fd->query_close_callback(), \
find_call_out (do_timeout)); \
|
39202e | 2003-11-03 | Martin Stjernholm | | } while (0)
#else
#define CHECK_FD_SAFE_USE do {} while (0)
#endif
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <roxen.h>
#include <module.h>
|
773ac6 | 2001-03-20 | Martin Stjernholm | | #include <request_trace.h>
|
ae7900 | 2008-11-05 | Martin Stjernholm | | #define MY_TRACE_ENTER(MSG) ID_TRACE_ENTER (this, (MSG), 0)
#define MY_TRACE_LEAVE(MSG) ID_TRACE_LEAVE (this, (MSG))
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
d5cf25 | 2002-12-11 | Anders Johansson | | mapping(string:array) real_variables = ([]);
|
5aca9b | 2001-09-28 | Martin Stjernholm | | mapping(string:mixed)|FakedVariables variables = FakedVariables( real_variables );
|
2fdf09 | 2000-12-02 | Per Hedbor | |
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | mapping (string:mixed) misc =
([
#ifdef REQUEST_DEBUG
"trace_enter":lambda(mixed ...args) {
|
52e082 | 2000-03-07 | Henrik Grubbström (Grubba) | | REQUEST_WERR(sprintf("TRACE_ENTER(%{%O,%})", args));
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | },
"trace_leave":lambda(mixed ...args) {
|
52e082 | 2000-03-07 | Henrik Grubbström (Grubba) | | REQUEST_WERR(sprintf("TRACE_LEAVE(%{%O,%})", args));
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | }
|
338ffa | 2000-02-15 | Martin Nilsson | | #endif // REQUEST_DEBUG
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | ]);
|
99e65a | 2003-06-18 | Tomas Nilsson | | mapping (string:mixed) connection_misc = ([ ]);
|
8200cd | 1998-07-14 | Henrik Grubbström (Grubba) | | mapping (string:string) request_headers = ([ ]);
|
f49bd3 | 2000-01-20 | Martin Nilsson | | mapping (string:string) client_var = ([ ]);
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
06d533 | 1998-04-03 | Per Hedbor | | multiset (string) prestate = (< >);
multiset (string) config = (< >);
|
ebb1c5 | 1998-02-24 | Per Hedbor | | multiset (string) pragma = (< >);
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
beaca0 | 1998-02-20 | Per Hedbor | | mapping file;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
string rest_query="";
|
26b0b9 | 2001-10-02 | Per Hedbor | | string raw="";
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | int raw_bytes = 0;
|
60a1a1 | 1998-08-03 | Henrik Grubbström (Grubba) | | string extra_extension = "";
|
cf4a90 | 2001-01-19 | Per Hedbor | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mapping connection_stats = ([]);
|
b611c6 | 2002-03-27 | Per Hedbor | |
|
cf4a90 | 2001-01-19 | Per Hedbor | | class AuthEmulator
{
mixed `[]( int i )
{
User u;
switch( i )
{
case 0:
return conf->authenticate( this_object() );
case 1:
if( u = conf->authenticate( this_object() ) )
return u->name();
if( realauth )
return (realauth/":")[0];
case 2:
if( u = conf->authenticate( this_object() ) )
return 0;
if( realauth )
return ((realauth/":")[1..])*":";
}
}
int `!( )
{
return !realauth;
}
}
|
9689f1 | 2002-09-03 | Martin Stjernholm | | array|AuthEmulator auth;
|
0b0d08 | 2000-02-14 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
199d03 | 1999-09-05 | Francesco Chemolli | | object pipe;
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
ba88df | 1999-09-29 | Francesco Chemolli | |
|
d5cf25 | 2002-12-11 | Anders Johansson | | mapping (string:mixed) throttle=([]);
|
ba88df | 1999-09-29 | Francesco Chemolli | |
|
199d03 | 1999-09-05 | Francesco Chemolli | | object throttler;
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
199d03 | 1999-09-05 | Francesco Chemolli | |
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
199d03 | 1999-09-05 | Francesco Chemolli | |
|
e5bad2 | 1998-02-10 | Per Hedbor | | private void setup_pipe()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
199d03 | 1999-09-05 | Francesco Chemolli | | if(!my_fd) {
|
184261 | 1997-05-30 | Henrik Grubbström (Grubba) | | end();
return;
}
|
5f6dae | 2000-08-13 | Per Hedbor | | if ( throttle->doit && conf->query("req_throttle") )
throttle->doit = 0;
if( throttle->doit || conf->throttler )
pipe=roxen.slowpipe();
else
pipe=roxen.fastpipe();
if (throttle->doit)
{
throttle->rate=max(throttle->rate, conf->query("req_throttle_min"));
|
ba88df | 1999-09-29 | Francesco Chemolli | | pipe->throttle(throttle->rate,
(int)(throttle->rate*conf->query("req_throttle_depth_mult")),
0);
|
bdd308 | 2000-05-14 | Francesco Chemolli | | THROTTLING_DEBUG("throtting request at "+throttle->rate);
|
199d03 | 1999-09-05 | Francesco Chemolli | | }
|
b611c6 | 2002-03-27 | Per Hedbor | | if( pipe->set_status_mapping )
pipe->set_status_mapping( connection_stats );
|
5f6dae | 2000-08-13 | Per Hedbor | | if ( conf->throttler )
|
b611c6 | 2002-03-27 | Per Hedbor | | pipe->assign_throttler( conf->throttler );
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
199d03 | 1999-09-05 | Francesco Chemolli | |
|
47a940 | 2008-05-09 | Martin Stjernholm | | void send(string|object what, int|void len,
#ifdef CONNECTION_DEBUG
void|int connection_debug_verbose
#endif
)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
66d845 | 2002-03-20 | Per Hedbor | | if( len>0 && port_obj && port_obj->minimum_byterate )
|
dc6fe1 | 2001-08-20 | Per Hedbor | | call_out( end, len / port_obj->minimum_byterate );
|
9c1900 | 2001-02-27 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!what) return;
|
e5bad2 | 1998-02-10 | Per Hedbor | | if(!pipe) setup_pipe();
|
1139a1 | 2006-10-13 | Martin Stjernholm | | if(stringp(what)) {
|
acd724 | 2004-04-27 | Martin Stjernholm | | #ifdef CONNECTION_DEBUG
|
47a940 | 2008-05-09 | Martin Stjernholm | | if (connection_debug_verbose
|
1e6cb6 | 2008-11-05 | Martin Stjernholm | | #if TOSTR(CONNECTION_DEBUG) != "1"
|
47a940 | 2008-05-09 | Martin Stjernholm | |
|
1e6cb6 | 2008-11-05 | Martin Stjernholm | | || has_prefix(file->type || "", TOSTR(CONNECTION_DEBUG))
|
47a940 | 2008-05-09 | Martin Stjernholm | | #endif
)
werror ("HTTP[%s]: Response (length %d) ===============================\n"
|
7a1424 | 2009-01-07 | Martin Stjernholm | | "%O\n", DEBUG_GET_FD, sizeof (what), what);
|
47a940 | 2008-05-09 | Martin Stjernholm | | else
|
1139a1 | 2006-10-13 | Martin Stjernholm | | werror ("HTTP[%s]: Response =============================================\n"
|
47a940 | 2008-05-09 | Martin Stjernholm | | "String, length %d\n", DEBUG_GET_FD, sizeof (what));
|
acd724 | 2004-04-27 | Martin Stjernholm | | #else
|
f136c2 | 2002-02-26 | Martin Stjernholm | | REQUEST_WERR(sprintf("HTTP: Pipe string %O", what));
|
acd724 | 2004-04-27 | Martin Stjernholm | | #endif
|
f136c2 | 2002-02-26 | Martin Stjernholm | | pipe->write(what);
}
else {
|
acd724 | 2004-04-27 | Martin Stjernholm | | #ifdef CONNECTION_DEBUG
|
1139a1 | 2006-10-13 | Martin Stjernholm | | werror ("HTTP[%s]: Response =============================================\n"
"Stream %O, length %O\n", DEBUG_GET_FD, what, len);
|
acd724 | 2004-04-27 | Martin Stjernholm | | #else
|
f136c2 | 2002-02-26 | Martin Stjernholm | | REQUEST_WERR(sprintf("HTTP: Pipe stream %O, length %O", what, len));
|
acd724 | 2004-04-27 | Martin Stjernholm | | #endif
|
f136c2 | 2002-02-26 | Martin Stjernholm | | pipe->input(what,len);
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | int(0..1) my_fd_busy;
int(0..1) pipe_pending;
|
5f6dae | 2000-08-13 | Per Hedbor | | void start_sender( )
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | {
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | if (my_fd_busy) {
pipe_pending = 1;
|
1139a1 | 2006-10-13 | Martin Stjernholm | | REQUEST_WERR ("HTTP: Pipe pending.\n");
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | return;
}
|
5f6dae | 2000-08-13 | Per Hedbor | | if (pipe)
{
|
f136c2 | 2002-02-26 | Martin Stjernholm | | MARK_FD("HTTP really handled, piping response");
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | #ifdef FD_DEBUG
|
e2df6a | 2001-01-03 | Per Hedbor | | call_out(timer, 30, predef::time(1));
|
e29ec5 | 2004-08-17 | Henrik Grubbström (Grubba) | | pipe->set_done_callback(lambda (int fsent) {
remove_call_out(timer);
do_log(fsent);
} );
#else
|
5f6dae | 2000-08-13 | Per Hedbor | | pipe->set_done_callback( do_log );
|
e29ec5 | 2004-08-17 | Henrik Grubbström (Grubba) | | #endif
|
5f6dae | 2000-08-13 | Per Hedbor | | pipe->output( my_fd );
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | } else {
MARK_FD("HTTP really handled, pipe done");
|
5f6dae | 2000-08-13 | Per Hedbor | | do_log();
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | }
}
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | void my_fd_released()
{
my_fd_busy = 0;
|
1139a1 | 2006-10-13 | Martin Stjernholm | | REQUEST_WERR ("HTTP: Fd released.\n");
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | if (pipe_pending) {
start_sender();
}
}
|
3e2c34 | 2001-01-11 | Per Hedbor | | #ifdef OLD_RXML_CONFIG
private void really_set_config(array mod_config)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
3e2c34 | 2001-01-11 | Per Hedbor | | string url;
if(sscanf(replace(raw_url,({"%3c","%3e","%3C","%3E" }),
({"<",">","<",">"})),"/<%*s>/%s",url)!=2)
url = "/";
|
e3bda3 | 2000-01-12 | Martin Nilsson | | else
|
3e2c34 | 2001-01-11 | Per Hedbor | | url = "/"+url;
|
e3bda3 | 2000-01-12 | Martin Nilsson | |
|
3e2c34 | 2001-01-11 | Per Hedbor | | multiset do_mod_config( multiset config )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
3e2c34 | 2001-01-11 | Per Hedbor | | if(!mod_config) return config;
foreach(mod_config, string m)
if(m[0]=='-')
config[m[1..]]=0;
else
config[m]=1;
return config;
};
|
0ddff6 | 1997-07-20 | Henrik Grubbström (Grubba) | |
|
3e2c34 | 2001-01-11 | Per Hedbor | | void do_send_reply( string what, string url ) {
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | |
|
39202e | 2003-11-03 | Martin Stjernholm | | CHECK_FD_SAFE_USE;
|
fce66d | 2001-08-13 | Martin Stjernholm | | url = url_base() + url[1..];
|
96cf67 | 2009-01-15 | Martin Stjernholm | | string res = prot + " 302 Roxen config coming up\r\n"+
(what?what+"\r\n":"")+"Location: "+url+"\r\n"
"Connection: close\r\nDate: "+
Roxen.http_date(predef::time(1))+
"\r\nContent-Type: text/html\r\n"
"Content-Length: 1\r\n\r\nx";
#ifdef CONNECTION_DEBUG
werror ("HTTP[%s]: Blocking response (length %d) ========================\n"
"%O\n", DEBUG_GET_FD, sizeof (res), res);
#else
REQUEST_WERR(sprintf("HTTP: Send blocking %O", res));
#endif
|
dcc895 | 2001-10-09 | Marcus Wellhardh | | my_fd->set_blocking();
|
96cf67 | 2009-01-15 | Martin Stjernholm | | my_fd->write (res);
|
3e2c34 | 2001-01-11 | Per Hedbor | | my_fd->close();
my_fd = 0;
end();
};
|
0ddff6 | 1997-07-20 | Henrik Grubbström (Grubba) | |
|
3e2c34 | 2001-01-11 | Per Hedbor | | if(supports->cookies)
{
do_send_reply("Set-Cookie: "+
Roxen.http_roxen_config_cookie(indices(do_mod_config(config))*","),
url );
return;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
3e2c34 | 2001-01-11 | Per Hedbor | | if (sscanf(replace(url, ({ "%28", "%29" }), ({ "(", ")" })),
"/(%*s)/%s", url) == 2)
url = "/" + url;
do_send_reply(0,Roxen.add_pre_state( url, do_mod_config( prestate ) ));
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
a3ebea | 2000-08-12 | Per Hedbor | | #endif
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
edc50f | 2005-12-07 | Henrik Grubbström (Grubba) | | #if 0
|
ad3d95 | 2004-12-01 | Stefan Wallström | |
|
55533a | 2002-03-22 | Ian Delahorne | |
|
ad3d95 | 2004-12-01 | Stefan Wallström | |
|
55533a | 2002-03-22 | Ian Delahorne | |
|
edc50f | 2005-12-07 | Henrik Grubbström (Grubba) | |
|
970cc9 | 2006-04-20 | Henrik Grubbström (Grubba) | |
|
edc50f | 2005-12-07 | Henrik Grubbström (Grubba) | |
|
ad3d95 | 2004-12-01 | Stefan Wallström | | mapping(string:string) parse_cookies( array|string contents )
|
55533a | 2002-03-22 | Ian Delahorne | | {
if(!contents)
return cookies;
|
ad3d95 | 2004-12-01 | Stefan Wallström | |
array tmp = arrayp(contents) ? contents : ({ contents});
foreach(tmp, string cookieheader) {
foreach(((cookieheader/";") - ({""})), string c)
{
string name, value;
while(sizeof(c) && c[0]==' ') c=c[1..];
if(sscanf(c, "%s=%s", name, value) == 2)
{
value=http_decode_string(value);
name=http_decode_string(name);
cookies[ name ]=value;
|
55533a | 2002-03-22 | Ian Delahorne | | #ifdef OLD_RXML_CONFIG
|
ad3d95 | 2004-12-01 | Stefan Wallström | | if( (name == "RoxenConfig") && strlen(value) )
config = mkmultiset( value/"," );
|
55533a | 2002-03-22 | Ian Delahorne | | #endif
|
ad3d95 | 2004-12-01 | Stefan Wallström | | }
}
|
55533a | 2002-03-22 | Ian Delahorne | | }
return cookies;
}
|
edc50f | 2005-12-07 | Henrik Grubbström (Grubba) | | #endif
|
55533a | 2002-03-22 | Ian Delahorne | |
|
dcc895 | 2001-10-09 | Marcus Wellhardh | | int things_to_do_when_not_sending_from_cache( )
|
a86c3b | 2000-08-28 | Per Hedbor | | {
#ifdef OLD_RXML_CONFIG
array mod_config;
int config_in_url;
#endif
|
2e0b59 | 2008-01-08 | Martin Stjernholm | | misc->cachekey = ProtocolCacheKey();
|
a2a5aa | 2000-08-31 | Per Hedbor | | misc->_cachecallbacks = ({});
|
bf2543 | 2001-02-24 | Per Hedbor | |
|
a432ad | 2008-01-10 | Martin Stjernholm | | init_pref_languages();
|
edc50f | 2005-12-07 | Henrik Grubbström (Grubba) | | init_cookies();
|
a86c3b | 2000-08-28 | Per Hedbor | |
#ifndef DISABLE_SUPPORTS
|
f16377 | 2000-08-28 | Per Hedbor | | if( !supports )
|
a86c3b | 2000-08-28 | Per Hedbor | | {
if( !client )
{
client = ({ "unknown" });
array s_and_v = find_supports_and_vars("", supports);
supports = s_and_v[0];
client_var = s_and_v[1];
}
else
{
if( !client_var->Fullname )
client_var->Fullname = "unknown";
client_var->fullname=lower_case(client_var->Fullname);
array s_and_v=find_supports_and_vars(client_var->fullname,supports,client_var);
supports = s_and_v[0];
client_var = s_and_v[1];
}
}
|
18c1e5 | 2008-02-18 | Martin Stjernholm | |
|
a86c3b | 2000-08-28 | Per Hedbor | | if ( client_var->charset && client_var->charset != "iso-8859-1" )
{
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | |
NO_PROTO_CACHE();
|
c0480e | 2008-02-18 | Martin Stjernholm | |
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | |
|
a86c3b | 2000-08-28 | Per Hedbor | | set_output_charset( client_var->charset );
input_charset = client_var->charset;
}
|
c0480e | 2008-02-18 | Martin Stjernholm | |
#else // DISABLE_SUPPORTS
|
a86c3b | 2000-08-28 | Per Hedbor | | supports = (< "images", "gifinline", "forms", "mailto">);
#endif
|
18c1e5 | 2008-02-18 | Martin Stjernholm | |
|
c0480e | 2008-02-18 | Martin Stjernholm | | {
string f = raw_url;
sscanf (f, "%s?%s", f, query);
if (query) {
int i = search (query, "roxen_magic_per_u=%25");
if (i >= 0 && (i == 0 || query[i - 1] == '&')) {
REQUEST_WERR(sprintf("Broken http encoding detected. query=%O\n",
query));
query = replace(query, ({ "%25u", "%25U" }), ({ "%u", "%U" }));
REQUEST_WERR(sprintf("Repaired query=%O\n", query));
}
}
|
655ae9 | 2009-03-21 | Martin Stjernholm | | {
mapping(string:array(string)) vars =
misc->post_variables ? misc->post_variables + ([]) : ([]);
if (query)
split_query_vars (query, vars);
if (sizeof (vars)) {
decode_query: {
if (input_charset) {
if (mixed err = catch {
f = decode_query_charset (_Roxen.http_decode_string (f),
vars, input_charset);
}) {
report_debug ("Client %O sent query %O which failed to decode "
"with its own charset %O: %s",
client_var->fullname, raw_url,
input_charset, describe_error (err));
input_charset = 0;
}
else break decode_query;
|
c0480e | 2008-02-18 | Martin Stjernholm | | }
|
655ae9 | 2009-03-21 | Martin Stjernholm | |
f = decode_query_charset (_Roxen.http_decode_string (f),
vars, "roxen-http-default");
|
c0480e | 2008-02-18 | Martin Stjernholm | | }
|
996820 | 2009-03-21 | Martin Stjernholm | | if (array(string) rest = m_delete (real_variables, ""))
rest_query = rest[0];
|
655ae9 | 2009-03-21 | Martin Stjernholm | | if (input_charset && misc->post_variables) {
if (query) {
function(string:string) decoder =
Roxen.get_decoder_for_client_charset (input_charset);
mapping(string:array(string)) decoded_vars = ([]);
foreach (misc->post_variables; string var; array(string) vals) {
var = decoder (var);
decoded_vars[var] = real_variables[var][..sizeof (vals) - 1];
}
misc->post_variables = decoded_vars;
}
else
misc->post_variables = real_variables + ([]);
if (misc->post_parts) {
mapping(string:string) decoded_names = ([]);
function(string:string) decoder =
Roxen.get_decoder_for_client_charset (input_charset);
mapping(string:array(MIME.Message)) decoded_post_parts = ([]);
foreach (misc->post_parts; string var; array(MIME.Message) parts) {
string decoded_var = decoder (var);
decoded_names[var] = decoded_var;
decoded_post_parts[decoded_var] = parts;
}
misc->post_parts = decoded_post_parts;
if (misc->files)
misc->files = map (misc->files, decoded_names);
}
}
|
fdd115 | 2008-09-26 | Martin Stjernholm | | }
|
d4505c | 2008-09-26 | Martin Stjernholm | | else {
|
655ae9 | 2009-03-21 | Martin Stjernholm | |
|
d4505c | 2008-09-26 | Martin Stjernholm | | f = http_decode_string (f);
if (input_charset) {
if (mixed err = catch {
f = Roxen.get_decoder_for_client_charset (input_charset) (f);
})
report_debug ("Client %O requested path %O which failed to decode "
"with the input charset %O: %s",
client_var->fullname, f, input_charset,
describe_error (err));
}
else
catch (f = utf8_to_string (f));
|
c0480e | 2008-02-18 | Martin Stjernholm | | }
|
655ae9 | 2009-03-21 | Martin Stjernholm | |
if (mapping(string:array(string)) ppv =
m_delete (misc, "proper_post_vars")) {
misc->post_variables = ppv;
foreach (ppv; string var; array(string) val) {
if (array(string) oldval = real_variables[var])
real_variables[var] = val + oldval;
else
real_variables[var] = val;
}
}
|
c0480e | 2008-02-18 | Martin Stjernholm | | }
#if 0
if(search(f, "\0") != -1)
sscanf(f, "%s\0", f);
#endif
if( strlen( f ) > 5 )
{
string a;
switch( f[1] )
{
#ifdef OLD_RXML_CONFIG
case '<':
if (sscanf(f, "/<%s>/%s", a, f)==2)
{
config_in_url = 1;
mod_config = (a/",");
f = "/"+f;
}
#endif
case '(':
if(sscanf(f, "/(%s)/%s", a, f)==2)
{
prestate = (multiset)( a/","-({""}) );
f = "/"+f;
}
}
}
if (has_prefix (f, "/"))
not_query = combine_path_unix ("/", f);
else
not_query = combine_path_unix ("/", f)[1..];
}
|
552ed0 | 2008-01-10 | Martin Stjernholm | | {
int i = search (client, "MSIE");
if (i < 0)
supports->vary = 1;
else if (++i < sizeof (client) &&
sscanf (client[i], "%d", int msie_major) == 1) {
if (msie_major >= 7)
supports->vary = 1;
}
|
214e60 | 2006-08-11 | Henrik Grubbström (Grubba) | | }
|
18c1e5 | 2008-02-18 | Martin Stjernholm | |
|
f136c2 | 2002-02-26 | Martin Stjernholm | |
|
a86c3b | 2000-08-28 | Per Hedbor | | if(!referer) referer = ({ });
|
18c1e5 | 2008-02-18 | Martin Stjernholm | |
|
a86c3b | 2000-08-28 | Per Hedbor | | if(misc->proxyauth)
{
mixed tmp1,tmp2;
foreach(tmp2 = (raw / "\n"), tmp1) {
if(!search(lower_case(tmp1), "proxy-authorization:"))
tmp2 -= ({tmp1});
}
raw = tmp2 * "\n";
}
|
18c1e5 | 2008-02-18 | Martin Stjernholm | |
|
a86c3b | 2000-08-28 | Per Hedbor | | #ifdef OLD_RXML_CONFIG
if(config_in_url) {
|
f136c2 | 2002-02-26 | Martin Stjernholm | |
|
e056e9 | 2000-10-19 | Per Hedbor | | really_set_config( mod_config );
|
dcc895 | 2001-10-09 | Marcus Wellhardh | | return 1;
|
a86c3b | 2000-08-28 | Per Hedbor | | }
#endif
|
18c1e5 | 2008-02-18 | Martin Stjernholm | |
|
79e7c4 | 2004-05-05 | Marcus Wellhardh | | if(!supports->cookies && !sizeof(config))
|
a86c3b | 2000-08-28 | Per Hedbor | | config = prestate;
|
49681e | 2006-12-14 | Henrik Grubbström (Grubba) | | else {
|
bc0fa0 | 2001-03-08 | Per Hedbor | | if( port_obj->set_cookie
|
a86c3b | 2000-08-28 | Per Hedbor | | && !cookies->RoxenUserID && strlen(not_query)
&& not_query[0]=='/' && method!="PUT")
{
|
49681e | 2006-12-14 | Henrik Grubbström (Grubba) | | NO_PROTO_CACHE();
|
a86c3b | 2000-08-28 | Per Hedbor | | if (!(port_obj->set_cookie_only_once &&
|
49681e | 2006-12-14 | Henrik Grubbström (Grubba) | | cache_lookup("hosts_for_cookie",remoteaddr))) {
|
85979c | 2008-08-18 | Erik Dahl | | misc->moreheads = ([ "Set-Cookie":Roxen.http_roxen_id_cookie(), ]);
|
49681e | 2006-12-14 | Henrik Grubbström (Grubba) | | }
|
a86c3b | 2000-08-28 | Per Hedbor | | if (port_obj->set_cookie_only_once)
cache_set("hosts_for_cookie",remoteaddr,1);
}
|
49681e | 2006-12-14 | Henrik Grubbström (Grubba) | | }
|
2fdf09 | 2000-12-02 | Per Hedbor | | }
|
d25fde | 2000-10-17 | Per Hedbor | |
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | |
private int got_chunk_fragment(string fragment)
{
|
7e28e2 | 2009-06-05 | Henrik Grubbström (Grubba) | | #ifdef CONNECTION_DEBUG
werror("HTTP[%s]: Fragment (length %d+%d/%d) ============================\n"
"%O\n", DEBUG_GET_FD,
sizeof(fragment), sizeof(misc->chunk_buf||""), misc->chunk_len,
fragment);
#else
REQUEST_WERR(sprintf("HTTP: Got Fragment %O", fragment));
#endif
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | string buf = fragment;
int chunk_offset;
if (misc->chunk_len) {
if (misc->chunk_len >= sizeof(fragment)) {
data_buffer->add(fragment);
misc->chunk_len -= sizeof(fragment);
return 0;
} else {
data_buffer->add(fragment[..misc->chunk_len - 1]);
chunk_offset = misc->chunk_len;
misc->chunk_len = 0;
}
} else {
buf = misc->chunk_buf + buf;
}
misc->chunk_buf = "";
while(misc->chunked == 1) {
int chunk_data_offset;
string chunk_extras;
|
760844 | 2009-06-04 | Henrik Grubbström (Grubba) | | int n = sscanf(buf, "%" + chunk_offset + "*s%x%s\r\n%n",
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | misc->chunk_len, chunk_extras,
chunk_data_offset);
if (n < 4) {
misc->chunk_buf = buf[chunk_offset..];
misc->chunk_len = 0;
return 0;
}
|
7e28e2 | 2009-06-05 | Henrik Grubbström (Grubba) | | #ifdef CONNECTION_DEBUG
werror("HTTP[%s]: Got chunk with %d bytes of data.\n",
DEBUG_GET_FD, misc->chunk_len);
#endif
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | |
if (sizeof(buf) < chunk_data_offset + misc->chunk_len) {
if (!data_buffer) {
data_buffer =
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | String.Buffer(sizeof(data) + misc->chunk_len + 16384);
if (sizeof(data)) data_buffer->add(data);
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | data = "";
}
data_buffer->add(buf[chunk_data_offset..]);
misc->chunk_len -= sizeof(buf) - chunk_data_offset;
return 0;
} else if (misc->chunk_len) {
string str =
buf[chunk_data_offset..chunk_data_offset + misc->chunk_len - 1];
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | if (sizeof(data) && !data_buffer) {
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | |
data_buffer = String.Buffer(sizeof(data) + misc->chunk_len + 16384);
data_buffer->add(data);
data_buffer->add(str);
data = "";
}
if (data_buffer) {
data_buffer->add(str);
} else {
data = str;
}
chunk_offset = chunk_data_offset + misc->chunk_len;
} else {
if (data_buffer) {
data = data_buffer->get();
data_buffer = 0;
}
chunk_offset = chunk_data_offset;
misc->len = sizeof(data);
misc->chunked = 2;
break;
}
}
if (misc->chunked == 2) {
if (!misc->chunked_hp) {
|
7e28e2 | 2009-06-05 | Henrik Grubbström (Grubba) | | #ifdef CONNECTION_DEBUG
werror("HTTP[%s]: Parsing entity headers...\n", DEBUG_GET_FD);
#endif
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | if (buf[chunk_offset..chunk_offset + 1] == "\r\n") {
|
7e28e2 | 2009-06-05 | Henrik Grubbström (Grubba) | | #ifdef CONNECTION_DEBUG
werror("HTTP[%s]: No entity headers.\n", DEBUG_GET_FD);
#endif
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | leftovers = buf[chunk_offset+2..];
misc->chunked = 3;
return 3;
}
misc->chunked_hp = Roxen.HeaderParser();
misc->chunked_hp->feed(" \r\n");
}
array res;
if (mixed err = catch {
res = misc->chunked_hp->feed(buf[chunk_offset..]);
}) {
|
7e28e2 | 2009-06-05 | Henrik Grubbström (Grubba) | | #if defined(DEBUG) || defined(CONNECTION_DEBUG)
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | report_debug ("Got bad request (chunked), HeaderParser error: " +
describe_error (err));
#endif
misc->connection = "close";
leftovers = "";
} else {
if (!res) return 0;
|
7e28e2 | 2009-06-05 | Henrik Grubbström (Grubba) | | #ifdef CONNECTION_DEBUG
werror("HTTP[%s]: Got entity headers: %O.\n", DEBUG_GET_FD, res[2]);
#endif
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | leftovers = res[0];
request_headers |= res[2];
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | |
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | |
}
misc->chunked = 3;
m_delete(misc, "chunked_hp");
}
|
7e28e2 | 2009-06-05 | Henrik Grubbström (Grubba) | | #ifdef CONNECTION_DEBUG
werror("HTTP[%s]: Chunked parsing done.\n", DEBUG_GET_FD);
#endif
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | return 3;
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected Roxen.HeaderParser hp = Roxen.HeaderParser();
|
d25fde | 2000-10-17 | Per Hedbor | |
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | |
|
a3ebea | 2000-08-12 | Per Hedbor | | private int parse_got( string new_data )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
5a1a5e | 2008-02-18 | Martin Stjernholm | | if (hp) {
|
49d460 | 2008-02-15 | Martin Stjernholm | | string line;
TIMER_START(parse_got);
|
5a1a5e | 2008-02-18 | Martin Stjernholm | | if (!hrtime)
hrtime = gethrtime();
|
49d460 | 2008-02-15 | Martin Stjernholm | | {
array res;
if( mixed err = catch( res = hp->feed( new_data ) ) ) {
|
95e41e | 2003-10-28 | Martin Stjernholm | | #ifdef DEBUG
|
49d460 | 2008-02-15 | Martin Stjernholm | | report_debug ("Got bad request, HeaderParser error: " + describe_error (err));
|
95e41e | 2003-10-28 | Martin Stjernholm | | #endif
|
49d460 | 2008-02-15 | Martin Stjernholm | | return 1;
}
if( !res )
{
TIMER_END(parse_got);
return 0;
}
[data, line, request_headers] = res;
|
9c1900 | 2001-02-27 | Per Hedbor | | }
|
49d460 | 2008-02-15 | Martin Stjernholm | | hp = 0;
TIMER_END(parse_got);
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
49d460 | 2008-02-15 | Martin Stjernholm | |
|
6110fd | 2008-02-15 | Martin Stjernholm | |
|
49d460 | 2008-02-15 | Martin Stjernholm | | TIMER_START(parse_got_2);
TIMER_START(parse_got_2_parse_line);
|
6110fd | 2008-02-15 | Martin Stjernholm | | string f;
array(string) sl = line / " ";
switch( sizeof( sl ) )
{
default:
sl = ({ sl[0], sl[1..sizeof(sl)-2]*" ", sl[-1] });
case 3:
method = sl[0];
f = sl[1];
clientprot = sl[2];
prot = clientprot;
if(!(< "HTTP/1.0", "HTTP/1.1" >)[prot])
{
int maj,min;
if( sscanf(prot, "HTTP/%d.%d", maj, min) == 2 )
prot = "HTTP/" + maj + "." + min;
else
prot = "HTTP/1.1";
}
misc->connection = "keep-alive";
if (prot == "HTTP/1.0") {
misc->connection = "close";
}
break;
|
c0202a | 2001-02-01 | Per Hedbor | |
|
6110fd | 2008-02-15 | Martin Stjernholm | | case 2:
case 1:
misc->connection = "close";
method = sl[0];
f = sl[-1];
if( sizeof( sl ) == 1 )
sscanf( method, "%s%*[\r\n]", method );
|
c0202a | 2001-02-01 | Per Hedbor | |
|
6110fd | 2008-02-15 | Martin Stjernholm | | clientprot = prot = "HTTP/0.9";
if(method != "PING")
method = "GET";
else
{
|
96cf67 | 2009-01-15 | Martin Stjernholm | | #ifdef CONNECTION_DEBUG
werror ("HTTP[%s]: Response =============================================\n"
"%O\n", DEBUG_GET_FD, "PONG\r\n");
#else
REQUEST_WERR("HTTP: Send PONG");
#endif
|
6110fd | 2008-02-15 | Martin Stjernholm | | my_fd->write("PONG\r\n");
TIMER_END(parse_got_2_parse_line);
TIMER_END(parse_got_2);
return 2;
}
data = "";
sscanf( f, "%s%*[\r\n]", f );
if (sizeof(sl) == 1)
NO_PROTO_CACHE();
break;
|
94add0 | 2001-02-01 | Henrik Grubbström (Grubba) | |
|
6110fd | 2008-02-15 | Martin Stjernholm | | case 0:
break;
}
TIMER_END(parse_got_2_parse_line);
REQUEST_WERR(sprintf("HTTP: request line %O", line));
REQUEST_WERR(sprintf("HTTP: headers %O", request_headers));
REQUEST_WERR(sprintf("HTTP: data (length %d) %O", strlen(data),data));
raw_url = f;
time = predef::time(1);
|
7ec660 | 1997-01-29 | Per Hedbor | |
|
435dfc | 2008-02-18 | Martin Stjernholm | | if(!remoteaddr)
{
if(my_fd) {
remoteaddr = my_fd->query_address();
if(remoteaddr)
sscanf(remoteaddr, "%s %*s", remoteaddr);
}
if(!remoteaddr) {
|
118fce | 2009-05-29 | Martin Stjernholm | | REQUEST_WERR(sprintf ("HTTP: No remote address (error %d).",
my_fd->errno()));
|
435dfc | 2008-02-18 | Martin Stjernholm | | TIMER_END(parse_got_2);
return 2;
}
|
e5bad2 | 1998-02-10 | Per Hedbor | | }
|
7ec660 | 1997-01-29 | Per Hedbor | |
|
435dfc | 2008-02-18 | Martin Stjernholm | | TIMER_START(parse_got_2_parse_headers);
|
5a1a5e | 2008-02-18 | Martin Stjernholm | | foreach (request_headers; string linename; array|string contents)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
435dfc | 2008-02-18 | Martin Stjernholm | | if( arrayp(contents) ) contents = contents[0];
switch (linename)
{
case "cache-control":
case "pragma": pragma|=(multiset)((contents-" ")/","); break;
case "content-length": misc->len = (int)contents; break;
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | case "transfer-encoding":
misc->transfer_encoding =
map(lower_case(contents)/";", String.trim_all_whites);
if (has_value(misc->transfer_encoding, "chunked")) {
misc->chunked = 1;
misc->chunk_buf = "";
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | new_data = data;
data = "";
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | }
break;
|
435dfc | 2008-02-18 | Martin Stjernholm | | case "authorization": rawauth = contents; break;
case "referer": referer = ({contents}); break;
case "if-modified-since": since=contents; break;
case "if-match": break;
case "if-none-match":
none_match = (multiset)((contents-" ")/",");
break;
case "proxy-authorization":
array y;
y = contents / " ";
if(sizeof(y) < 2)
break;
y[1] = decode(y[1]);
misc->proxyauth=y;
break;
case "user-agent":
if( !client )
{
sscanf(contents, "%s via", contents);
client_var->Fullname=contents;
client = contents/" " - ({ "" });
}
break;
case "request-range":
contents = lower_case(contents-" ");
if (has_prefix(contents, "bytes"))
misc->range = contents[6..];
break;
case "range":
contents = lower_case(contents-" ");
if (!misc->range && has_prefix(contents, "bytes"))
misc->range = contents[6..];
break;
case "connection":
misc->client_connection = (<@(lower_case(contents)/" " - ({""}))>);
if (misc->client_connection->close) {
misc->connection = "close";
} else if (misc->client_connection["keep-alive"]) {
misc->connection = "keep-alive";
}
break;
case "host":
misc[linename] = lower_case(contents);
break;
case "content-type":
|
34acd0 | 2008-02-19 | Martin Stjernholm | |
|
435dfc | 2008-02-18 | Martin Stjernholm | | misc[linename] = contents;
|
34acd0 | 2008-02-19 | Martin Stjernholm | | #define WS "%*[ \t]"
sscanf (contents, WS"%[^ \t/]"WS"/"WS"%[^ \t;]"WS";"WS"%s",
string ct_type, string ct_subtype,
misc->content_type_params);
misc->content_type_type = lower_case (ct_type + "/" + ct_subtype);
|
435dfc | 2008-02-18 | Martin Stjernholm | | break;
case "destination":
if (mixed err = catch {
contents = http_decode_string (Standards.URI(contents)->path);
}) {
|
dd3719 | 2004-04-21 | Henrik Grubbström (Grubba) | | #ifdef DEBUG
|
435dfc | 2008-02-18 | Martin Stjernholm | | report_debug(sprintf("Destination header contained a bad URI: %O\n"
"%s", contents, describe_error(err)));
|
dd3719 | 2004-04-21 | Henrik Grubbström (Grubba) | | #endif /* DEBUG */
|
435dfc | 2008-02-18 | Martin Stjernholm | | }
misc["new-uri"] = VFS.normalize_path (contents);
break;
|
2750d4 | 2009-01-15 | Martin Stjernholm | |
case "expect":
|
11171a | 2009-04-01 | Thomas Gusenleitner | |
if (String.trim_all_whites(lower_case(contents)) != "100-continue") {
|
96cf67 | 2009-01-15 | Martin Stjernholm | | string res = "HTTP/1.1 417 Expectation Failed\r\n\r\n";
#ifdef CONNECTION_DEBUG
werror ("HTTP[%s]: Response (length %d) =================================\n"
"%O\n", DEBUG_GET_FD, sizeof (res), res);
#else
REQUEST_WERR(sprintf("HTTP: Send %O", res));
#endif
my_fd->write (res);
|
2750d4 | 2009-01-15 | Martin Stjernholm | | return 2;
}
break;
|
435dfc | 2008-02-18 | Martin Stjernholm | | }
|
41b77c | 1999-07-15 | David Hedbor | | }
|
435dfc | 2008-02-18 | Martin Stjernholm | | TIMER_END(parse_got_2_parse_headers);
|
5a1a5e | 2008-02-18 | Martin Stjernholm | | }
|
6110fd | 2008-02-15 | Martin Stjernholm | |
|
1752c3 | 2003-04-22 | Dan Nelson | | TIMER_START(parse_got_2_more_data);
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | if (misc->chunked) {
int ret = got_chunk_fragment(new_data);
if (ret != 3) {
REQUEST_WERR(sprintf("HTTP: More data needed in %s (chunked).", method));
ready_to_receive();
TIMER_END(parse_got_2_more_data);
TIMER_END(parse_got_2);
return ret;
}
} else if(misc->len)
|
a86c3b | 2000-08-28 | Per Hedbor | | {
int l = misc->len;
wanted_data=l;
have_data=strlen(data);
|
fdd26d | 2000-07-23 | Stefan Wallström | |
|
a86c3b | 2000-08-28 | Per Hedbor | | if(strlen(data) < l)
{
|
f136c2 | 2002-02-26 | Martin Stjernholm | | REQUEST_WERR(sprintf("HTTP: More data needed in %s.", method));
|
e1995f | 2003-12-29 | Henrik Grubbström (Grubba) | | ready_to_receive();
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | TIMER_END(parse_got_2_more_data);
|
0f1512 | 2003-02-25 | Henrik Grubbström (Grubba) | | TIMER_END(parse_got_2);
|
a86c3b | 2000-08-28 | Per Hedbor | | return 0;
}
leftovers = data[l+2..];
data = data[..l+1];
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | } else {
leftovers = data;
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | data = "";
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | }
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | if (sizeof(data)) {
|
1752c3 | 2003-04-22 | Dan Nelson | | switch(method) {
case "POST":
|
5fdddc | 2009-03-31 | Martin Stjernholm | |
|
18c1e5 | 2008-02-18 | Martin Stjernholm | |
|
655ae9 | 2009-03-21 | Martin Stjernholm | |
|
34acd0 | 2008-02-19 | Martin Stjernholm | | switch (misc->content_type_type)
|
faf7c0 | 2001-08-23 | Henrik Grubbström (Grubba) | | {
|
34acd0 | 2008-02-19 | Martin Stjernholm | | case "application/x-www-form-urlencoded": {
|
18c1e5 | 2008-02-18 | Martin Stjernholm | |
|
34acd0 | 2008-02-19 | Martin Stjernholm | |
|
655ae9 | 2009-03-21 | Martin Stjernholm | | string v = String.trim_all_whites (data);
|
34acd0 | 2008-02-19 | Martin Stjernholm | |
|
655ae9 | 2009-03-21 | Martin Stjernholm | |
|
c0480e | 2008-02-18 | Martin Stjernholm | |
|
655ae9 | 2009-03-21 | Martin Stjernholm | | split_query_vars (v, misc->post_variables = ([]));
|
faf7c0 | 2001-08-23 | Henrik Grubbström (Grubba) | | break;
|
18c1e5 | 2008-02-18 | Martin Stjernholm | | }
|
a86c3b | 2000-08-28 | Per Hedbor | |
|
18c1e5 | 2008-02-18 | Martin Stjernholm | | case "multipart/form-data": {
|
eab87a | 2008-08-13 | Mathias Södermark | |
|
655ae9 | 2009-03-21 | Martin Stjernholm | | MIME.Message messg = MIME.Message(data, request_headers, UNDEFINED, 1);
array(MIME.Message) parts = messg->body_parts;
if (!parts) {
|
d0739e | 2002-02-14 | Henrik Grubbström (Grubba) | | report_error("HTTP: Bad multipart/form-data.\n"
" headers:\n"
"%{ %O:%O\n%}"
" data:\n"
"%{ %O\"\\n\"\n%}",
(array)request_headers,
data/"\n");
|
655ae9 | 2009-03-21 | Martin Stjernholm | | }
else {
{
array(MIME.Message) subparts = ({});
foreach (parts; int i; MIME.Message part)
if (array(MIME.Message) sub = part->body_parts) {
subparts += sub;
parts[i] = 0;
}
if (sizeof (subparts))
parts = parts - ({0}) + subparts;
}
mapping(string:string) rfc2047_decoded = ([]);
int rfc2388_mode;
foreach (parts, MIME.Message part) {
foreach (part->disp_params;; string param) {
string decoded;
if (!catch (decoded = MIME.decode_words_text_remapped (param)) &&
decoded != param)
rfc2047_decoded[param] = decoded;
}
if (part->params->charset)
rfc2388_mode = 1;
}
if (sizeof (rfc2047_decoded))
rfc2388_mode = 1;
mapping(string:array(MIME.Message)) post_parts =
misc->post_parts = ([]);
if (rfc2388_mode) {
mapping(string:array(string)) post_vars =
misc->proper_post_vars = ([]);
foreach (parts, MIME.Message part) {
string name = part->disp_params->name;
if (string decoded = rfc2047_decoded[name]) name = decoded;
post_parts[name] += ({part});
string data = part->getdata();
if (string charset = part->param->charset) {
if (mixed err = catch {
data = Locale.Charset.decoder (charset)->
feed (data)->drain();
})
report_debug ("Client %q sent data for %q which failed to "
"decode with supplied charset %q: %s",
client_var->fullname, name, charset,
describe_error (err));
}
post_vars[name] += ({data});
if (part->headers["content-type"])
post_vars[name + ".mimetype"] += ({part->type + "/" +
part->subtype});
if (string filename = part->disp_params->filename) {
if (string decoded = rfc2047_decoded[filename])
filename = decoded;
post_vars[name + ".filename"] += ({filename});
misc->files += ({name});
}
|
12db5a | 2009-01-10 | Stephen R. van den Berg | | }
|
655ae9 | 2009-03-21 | Martin Stjernholm | | }
else {
mapping(string:array(string)) post_vars =
misc->post_variables = ([]);
foreach (parts, MIME.Message part) {
string name = part->disp_params->name;
post_parts[name] += ({part});
|
5fdddc | 2009-03-31 | Martin Stjernholm | |
|
655ae9 | 2009-03-21 | Martin Stjernholm | | post_vars[name] += ({part->getdata()});
if (part->headers["content-type"])
post_vars[name + ".mimetype"] += ({part->type + "/" +
part->subtype});
if (string filename = part->disp_params->filename) {
post_vars[name + ".filename"] += ({filename});
misc->files += ({name});
}
|
12db5a | 2009-01-10 | Stephen R. van den Berg | | }
|
d0739e | 2002-02-14 | Henrik Grubbström (Grubba) | | }
|
faf7c0 | 2001-08-23 | Henrik Grubbström (Grubba) | | }
break;
}
|
18c1e5 | 2008-02-18 | Martin Stjernholm | | }
|
1752c3 | 2003-04-22 | Dan Nelson | | break;
|
dde965 | 1996-12-08 | David Hedbor | | }
|
ceb927 | 1997-05-15 | David Hedbor | | }
|
1752c3 | 2003-04-22 | Dan Nelson | | TIMER_END(parse_got_2_more_data);
|
6110fd | 2008-02-15 | Martin Stjernholm | |
|
8e7d8c | 2001-11-07 | Henrik Grubbström (Grubba) | | if (!(< "HTTP/1.0", "HTTP/0.9" >)[prot]) {
|
01f8b8 | 2001-11-05 | Henrik Grubbström (Grubba) | | if (!misc->host) {
|
96cf67 | 2009-01-15 | Martin Stjernholm | | string res = (prot||"HTTP/1.1") +
" 400 Bad request (missing host header).\r\n"
"Content-Length: 0\r\n"
"Date: "+Roxen.http_date(predef::time())+"\r\n"
"\r\n";
#ifdef CONNECTION_DEBUG
werror ("HTTP[%s]: Response (length %d) =================================\n"
"%O\n", DEBUG_GET_FD, sizeof (res), res);
#else
|
01f8b8 | 2001-11-05 | Henrik Grubbström (Grubba) | | REQUEST_WERR("HTTP: HTTP/1.1 request without a host header.");
|
96cf67 | 2009-01-15 | Martin Stjernholm | | #endif
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | |
|
96cf67 | 2009-01-15 | Martin Stjernholm | | my_fd->write (res);
|
1752c3 | 2003-04-22 | Dan Nelson | | TIMER_END(parse_got_2);
|
01f8b8 | 2001-11-05 | Henrik Grubbström (Grubba) | | return 2;
}
}
|
0f1512 | 2003-02-25 | Henrik Grubbström (Grubba) | | TIMER_END(parse_got_2);
|
6110fd | 2008-02-15 | Martin Stjernholm | |
|
41b77c | 1999-07-15 | David Hedbor | | return 3;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
void disconnect()
{
|
ebb1c5 | 1998-02-24 | Per Hedbor | | file = 0;
|
aa0207 | 2002-04-05 | Henrik Grubbström (Grubba) | | conf && conf->connection_drop( this_object() );
|
93aa10 | 2003-11-17 | Martin Stjernholm | |
if (my_fd) {
MARK_FD("HTTP closed");
CHECK_FD_SAFE_USE;
|
4a9840 | 2004-08-18 | Martin Stjernholm | | if (mixed err = catch (my_fd->close())) {
#ifdef DEBUG
report_debug ("Failed to close http(s) connection: " +
|
347d85 | 2007-03-09 | Martin Stjernholm | | describe_backtrace (err));
|
6e4d30 | 2004-05-18 | Martin Stjernholm | | #endif
|
4a9840 | 2004-08-18 | Martin Stjernholm | | }
|
93aa10 | 2003-11-17 | Martin Stjernholm | | my_fd = 0;
}
|
9c1900 | 2001-02-27 | Per Hedbor | | MERGE_TIMERS(conf);
|
14179b | 1997-01-29 | Per Hedbor | | destruct();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void cleanup_request_object()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
01f439 | 2002-03-28 | Per Hedbor | | if( conf )
conf->connection_drop( this_object() );
|
a8e2b3 | 2004-05-07 | Henrik Grubbström (Grubba) | | xml_data = 0;
|
1050aa | 2004-02-20 | Martin Stjernholm | | }
void end(int|void keepit)
{
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | if (my_fd) {
CHECK_FD_SAFE_USE;
}
|
1050aa | 2004-02-20 | Martin Stjernholm | |
cleanup_request_object();
|
1752c3 | 2003-04-22 | Dan Nelson | |
|
0aee22 | 2000-08-15 | Martin Stjernholm | | if(keepit
|
c60a40 | 2000-08-22 | Per Hedbor | | && !file->raw
|
f9252e | 2004-05-07 | Henrik Grubbström (Grubba) | | && misc->connection != "close"
|
01f439 | 2002-03-28 | Per Hedbor | | && my_fd
|
1050aa | 2004-02-20 | Martin Stjernholm | |
|
01f439 | 2002-03-28 | Per Hedbor | | && !catch(my_fd->query_address()) )
|
ebb1c5 | 1998-02-24 | Per Hedbor | | {
|
26f44e | 2000-08-13 | Per Hedbor | | object o = object_program(this_object())(0, 0, 0);
|
ebb1c5 | 1998-02-24 | Per Hedbor | | o->remoteaddr = remoteaddr;
|
755c34 | 2010-10-11 | Stefan Wallström | |
|
ebb1c5 | 1998-02-24 | Per Hedbor | | o->host = host;
|
26f44e | 2000-08-13 | Per Hedbor | | o->conf = conf;
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | o->my_fd_busy = !!pipe;
o->pipe = 0;
|
99e65a | 2003-06-18 | Tomas Nilsson | | o->connection_misc = connection_misc;
|
766c71 | 2003-02-03 | Henrik Grubbström (Grubba) | | o->kept_alive = kept_alive+1;
|
0aee22 | 2000-08-15 | Martin Stjernholm | | object fd = my_fd;
my_fd=0;
|
5f6dae | 2000-08-13 | Per Hedbor | | pipe = 0;
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | chained_to = o;
|
4a9840 | 2004-08-18 | Martin Stjernholm | | call_out (o->chain, 0, fd,port_obj,leftovers);
|
0aee22 | 2000-08-15 | Martin Stjernholm | | disconnect();
|
ebb1c5 | 1998-02-24 | Per Hedbor | | return;
}
|
ae2d0e | 2002-11-18 | Henrik Grubbström (Grubba) | | data_buffer = 0;
|
5f6dae | 2000-08-13 | Per Hedbor | | pipe = 0;
|
0aee22 | 2000-08-15 | Martin Stjernholm | | disconnect();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void close_cb()
|
1050aa | 2004-02-20 | Martin Stjernholm | | {
|
20f9b9 | 2004-05-12 | Martin Stjernholm | | #ifdef CONNECTION_DEBUG
|
1139a1 | 2006-10-13 | Martin Stjernholm | | werror ("HTTP[%s]: Client close -----------------------------------------\n",
DEBUG_GET_FD);
|
20f9b9 | 2004-05-12 | Martin Stjernholm | | #else
|
1050aa | 2004-02-20 | Martin Stjernholm | | REQUEST_WERR ("HTTP: Got remote close.");
|
20f9b9 | 2004-05-12 | Martin Stjernholm | | #endif
|
1050aa | 2004-02-20 | Martin Stjernholm | |
CHECK_FD_SAFE_USE;
cleanup_request_object();
data_buffer = 0;
pipe = 0;
|
347d85 | 2007-03-09 | Martin Stjernholm | |
|
5c21cb | 2006-11-16 | Martin Stjernholm | |
|
347d85 | 2007-03-09 | Martin Stjernholm | |
my_fd->set_read_callback (0);
my_fd->set_close_callback (0);
if (my_fd->set_alert_callback) {
my_fd->set_alert_callback (0);
my_fd->set_accept_callback (0);
}
|
1050aa | 2004-02-20 | Martin Stjernholm | | my_fd = 0;
disconnect();
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void do_timeout()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
e2df6a | 2001-01-03 | Per Hedbor | | int elapsed = predef::time(1)-time;
|
9211b2 | 1998-04-24 | Per Hedbor | | if(time && elapsed >= 30)
|
8afc81 | 1998-02-04 | Per Hedbor | | {
|
b692e0 | 2004-08-11 | Henrik Grubbström (Grubba) | | #ifdef CONNECTION_DEBUG
|
1139a1 | 2006-10-13 | Martin Stjernholm | | werror ("HTTP[%s]: Connection timed out. Closing.\n", DEBUG_GET_FD);
#endif
|
b692e0 | 2004-08-11 | Henrik Grubbström (Grubba) | | REQUEST_WERR(sprintf("HTTP: Connection timed out. Closing.\n"
"rcb:%O\n"
"wcb:%O\n"
"ccb:%O\n",
my_fd->query_read_callback(),
my_fd->query_write_callback(),
my_fd->query_close_callback()));
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP timeout");
|
5f6dae | 2000-08-13 | Per Hedbor | | end();
|
8afc81 | 1998-02-04 | Per Hedbor | | } else {
|
39202e | 2003-11-03 | Martin Stjernholm | | #ifdef DEBUG
error ("This shouldn't happen.\n");
#endif
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
|
8afc81 | 1998-02-04 | Per Hedbor | | call_out(do_timeout, 10);
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP premature timeout");
|
8afc81 | 1998-02-04 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string link_to(string file, int line, string fun, int eid, int qq)
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (!file || !line) return "<a>";
|
4f6d92 | 2000-03-27 | Johan Sundström | | return ("<a href=\"/(old_error,find_file)/error/?"+
|
3befe1 | 2000-08-22 | Martin Stjernholm | | "file="+Roxen.http_encode_url(file)+
(fun ? "&fun="+Roxen.http_encode_url(fun) : "") +
|
8641d4 | 2000-03-24 | Martin Stjernholm | | "&off="+qq+
"&error="+eid+
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | "&error_md5="+get_err_md5(get_err_info(eid))+
|
8641d4 | 2000-03-24 | Martin Stjernholm | | (line ? "&line="+line+"#here" : "") +
"\">");
|
86e77d | 1998-05-07 | Per Hedbor | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string error_page(string title, void|string msg,
void|string longmsg, void|string body)
|
8641d4 | 2000-03-24 | Martin Stjernholm | | {
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | if (longmsg && has_suffix (longmsg, "\n"))
longmsg = longmsg[..sizeof (longmsg) - 2];
|
7d7d1b | 2005-01-19 | Martin Stjernholm | | return #"\
<html><head>
<title>Internal Server Error</title>
<style>
.msg { font-family: verdana, helvetica, arial, sans-serif;
font-size: 12px;
line-height: 160% }
.big { font-family: georgia, times, serif;
font-size: 18px;
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | padding-top: 6px }
|
7d7d1b | 2005-01-19 | Martin Stjernholm | | .info { font-family: verdana, helvetica, arial, sans-serif;
font-size: 10px;
color: #999999 }
.list { padding-left: 20px;
list-style-type:square; }
.code { font-family: monaco, courier, monospace;
font-size: 10px;
color: #404070; }
</style>
</head>
<body text='#000000' style='margin: 0; padding: 0' vlink='#2331d1'
rightmargin='0' leftmargin='0' alink='#f6f6ff' link='#0000ee'
bgcolor='#f2f1eb' bottommargin='0' topmargin='0'>
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | <table border='0' cellspacing='30' cellpadding='0' height='99%'>
|
7d7d1b | 2005-01-19 | Martin Stjernholm | | <tr>
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | <td width='1'><img src='/internal-roxen-500' /></td>
|
7d7d1b | 2005-01-19 | Martin Stjernholm | | <td valign='bottom'><img src='/internal-roxen-server-error' /></td>
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | </tr>
<tr>
<td></td>
|
7d7d1b | 2005-01-19 | Martin Stjernholm | | <td>
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | <div class='msg'>" + title + #"</div>" +
(msg ? #"
<div class='big'>" + msg + #"</div>" : "") +
(longmsg ? #"
<div class='code'><pre>" + longmsg + #"</pre></div>" : "") + #"
|
7d7d1b | 2005-01-19 | Martin Stjernholm | | </td>
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | </tr>
<tr>
<td colspan='2'>" +
(body ? #"
<div class='msg'>" + body + #"</div>" : "") + #"
|
7d7d1b | 2005-01-19 | Martin Stjernholm | | </td>
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | </tr>
<tr valign='bottom' height='100%'>
<td colspan='2'>
|
7d7d1b | 2005-01-19 | Martin Stjernholm | | <table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td><img src='/internal-roxen-roxen-mini.gif' /></td>
<td class='info'>
<b>" + roxen_product_name + #"</b>
<font color='#ffbe00'>|</font> " + roxen_dist_version + #"
</td>
</tr>
</table>
</td>
</tr>
</table>
</body></html>";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | }
|
86e77d | 1998-05-07 | Per Hedbor | |
|
8986cf | 2004-06-21 | Jonas Wallden | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string get_err_md5(array(string|array(string)|array(array)) err_info)
|
2b9d4b | 1998-03-25 | Per Hedbor | | {
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | if (err_info) {
|
4e3207 | 2009-01-09 | Stephen R. van den Berg | | return String.string2hex(Crypto.MD5.hash(err_info[3]));
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | }
return "NONE";
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected array(string|array(string)|array(array)) get_err_info(int eid,
string|void md5)
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | {
array(string|array(string)|array(array)) err_info =
|
8641d4 | 2000-03-24 | Martin Stjernholm | | roxen.query_var ("errors")[eid];
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | |
if (!err_info ||
(md5 && (md5 != get_err_md5(err_info)))) {
return 0;
}
return err_info;
}
string format_backtrace(int eid, string|void md5)
{
array(string|array(string)|array(array)) err_info = get_err_info(eid, md5);
if (!err_info) {
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | return error_page("Unregistered error");
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | }
[string msg, array(string) rxml_bt, array(array) bt,
string raw_bt_descr, string raw_url, string raw] = err_info;
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | sscanf (msg, "%s\n%s", string title, string longmsg);
|
dcf62c | 2006-05-04 | Martin Stjernholm | | if (!title) title = msg;
|
8986cf | 2004-06-21 | Jonas Wallden | | string body = "";
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
if (rxml_bt && sizeof (rxml_bt)) {
|
8986cf | 2004-06-21 | Jonas Wallden | | body +=
"RXML frame backtrace"
"<ul class='list'>";
foreach(rxml_bt, string line)
body += "<li class='code'>" + Roxen.html_encode_string(line) + "</li>\n";
body += "</ul>\n";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | }
|
c658b9 | 2000-03-24 | Martin Stjernholm | | if (bt && sizeof (bt)) {
|
8986cf | 2004-06-21 | Jonas Wallden | | body +=
"Pike backtrace"
"<ul class='list'>";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | int q = sizeof (bt);
|
664da6 | 2001-06-08 | Martin Stjernholm | | foreach(bt, [string file, int line, string func, string descr])
|
0efa77 | 2001-09-05 | Marcus Comstedt | | {
#if constant(PIKE_MODULE_RELOC)
file = file && master()->relocate_module(file);
#endif
|
8986cf | 2004-06-21 | Jonas Wallden | | q--;
body +=
"<li>" +
link_to(file, line, func, eid, q) +
(file ? Roxen.html_encode_string(file) : "<i>Unknown program</i>") +
|
8641d4 | 2000-03-24 | Martin Stjernholm | | (line ? ":" + line : "") +
|
8986cf | 2004-06-21 | Jonas Wallden | | "</a>" +
(file ? Roxen.html_encode_string(get_cvs_id(file)) : "") +
"<br /><span class='code'>" +
|
e92130 | 2004-06-21 | Jonas Wallden | | replace(Roxen.html_encode_string(descr), " ", " ") +
|
8986cf | 2004-06-21 | Jonas Wallden | | "</span></li>\n";
|
0efa77 | 2001-09-05 | Marcus Comstedt | | }
|
8986cf | 2004-06-21 | Jonas Wallden | | body += "</ul>\n\n";
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
|
8986cf | 2004-06-21 | Jonas Wallden | | body +=
"<p>Generate "
"<a href=\"/(old_error,plain)/error/?"
"error=" + eid +
"&error_md5=" + get_err_md5(get_err_info(eid)) +
"\">"
"text-only version</a> of this error message for bug reports.</p>";
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | return error_page("The server failed to fulfill your query.",
title, longmsg != "" && longmsg, body);
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string generate_bugreport(string msg, array(string) rxml_bt, array(string) bt,
|
282739 | 2000-03-26 | Martin Stjernholm | | string raw_bt_descr, string raw_url, string raw)
|
2b9d4b | 1998-03-25 | Per Hedbor | | {
|
a7d90b | 2004-04-25 | Henrik Grubbström (Grubba) | | return ("Roxen version: "+roxen.version()+
(roxen.real_version != roxen.version()?
|
282739 | 2000-03-26 | Martin Stjernholm | | " ("+roxen.real_version+")":"")+
"\nPike version: " + predef::version() +
"\nRequested URL: "+raw_url+"\n"
"\nError: " + raw_bt_descr +
"\nRequest data:\n"+raw);
|
f28818 | 1998-05-25 | Per Hedbor | | }
string censor(string what)
{
string a, b, c;
|
0322b7 | 1999-08-06 | Per Hedbor | | if(!what)
return "No backtrace";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if(sscanf(what, "%suthorization:%s\n%s", a, b, c)==3)
return a+"uthorization: ################ (censored)\n"+c;
|
f28818 | 1998-05-25 | Per Hedbor | | return what;
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
1d3134 | 2000-09-03 | Per Hedbor | | int store_error(mixed _err)
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
1d3134 | 2000-09-03 | Per Hedbor | | mixed err = _err;
_err = 0;
|
35c263 | 1999-02-16 | Per Hedbor | | mapping e = roxen.query_var("errors");
if(!e) roxen.set_var("errors", ([]));
e = roxen.query_var("errors");
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
86e77d | 1998-05-07 | Per Hedbor | | int id = ++e[0];
if(id>1024) id = 1;
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
string msg;
array(string) rxml_bt;
if (!err) msg = "Unknown error";
else {
msg = describe_error (err);
int i = search (msg, "\nRXML frame backtrace:\n");
if (i >= 0) {
rxml_bt = (msg[i + sizeof ("\nRXML frame backtrace:")..] / "\n | ")[1..];
if (sizeof (rxml_bt)) rxml_bt[-1] = rxml_bt[-1][..sizeof (rxml_bt[-1]) - 2];
msg = msg[..i - 1];
}
}
|
1d3134 | 2000-09-03 | Per Hedbor | | function dp = master()->describe_program;
|
008c69 | 2001-03-16 | Martin Nilsson | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string cwd = getcwd() + "/";
array bt;
|
c658b9 | 2000-03-24 | Martin Stjernholm | | if (arrayp (err) && sizeof (err) >= 2 && arrayp (err[1]) ||
objectp (err) && err->is_generic_error) {
|
008c69 | 2001-03-16 | Martin Nilsson | |
object d = master()->Describer();
|
664da6 | 2001-06-08 | Martin Stjernholm | | d->identify_parts(err[1]);
|
008c69 | 2001-03-16 | Martin Nilsson | | function dcl = d->describe_comma_list;
|
8641d4 | 2000-03-24 | Martin Stjernholm | | bt = ({});
|
008c69 | 2001-03-16 | Martin Nilsson | |
|
664da6 | 2001-06-08 | Martin Stjernholm | | foreach (reverse (err[1]), mixed ent) {
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string file, func, descr;
int line;
if (arrayp (ent)) {
if (sizeof (ent) && stringp (ent[0]))
if (ent[0][..sizeof (cwd) - 1] == cwd)
file = ent[0] = ent[0][sizeof (cwd)..];
else
file = ent[0];
if (sizeof (ent) >= 2) line = ent[1];
if (sizeof (ent) >= 3)
if(functionp(ent[2])) {
|
3befe1 | 2000-08-22 | Martin Stjernholm | | func = "";
if (object o = function_object (ent[2])) {
string s;
if (!catch (s = sprintf ("%O",o)) && s != "object")
func = s + "->";
}
func += function_name(ent[2]);
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (!file)
catch {
|
1d3134 | 2000-09-03 | Per Hedbor | | file = dp(object_program( function_object( ent[2] ) ) );
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (file[..sizeof (cwd) - 1] == cwd) file = file[sizeof (cwd)..];
};
}
else if (stringp(ent[2])) func = ent[2];
|
2c639f | 2000-09-02 | Per Hedbor | | else func ="<unknown function>";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (sizeof (ent) >= 4)
|
aceff2 | 2009-01-09 | Martin Stjernholm | | descr = func + "(" +dcl(ent[3..],1000)+")";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | else
descr = func + "()";
}
else if (stringp (ent)) descr = ent;
else if (catch (descr = sprintf ("%O", ent)))
descr = "???";
bt += ({({file, line, func, descr})});
}
}
|
3d7773 | 2001-12-04 | Martin Stjernholm | | add_cvs_ids (err);
|
282739 | 2000-03-26 | Martin Stjernholm | | e[id] = ({msg,rxml_bt,bt,describe_backtrace (err),raw_url,censor(raw)});
|
86e77d | 1998-05-07 | Per Hedbor | | return id;
}
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | array get_error(string eid, string md5)
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
35c263 | 1999-02-16 | Per Hedbor | | mapping e = roxen.query_var("errors");
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | if(e) {
array r = e[(int)eid];
|
4e3207 | 2009-01-09 | Stephen R. van den Berg | | if (r && (md5 == String.string2hex(Crypto.MD5.hash(r[3])))) {
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | return r;
}
}
|
86e77d | 1998-05-07 | Per Hedbor | | return 0;
}
|
1d3134 | 2000-09-03 | Per Hedbor | | void internal_error(array _err)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | NO_PROTO_CACHE();
|
1d3134 | 2000-09-03 | Per Hedbor | | mixed err = _err;
_err = 0;
|
bd2223 | 1998-03-27 | David Hedbor | | array err2;
|
e9d117 | 2001-07-31 | Per Hedbor | | if(port_obj && port_obj->query("show_internals"))
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
abdff2 | 1999-12-27 | Martin Nilsson | | err2 = catch {
|
7dba2f | 2000-05-08 | Martin Nilsson | | file = Roxen.http_low_answer(500, format_backtrace(store_error(err)));
|
a7ebda | 2000-01-30 | Per Hedbor | | };
|
bd2223 | 1998-03-27 | David Hedbor | | if(err2) {
werror("Internal server error in internal_error():\n" +
|
86e77d | 1998-05-07 | Per Hedbor | | describe_backtrace(err2)+"\n while processing \n"+
|
bd2223 | 1998-03-27 | David Hedbor | | describe_backtrace(err));
|
8986cf | 2004-06-21 | Jonas Wallden | | file =
Roxen.http_low_answer(500, error_page("The server failed to fulfill "
"your query due to an internal "
"error in the internal error "
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | "routine."));
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
f78848 | 1998-03-18 | Henrik Grubbström (Grubba) | | } else {
|
8986cf | 2004-06-21 | Jonas Wallden | | file =
Roxen.http_low_answer(500, error_page("The server failed to fulfill "
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | "your query."));
|
f78848 | 1998-03-18 | Henrik Grubbström (Grubba) | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | report_error("Internal server error: " +
describe_backtrace(err) + "\n");
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | #ifdef INTERNAL_ERROR_DEBUG
report_error(sprintf("Raw backtrace:%O\n", err));
#endif /* INTERNAL_ERROR_DEBUG */
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
2b40f4 | 1999-12-29 | Martin Stjernholm | |
|
48fa85 | 2004-01-19 | Martin Stjernholm | | #define INTERNAL_ERROR(err) do { \
if (mixed __eRr = catch (internal_error (err))) \
report_error("Internal server error: " + describe_backtrace(err) + \
"internal_error() also failed: " + describe_backtrace(__eRr)); \
} while (0)
|
2b40f4 | 1999-12-29 | Martin Stjernholm | |
|
23a789 | 1996-12-15 | Per Hedbor | | int wants_more()
{
return !!cache;
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected object(this_program) chained_to;
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void destroy()
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | {
|
34dd57 | 2007-02-26 | Martin Stjernholm | |
remove_call_out (do_timeout);
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | if (chained_to) {
|
d41254 | 2005-04-06 | Henrik Grubbström (Grubba) | |
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | call_out(chained_to->my_fd_released, 0);
chained_to = 0;
}
}
|
888665 | 2000-09-19 | Per Hedbor | | void do_log( int|void fsent )
|
d7b087 | 1997-08-31 | Per Hedbor | | {
|
acd724 | 2004-04-27 | Martin Stjernholm | | #ifdef CONNECTION_DEBUG
|
1139a1 | 2006-10-13 | Martin Stjernholm | | werror ("HTTP[%s]: Response sent ========================================\n",
DEBUG_GET_FD);
|
acd724 | 2004-04-27 | Martin Stjernholm | | #endif
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP logging");
|
e7185f | 2005-04-01 | Henrik Grubbström (Grubba) | | if (chained_to) {
call_out(chained_to->my_fd_released, 0);
chained_to = 0;
}
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(do_log);
|
d7b087 | 1997-08-31 | Per Hedbor | | if(conf)
{
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | if(!(file->len = fsent) && pipe) {
|
5f6dae | 2000-08-13 | Per Hedbor | | file->len = pipe->bytes_sent();
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | }
|
d7b087 | 1997-08-31 | Per Hedbor | | if(conf)
{
if(file->len > 0) conf->sent+=file->len;
|
d98628 | 1999-06-30 | David Hedbor | | file->len += misc->_log_cheat_addition;
|
9e0369 | 2010-05-19 | Fredrik Noring | |
{
float t = (gethrtime() - hrtime)/1E6;
if (t > 0.01) conf->request_num_runs_001s++;
if (t > 0.05) conf->request_num_runs_005s++;
if (t > 0.15) conf->request_num_runs_015s++;
if (t > 0.50) conf->request_num_runs_05s++;
if (t > 1.00) conf->request_num_runs_1s++;
if (t > 5.00) conf->request_num_runs_5s++;
if (t > 15.00) conf->request_num_runs_15s++;
conf->request_acc_time += (int)(1E6*t);
}
{
float t = handle_time/1E6;
if (t > 0.01) conf->handle_num_runs_001s++;
if (t > 0.05) conf->handle_num_runs_005s++;
if (t > 0.15) conf->handle_num_runs_015s++;
if (t > 0.50) conf->handle_num_runs_05s++;
if (t > 1.00) conf->handle_num_runs_1s++;
if (t > 5.00) conf->handle_num_runs_5s++;
if (t > 15.00) conf->handle_num_runs_15s++;
conf->handle_acc_time += (int)(1E6*t);
}
{
float t = queue_time/1E6;
if (t > 0.01) conf->queue_num_runs_001s++;
if (t > 0.05) conf->queue_num_runs_005s++;
if (t > 0.15) conf->queue_num_runs_015s++;
if (t > 0.50) conf->queue_num_runs_05s++;
if (t > 1.00) conf->queue_num_runs_1s++;
if (t > 5.00) conf->queue_num_runs_5s++;
if (t > 15.00) conf->queue_num_runs_15s++;
conf->queue_acc_time += (int)(1E6*t);
}
|
f7d981 | 1997-09-12 | Per Hedbor | | conf->log(file, this_object());
|
d7b087 | 1997-08-31 | Per Hedbor | | }
}
|
35233d | 2000-09-01 | Per Hedbor | | if( !port_obj )
{
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(do_log);
MERGE_TIMERS(conf);
|
b611c6 | 2002-03-27 | Per Hedbor | | if( conf )
conf->connection_drop( this_object() );
|
93aa10 | 2003-11-17 | Martin Stjernholm | | call_out (disconnect, 0);
|
35233d | 2000-09-01 | Per Hedbor | | return;
}
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(do_log);
|
c60a40 | 2000-08-22 | Per Hedbor | | end(1);
|
e5bad2 | 1998-02-10 | Per Hedbor | | return;
|
d7b087 | 1997-08-31 | Per Hedbor | | }
|
fa44bd | 1998-03-28 | David Hedbor | | #ifdef FD_DEBUG
|
4949d7 | 1998-03-28 | David Hedbor | | void timer(int start)
{
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | if(pipe) {
|
f136c2 | 2002-02-26 | Martin Stjernholm | | MARK_FD(sprintf("HTTP piping %d %d %d %d (%s)",
|
2c499e | 1998-03-28 | David Hedbor | | pipe->sent,
stringp(pipe->current_input) ?
|
b52900 | 1998-03-28 | David Hedbor | | strlen(pipe->current_input) : -1,
|
9feab4 | 1998-03-28 | David Hedbor | | pipe->last_called,
|
e2df6a | 2001-01-03 | Per Hedbor | | predef::time(1) - start,
|
42ba93 | 1998-03-28 | David Hedbor | | not_query));
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | } else {
|
42ba93 | 1998-03-28 | David Hedbor | | MARK_FD("HTTP piping, but no pipe for "+not_query);
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | }
|
4949d7 | 1998-03-28 | David Hedbor | | call_out(timer, 30, start);
}
|
fa44bd | 1998-03-28 | David Hedbor | | #endif
|
86e77d | 1998-05-07 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string handle_error_file_request (string msg, array(string) rxml_bt, array(array) bt,
|
282739 | 2000-03-26 | Martin Stjernholm | | string raw_bt_descr, string raw_url, string raw)
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
b07b5e | 2004-06-21 | Henrik Grubbström (Grubba) | |
string data;
foreach(bt, array frame) {
if (frame[0] == variables->file) {
data = Stdio.read_bytes(variables->file);
break;
}
}
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if(!data)
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | return error_page("Source file could not be read:", variables->file);
|
b07b5e | 2004-06-21 | Henrik Grubbström (Grubba) | |
|
86e77d | 1998-05-07 | Per Hedbor | | string down;
|
8641d4 | 2000-03-24 | Martin Stjernholm | | int next = (int) variables->off + 1;
|
86e77d | 1998-05-07 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if(next < sizeof (bt)) {
[string file, int line, string func, string descr] = bt[next];
down = link_to (file, line, func, (int) variables->error, next);
}
|
86e77d | 1998-05-07 | Per Hedbor | | else
down = "<a>";
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
int off = 49;
array (string) lines = data/"\n";
int start = (int)variables->line-50;
if(start < 0)
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
8641d4 | 2000-03-24 | Martin Stjernholm | | off += start;
start = 0;
}
int end = (int)variables->line+50;
|
86e77d | 1998-05-07 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
|
7dba2f | 2000-05-08 | Martin Nilsson | | lines = map (lines[start..end], Roxen.html_encode_string);
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
if(sizeof(lines)>off) {
sscanf (lines[off], "%[ \t]%s", string indent, string code);
if (!sizeof (code)) code = " ";
|
8986cf | 2004-06-21 | Jonas Wallden | | lines[off] = indent + "<font size='+1'><b>"+down+code+"</a></b></font>";
|
86e77d | 1998-05-07 | Per Hedbor | | }
|
8641d4 | 2000-03-24 | Martin Stjernholm | | lines[max(off-20,0)] = "<a name=here>"+lines[max(off-20,0)]+"</a>";
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
6cacf6 | 2006-03-10 | Martin Stjernholm | | return error_page("Source code for", variables->file, 0,
|
8986cf | 2004-06-21 | Jonas Wallden | | "<span class='code'><pre>" +
(lines * "\n") +
"</pre></span>");
|
86e77d | 1998-05-07 | Per Hedbor | | }
|
d98628 | 1999-06-30 | David Hedbor | |
#define BOUND "Byte_Me_Now_Roxen"
class MultiRangeWrapper
{
object file;
function rcb;
int current_pos, len, separator;
array ranges;
array range_info = ({});
string type;
string stored_data = "";
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | void create(mapping _file, array _ranges, array(string)|string t, object id)
|
d98628 | 1999-06-30 | David Hedbor | | {
file = _file->file;
len = _file->len;
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | if (arrayp(t)) type = t[-1];
else type = t;
|
d98628 | 1999-06-30 | David Hedbor | | ranges = _ranges;
int clen;
foreach(ranges, array range)
{
int rlen = 1+ range[1] - range[0];
|
84ae13 | 1999-07-28 | David Hedbor | | string sep = sprintf("\r\n--" BOUND "\r\nContent-Type: %s\r\n"
|
d98628 | 1999-06-30 | David Hedbor | | "Content-Range: bytes %d-%d/%d\r\n\r\n",
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | type, @range, len);
|
d98628 | 1999-06-30 | David Hedbor | | clen += rlen + strlen(sep);
range_info += ({ ({ rlen, sep }) });
}
clen += strlen(BOUND) + 8;
_file->len = clen;
}
string read(int num_bytes)
{
string out = stored_data;
int rlen, total = num_bytes;
num_bytes -= strlen(out);
|
037f4b | 1999-07-04 | David Hedbor | | stored_data = "";
|
d98628 | 1999-06-30 | David Hedbor | | foreach(ranges, array range)
{
rlen = range_info[0][0] - current_pos;
if(separator != 1) {
|
2ad0fd | 2006-11-08 | Henrik Grubbström (Grubba) | |
|
d98628 | 1999-06-30 | David Hedbor | | out += range_info[0][1];
num_bytes -= strlen(range_info[0][1]);
file->seek(range[0]);
separator = 1;
}
if(num_bytes > 0) {
if(rlen <= num_bytes)
{
out += file->read(rlen);
num_bytes -= rlen;
current_pos = separator = 0;
ranges = ranges[1..];
range_info = range_info[1..];
} else {
out += file->read(num_bytes);
current_pos += num_bytes;
num_bytes = 0;
}
}
|
30f032 | 1999-07-04 | David Hedbor | | if(num_bytes <= 0)
break;
|
d98628 | 1999-06-30 | David Hedbor | | }
|
037f4b | 1999-07-04 | David Hedbor | | if(!sizeof(ranges) && separator != 2) {
|
d98628 | 1999-06-30 | David Hedbor | | separator = 2;
out += "\r\n--" BOUND "--\r\n";
|
abdff2 | 1999-12-27 | Martin Nilsson | | }
|
d98628 | 1999-06-30 | David Hedbor | | if(strlen(out) > total)
{
stored_data = out[total..];
return out[..total-1];
}
return out ;
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
bceeba | 1999-07-05 | Henrik Grubbström (Grubba) | | mixed `->(string what)
{
|
d98628 | 1999-06-30 | David Hedbor | | switch(what) {
case "read":
return read;
case "set_nonblocking":
return 0;
|
30f032 | 1999-07-04 | David Hedbor | | case "query_fd":
|
bceeba | 1999-07-05 | Henrik Grubbström (Grubba) | | return lambda() { return -1; };
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
d98628 | 1999-06-30 | David Hedbor | | default:
return file[what];
}
}
}
|
9c1900 | 2001-02-27 | Per Hedbor | |
|
d98628 | 1999-06-30 | David Hedbor | | array parse_range_header(int len)
{
array ranges = ({});
foreach(misc->range / ",", string range)
{
int r1, r2;
if(range[0] == '-' ) {
r1 = (len - (int)range[1..]);
if(r1 < 0) {
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
d98628 | 1999-06-30 | David Hedbor | | r1 = 0;
}
|
feb680 | 2006-12-07 | Stefan Wallström | | ranges += ({ ({ r1, len-1 }) });
|
d98628 | 1999-06-30 | David Hedbor | | } else if(range[-1] == '-') {
r1 = (int)range;
if(r1 >= len)
|
abdff2 | 1999-12-27 | Martin Nilsson | | continue;
|
d98628 | 1999-06-30 | David Hedbor | | ranges += ({ ({ r1, len-1 }) });
} else if(sscanf(range, "%d-%d", r1, r2)==2) {
if(r1 <= r2) {
if(r1 >= len)
continue;
ranges += ({ ({ r1, r2 < len ? r2 : len -1 }) });
}
|
abdff2 | 1999-12-27 | Martin Nilsson | | else
|
d98628 | 1999-06-30 | David Hedbor | |
return 0;
} else
|
abdff2 | 1999-12-27 | Martin Nilsson | | return 0;
|
d98628 | 1999-06-30 | David Hedbor | | }
return ranges;
}
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | |
void handle_byte_ranges(mapping(string:mixed) file,
mapping(string:array(string)|string) variant_heads)
{
if(misc->range && file->len && (method == "GET") &&
(file->error == 200) && (objectp(file->file) || file->data))
{
array ranges = parse_range_header(file->len);
if(ranges)
{
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | NO_PROTO_CACHE();
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | if(sizeof(ranges))
{
m_delete(variant_heads, "Content-Length");
file->error = 206;
if(sizeof(ranges) == 1)
{
variant_heads["Content-Range"] = sprintf("bytes %d-%d/%d",
@ranges[0],
file->len);
if (objectp(file->file)) {
file->file->seek(ranges[0][0]);
} else {
file->data = file->data[ranges[0][0]..ranges[0][1]];
}
if(ranges[0][1] == (file->len - 1) &&
GLOBVAR(RestoreConnLogFull))
misc->_log_cheat_addition = ranges[0][0];
file->len = ranges[0][1] - ranges[0][0]+1;
} else {
array(string)|string content_type =
variant_heads["Content-Type"] || "application/octet-stream";
if(request_headers["request-range"]) {
variant_heads["Content-Type"] =
"multipart/x-byteranges; boundary=" BOUND;
} else {
variant_heads["Content-Type"] =
"multipart/byteranges; boundary=" BOUND;
}
if (objectp(file->file)) {
file->file = MultiRangeWrapper(file, ranges,
content_type, this_object());
} else {
array(string) res = allocate(sizeof(ranges)*3+1);
mapping(string:string) part_heads = ([
"Content-Type":content_type,
]);
int j;
foreach(ranges; int i; array(int) range) {
res[j++] = "\r\n--" BOUND "\r\n";
part_heads["Content-Range"] =
sprintf("bytes %d-%d/%d", @range, file->len);
|
f1a153 | 2008-12-09 | Stefan Wallström | |
|
6ac15f | 2008-12-09 | Stefan Wallström | |
|
f1a153 | 2008-12-09 | Stefan Wallström | | res[j++] = "Content-Type: "+part_heads["Content-Type"] + "\r\n" + "Content-Range: "+part_heads["Content-Range"] + "\r\n\r\n";
|
2ad0fd | 2006-11-08 | Henrik Grubbström (Grubba) | | res[j++] = file->data[range[0]..range[1]];
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | }
|
feb680 | 2006-12-07 | Stefan Wallström | | res[j++] = "\r\n--" BOUND "--\r\n";
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | file->len = sizeof(file->data = res * "");
}
}
|
214e60 | 2006-08-11 | Henrik Grubbström (Grubba) | | variant_heads["Content-Length"] = (string)file->len;
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | } else {
file->error = 416;
variant_heads["Content-Range"] = "*/"+file->len;
|
ed058f | 2010-05-26 | Henrik Grubbström (Grubba) | | file->file = file->type = file->len = 0;
file->data = "";
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | }
}
}
}
|
45b22b | 1998-10-26 | Henrik Grubbström (Grubba) | |
void ready_to_receive()
{
|
e1995f | 2003-12-29 | Henrik Grubbström (Grubba) | |
|
11171a | 2009-04-01 | Thomas Gusenleitner | | if (clientprot == "HTTP/1.1" && stringp(request_headers->expect) &&
(String.trim_all_whites(lower_case(request_headers->expect)) ==
"100-continue") && !my_fd_busy) {
|
96cf67 | 2009-01-15 | Martin Stjernholm | | string res = "HTTP/1.1 100 Continue\r\n\r\n";
#ifdef CONNECTION_DEBUG
werror ("HTTP[%s]: Response (length %d) =================================\n"
"%O\n", DEBUG_GET_FD, sizeof (res), res);
#else
REQUEST_WERR(sprintf("HTTP: Send %O", res));
#endif
my_fd->write (res);
}
|
45b22b | 1998-10-26 | Henrik Grubbström (Grubba) | | }
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | |
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | |
void low_send_result(string headers, string data, int|void len,
Stdio.File|void file)
{
|
7a2e7c | 2007-08-14 | Martin Stjernholm | |
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | if (!my_fd) {
do_log(0);
return;
}
|
4e40cc | 2010-06-30 | Henrik Grubbström (Grubba) | |
if (!data) data = "";
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | if (String.width (data) != 8) {
|
7a2e7c | 2007-08-14 | Martin Stjernholm | | int from, to;
foreach (data; from; int chr)
if (chr > 255)
break;
to = from + 1024;
from -= 1024;
error ("Attempt to send wide data: %s%O%s\n"
"Response mapping: %O\n"
"output_charset: %O\n",
from > 0 ? "..." : "",
data[from..to],
to < sizeof (data) ? "..." : "",
(this_program::file->data ?
this_program::file | (["data": "..."]) : this_program::file),
output_charset);
}
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | conf->hsent += sizeof(headers);
if(!kept_alive && (len > 0) &&
((sizeof(headers) + len) < (HTTP_BLOCKING_SIZE_THRESHOLD))) {
|
ae7900 | 2008-11-05 | Martin Stjernholm | | MY_TRACE_ENTER(sprintf("Sending blocking %d bytes of headers and "
"%d bytes of string data",
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | sizeof(headers), sizeof(data)));
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | TIMER_START(blocking_write);
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | if (sizeof(data) != len) {
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | data = data[..len-1];
}
if (file) {
data = file->read(len);
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | }
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | #ifdef CONNECTION_DEBUG
|
96cf67 | 2009-01-15 | Martin Stjernholm | | werror("HTTP[%s]: Blocking response (length %d) ======================\n"
|
7a1424 | 2009-01-07 | Martin Stjernholm | | "%O\n", DEBUG_GET_FD, sizeof (headers) + sizeof (data),
headers + data);
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | #else
REQUEST_WERR(sprintf("HTTP: Send blocking %O", headers + data));
#endif
int s = my_fd->write(({ headers, data }));
TIMER_END(blocking_write);
|
ae7900 | 2008-11-05 | Martin Stjernholm | | MY_TRACE_LEAVE(sprintf("Blocking write wrote %d bytes", s));
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | do_log(s);
} else {
|
ae7900 | 2008-11-05 | Martin Stjernholm | | MY_TRACE_ENTER(sprintf("Sending async %d bytes of headers and "
"%d bytes of string data",
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | sizeof(headers), sizeof(data)));
|
47a940 | 2008-05-09 | Martin Stjernholm | | #ifndef CONNECTION_DEBUG
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | REQUEST_WERR(sprintf("HTTP: Send headers %O", headers));
#endif
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | if (sizeof(headers))
|
47a940 | 2008-05-09 | Martin Stjernholm | | send(headers, 0,
#ifdef CONNECTION_DEBUG
1
#endif
);
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | if (sizeof(data))
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | send(data, len);
if (file)
send(file, len);
|
ae7900 | 2008-11-05 | Martin Stjernholm | |
MY_TRACE_LEAVE ("Async sender started");
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | start_sender();
}
}
|
56f695 | 2009-01-28 | Martin Jonsson | | #ifdef HTTP_COMPRESSION
|
c99371 | 2010-09-02 | Martin Jonsson | | #ifdef HTTP_COMPR_STREAM
class GzStreamingFile
{
protected Gz.deflate def;
protected Stdio.File srcfile;
protected string read_buf;
protected int crc;
protected int file_pos;
protected int at_eof;
protected int src_at_eof;
protected int trailer_written;
protected int level;
constant default_level = 7;
constant read_chunk_size = 1024*128;
void create (void|Stdio.File file, void|int level)
{
if (level)
this_program::level = level;
else
this_program::level = default_level;
if (file)
open (file);
}
int open (Stdio.File file)
{
read_buf = make_header();
file_pos = 0;
srcfile = file;
crc = Gz.crc32("");
at_eof = 0;
src_at_eof = 0;
trailer_written = 0;
def = Gz.deflate (-level, Gz.DEFAULT_STRATEGY);
return 1;
}
string read (int len)
{
String.Buffer buf = String.Buffer();
while (sizeof (read_buf) + sizeof (buf) < len && !src_at_eof) {
string chunk = srcfile->read (read_chunk_size);
if (sizeof (chunk) < read_chunk_size)
src_at_eof = 1;
buf->add (def->deflate (chunk, Gz.NO_FLUSH));
crc = Gz.crc32 (chunk, crc);
}
if (src_at_eof && !trailer_written) {
buf->add (def->deflate ("", Gz.FINISH));
buf->add (sprintf("%-4c%-4c", crc, srcfile->tell()));
trailer_written = 1;
}
read_buf += buf->get();
string result = read_buf[..len-1];
read_buf = read_buf[sizeof(result)..];
file_pos += sizeof (result);
if (src_at_eof && !sizeof (read_buf))
at_eof = 1;
return result;
}
int tell()
{
return file_pos;
}
int eof()
{
return at_eof;
}
int seek (int pos)
{
open (srcfile);
int offset;
while (offset + read_chunk_size < pos)
offset += sizeof (read (read_chunk_size));
read (pos-offset);
return file_pos;
}
string make_header()
{
return sprintf("%1c%1c%1c%1c%4c%1c%1c",
0x1f, 0x8b, 8, 0, 0, 0, 3);
|
ff7e93 | 2010-10-08 | Martin Jonsson | | }
string _sprintf()
{
return sprintf ("GzStreamingFile (%O)", srcfile);
}
|
c99371 | 2010-09-02 | Martin Jonsson | | }
#endif
|
01d9cb | 2010-05-19 | Arjan van Staalduijnen | | private int(0..1) compression_enabled_for_mimetype (string mimetype)
{
mapping(string:int) compress_exact_mimetypes = conf->http_compr_exact_mimes;
mapping(string:int) compress_main_mimetypes = conf->http_compr_main_mimes;
|
9016a8 | 2010-05-25 | Martin Jonsson | | if (mimetype)
mimetype = (mimetype / ";")[0];
|
01d9cb | 2010-05-19 | Arjan van Staalduijnen | |
return (conf->http_compr_enabled &&
mimetype &&
(compress_exact_mimetypes[mimetype] ||
(sscanf (mimetype, "%[^/]", string main_type) &&
compress_main_mimetypes[main_type])));
}
|
56f695 | 2009-01-28 | Martin Jonsson | | private string gzip_data(string data)
{
|
0b7815 | 2009-01-29 | Stephen R. van den Berg | | Stdio.FakeFile f = Stdio.FakeFile("", "wb");
|
56f695 | 2009-01-28 | Martin Jonsson | |
|
37820a | 2010-03-26 | Martin Jonsson | | Gz.File gzfile = conf->gz_file_pool->get();
|
56f695 | 2009-01-28 | Martin Jonsson | | if(!gzfile) {
|
0b7815 | 2009-01-29 | Stephen R. van den Berg | | gzfile = Gz.File(f, "wb");
|
56f695 | 2009-01-28 | Martin Jonsson | | gzfile->setparams(conf->query("http_compression_level"),
Gz.DEFAULT_STRATEGY);
|
37820a | 2010-03-26 | Martin Jonsson | | conf->gz_file_pool->set(gzfile);
|
56f695 | 2009-01-28 | Martin Jonsson | | } else {
|
0b7815 | 2009-01-29 | Stephen R. van den Berg | | gzfile->open(f, "wb");
|
56f695 | 2009-01-28 | Martin Jonsson | | }
gzfile->write(data);
gzfile->close();
return (string)f;
}
private string gunzip_data(string data)
{
|
0b7815 | 2009-01-29 | Stephen R. van den Berg | | Stdio.FakeFile f = Stdio.FakeFile(data, "rb");
|
56f695 | 2009-01-28 | Martin Jonsson | |
|
37820a | 2010-03-26 | Martin Jonsson | | Gz.File gzfile = conf->gz_file_pool->get();
|
56f695 | 2009-01-28 | Martin Jonsson | | if(!gzfile) {
|
0b7815 | 2009-01-29 | Stephen R. van den Berg | | gzfile = Gz.File(f, "rb");
|
56f695 | 2009-01-28 | Martin Jonsson | | gzfile->setparams(conf->query("http_compression_level"),
Gz.DEFAULT_STRATEGY);
|
37820a | 2010-03-26 | Martin Jonsson | | conf->gz_file_pool->set(gzfile);
|
56f695 | 2009-01-28 | Martin Jonsson | | } else {
|
0b7815 | 2009-01-29 | Stephen R. van den Berg | | gzfile->open(f, "rb");
|
56f695 | 2009-01-28 | Martin Jonsson | | }
string res = gzfile->read();
gzfile->close();
return res;
}
|
c99371 | 2010-09-02 | Martin Jonsson | | private
#ifdef HTTP_COMPR_STREAM
GzStreamingFile|
#endif
string try_gzip_data(Stdio.File|string data,
string mimetype)
|
56f695 | 2009-01-28 | Martin Jonsson | | {
int min_data_length = conf->http_compr_minlen;
int max_data_length = conf->http_compr_maxlen;
int len = sizeof(data);
|
c99371 | 2010-09-02 | Martin Jonsson | | if (compression_enabled_for_mimetype (mimetype)) {
if (stringp (data)) {
if (len >= min_data_length &&
(!max_data_length || len <= max_data_length)) {
data = gzip_data(data);
if (len>sizeof(data))
return data;
}
}
#ifdef HTTP_COMPR_STREAM
|
ff7e93 | 2010-10-08 | Martin Jonsson | | else if (objectp (data) && functionp (data->read) &&
functionp (data->tell)) {
|
c99371 | 2010-09-02 | Martin Jonsson | | return GzStreamingFile (data, conf->query ("http_compression_level"));
}
#endif
|
56f695 | 2009-01-28 | Martin Jonsson | | }
return 0;
}
private int(0..1) compress_dynamic_requests()
{
return conf->http_compr_dynamic_reqs;
}
private int(0..1) client_gzip_enabled()
{
|
b24351 | 2010-10-18 | Martin Jonsson | | array(string)|string accept_encoding = request_headers["accept-encoding"];
if (stringp (accept_encoding)) {
return has_value("," + lower_case(accept_encoding - " " - "\t") + ",",
",gzip,");
} else if (arrayp (accept_encoding)) {
foreach (accept_encoding, string ae) {
if (has_value("," + lower_case(ae - " " - "\t") + ",", ",gzip,"))
return 1;
}
}
|
c46b8e | 2009-01-28 | Jonas Wallden | | return 0;
|
56f695 | 2009-01-28 | Martin Jonsson | | }
#endif // HTTP_COMPRESSION
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | |
void send_result(mapping|void result)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(send_result);
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | if (my_fd)
CHECK_FD_SAFE_USE;
|
39202e | 2003-11-03 | Martin Stjernholm | |
|
3045db | 2009-09-21 | Martin Stjernholm | | destruct_threadbound_session_objects();
handle_time = gethrtime() - handle_time;
#if constant(System.CPU_TIME_IS_THREAD_LOCAL)
handle_vtime = gethrvtime() - handle_vtime;
#endif
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | array err;
|
26f44e | 2000-08-13 | Per Hedbor | | if (result)
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | file = result;
|
0d0e95 | 2000-11-13 | Per Hedbor | | #ifdef PROFILE
|
2923b6 | 2004-05-19 | Henrik Grubbström (Grubba) | | int elapsed = HRTIME()-req_time;
|
0d0e95 | 2000-11-13 | Per Hedbor | | string nid =
#ifdef FILE_PROFILE
(raw_url/"?")[0]
#else
dirname((raw_url/"?")[0])
#endif
|
2923b6 | 2004-05-19 | Henrik Grubbström (Grubba) | | + "?method="+method;
|
0d0e95 | 2000-11-13 | Per Hedbor | | array p;
|
2923b6 | 2004-05-19 | Henrik Grubbström (Grubba) | | if(!(p=conf->profile_map[nid])) {
p = conf->profile_map[nid] = ({0, 0, 0});
}
|
0d0e95 | 2000-11-13 | Per Hedbor | | p[0]++;
p[1] += elapsed;
if(elapsed > p[2]) p[2]=elapsed;
#endif
|
e57856 | 2002-12-18 | Henrik Grubbström (Grubba) | | REQUEST_WERR(sprintf("HTTP: response: prot %O, method %O, file %O, misc: %O",
prot, method, file, misc));
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
be9716 | 2003-11-25 | Anders Johansson | | #ifdef DEBUG_CACHEABLE
|
d894e8 | 2004-02-03 | Anders Johansson | | report_debug("<=== Request for %s returned cacheable %d (proto cache %s).\n",
raw_url, misc->cacheable,
misc->no_proto_cache ? "disabled" : "enabled");
|
be9716 | 2003-11-25 | Anders Johansson | | #endif
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | if( prot == "HTTP/0.9" ) NO_PROTO_CACHE();
|
5f6dae | 2000-08-13 | Per Hedbor | |
|
99b98b | 2000-08-14 | Per Hedbor | | if(!mappingp(file))
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | NO_PROTO_CACHE();
|
99b98b | 2000-08-14 | Per Hedbor | | if(misc->error_code)
|
1f5732 | 2008-05-07 | Martin Stjernholm | | file = Roxen.http_status(misc->error_code,
Roxen.http_status_messages[misc->error_code]);
|
99b98b | 2000-08-14 | Per Hedbor | | else if(err = catch {
|
73ce3d | 2000-12-11 | Per Hedbor | | file = conf->error_file( this_object() );
|
99b98b | 2000-08-14 | Per Hedbor | | })
|
2b40f4 | 1999-12-29 | Martin Stjernholm | | INTERNAL_ERROR(err);
|
99b98b | 2000-08-14 | Per Hedbor | | }
|
9b0f91 | 2004-04-20 | Martin Stjernholm | | else
{
if((file->file == -1) || file->leave_me)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
9b0f91 | 2004-04-20 | Martin Stjernholm | | TIMER_END(send_result);
file = 0;
pipe = 0;
|
b01723 | 2007-06-12 | Henrik Grubbström (Grubba) | | if (do_not_disconnect) return;
|
9b0f91 | 2004-04-20 | Martin Stjernholm | | my_fd = 0;
return;
|
5f6dae | 2000-08-13 | Per Hedbor | | }
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
9b0f91 | 2004-04-20 | Martin Stjernholm | | if(file->type == "raw") file->raw = 1;
}
|
c1413f | 2005-10-28 | Henrik Grubbström (Grubba) | |
|
27ef7f | 2005-11-18 | Henrik Grubbström (Grubba) | |
|
c1413f | 2005-10-28 | Henrik Grubbström (Grubba) | |
string head_string="";
string variant_string="";
|
27ef7f | 2005-11-18 | Henrik Grubbström (Grubba) | |
|
c1413f | 2005-10-28 | Henrik Grubbström (Grubba) | | string full_headers="";
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | #if 0
REQUEST_WERR(sprintf("HTTP: Sending result for prot:%O, method:%O, file:%O",
prot, method, file));
#endif
|
29abe6 | 2004-04-13 | Henrik Grubbström (Grubba) | | if(!file->raw && (prot != "HTTP/0.9"))
{
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | if (!sizeof (file) && multi_status)
file = multi_status->http_answer();
|
57de55 | 2004-05-05 | Martin Stjernholm | |
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | if (file->error == Protocols.HTTP.HTTP_NO_CONTENT) {
file->len = 0;
file->data = "";
}
|
edaa6f | 2001-02-01 | Per Hedbor | |
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | string head_status = file->rettext;
if (head_status) {
if (!file->file && !file->data &&
(!file->type || file->type == "text/html")) {
file->data = "<html><body>" +
replace (Roxen.html_encode_string (head_status), "\n", "<br />\n") +
"</body></html>";
file->len = sizeof (file->data);
file->type = "text/html";
|
29abe6 | 2004-04-13 | Henrik Grubbström (Grubba) | | }
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | if (has_value (head_status, "\n"))
head_status = map (head_status / "\n", String.trim_all_whites) * " ";
}
|
c2d7aa | 2004-04-13 | Martin Stjernholm | |
|
cf81c8 | 2009-01-29 | Martin Jonsson | | #ifdef HTTP_COMPRESSION
|
c0af64 | 2010-05-26 | Martin Jonsson | | if(compression_enabled_for_mimetype (get_response_content_type (file))) {
|
cf81c8 | 2009-01-29 | Martin Jonsson | |
if(!misc->vary)
|
e0bafe | 2009-04-17 | Martin Jonsson | | misc->vary = (< "accept-encoding" >);
|
cf81c8 | 2009-01-29 | Martin Jonsson | | else
|
e0bafe | 2009-04-17 | Martin Jonsson | | misc->vary["accept-encoding"] = 1;
|
cf81c8 | 2009-01-29 | Martin Jonsson | | }
#endif
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | mapping(string:string) heads = make_response_headers (file);
|
7fceff | 2005-11-28 | Henrik Grubbström (Grubba) | |
|
334414 | 2008-05-13 | Martin Stjernholm | |
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | mapping(string:string) variant_heads = ([ "Date":"",
"Content-Type":"",
"Content-Length":"",
|
94e9ac | 2005-12-05 | Henrik Grubbström (Grubba) | | "Connection":"",
"Expires":"",
|
334414 | 2008-05-13 | Martin Stjernholm | | "Cache-Control": "",
|
56f695 | 2009-01-28 | Martin Jonsson | | #ifdef HTTP_COMPRESSION
"Content-Encoding":"",
"ETag":"",
#endif
|
94e9ac | 2005-12-05 | Henrik Grubbström (Grubba) | | ]) & heads;
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | m_delete(heads, "Date");
m_delete(heads, "Content-Type");
m_delete(heads, "Content-Length");
m_delete(heads, "Connection");
|
94e9ac | 2005-12-05 | Henrik Grubbström (Grubba) | | m_delete(heads, "Expires");
|
334414 | 2008-05-13 | Martin Stjernholm | | m_delete(heads, "Cache-Control");
|
56f695 | 2009-01-28 | Martin Jonsson | | #ifdef HTTP_COMPRESSION
m_delete(heads, "Content-Encoding");
m_delete(heads, "ETag");
#endif
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | |
|
1f5732 | 2008-05-07 | Martin Stjernholm | | head_string = sprintf(" %s\r\n", head_status ||
Roxen.http_status_messages[file->error] || "");
|
2bfbd9 | 2004-04-13 | Martin Stjernholm | |
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | if (mixed err = catch(head_string += Roxen.make_http_headers(heads, 1)))
{
|
06e958 | 2009-09-22 | Martin Stjernholm | | report_debug("Roxen.make_http_headers failed on %O: %s",
heads, describe_error (err));
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | foreach(heads; string x; string|array(string) val) {
if( !arrayp( val ) ) val = ({val});
foreach( val, string xx ) {
if (!stringp (xx) && catch {xx = (string) xx;})
report_error("Error in request for %O:\n"
"Invalid value for header %O: %O\n",
raw_url, x, xx);
else if (String.width (xx) > 8)
report_error("Error in request for %O:\n"
"Invalid widestring value for header %O: %O\n",
raw_url, x, xx);
else
head_string += x+": "+xx+"\r\n";
}
|
c1413f | 2005-10-28 | Henrik Grubbström (Grubba) | | }
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | }
|
c1413f | 2005-10-28 | Henrik Grubbström (Grubba) | |
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | if (objectp(cookies)) {
|
abe6ce | 2006-08-16 | Henrik Grubbström (Grubba) | | real_cookies = cookies = ~cookies;
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | }
|
74da3d | 2008-01-10 | Martin Stjernholm | | int varies = misc->vary && (sizeof(misc->vary) - misc->vary["host"]);
|
5f6dae | 2000-08-13 | Per Hedbor | | #ifdef RAM_CACHE
|
451198 | 2006-09-21 | Henrik Grubbström (Grubba) | | if( (misc->cacheable > 0) && !misc->no_proto_cache)
{
if ((<"HEAD","GET">)[method]) {
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | if( file->len>0 &&
|
c1413f | 2005-10-28 | Henrik Grubbström (Grubba) | | ((file->len + sizeof(head_string)) <
|
0248d4 | 2004-05-25 | Martin Stjernholm | | conf->datacache->max_file_size)
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | && misc->cachekey )
|
0248d4 | 2004-05-25 | Martin Stjernholm | | {
misc->cachekey->activate();
string data = "";
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | if( file->data ) data = file->data[..file->len-1];
if( file->file ) data = file->file->read(file->len);
|
56f695 | 2009-01-28 | Martin Jonsson | |
#ifdef HTTP_COMPRESSION
string uncompressed = data;
string compressed;
|
ffc709 | 2009-05-07 | Stephen R. van den Berg | | string encoding = file->encoding;
if(!encoding) {
|
cda032 | 2009-04-17 | Stephen R. van den Berg | | if(compressed =
try_gzip_data(data, variant_heads["Content-Type"])) {
|
56f695 | 2009-01-28 | Martin Jonsson | | data = compressed;
|
ffc709 | 2009-05-07 | Stephen R. van den Berg | | encoding = "gzip";
|
56f695 | 2009-01-28 | Martin Jonsson | | }
}
#endif
|
526f5c | 2009-01-10 | Stephen R. van den Berg | | conf->datacache->set(misc->prot_cache_key, data,
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | | ([
"hs":head_string,
"key":misc->cachekey,
"etag":misc->etag,
"callbacks":misc->_cachecallbacks,
"len":file->len,
"raw":file->raw,
"error":file->error,
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | "type":variant_heads["Content-Type"],
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | | "last_modified":misc->last_modified,
|
94e9ac | 2005-12-05 | Henrik Grubbström (Grubba) | | "varies":varies,
"expires":variant_heads["Expires"],
|
334414 | 2008-05-13 | Martin Stjernholm | | "cache_control":variant_heads["Cache-Control"],
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | "mtime":(file->stat &&
file->stat[ST_MTIME]),
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | | "rf":realfile,
|
b418a4 | 2007-09-04 | Henrik Grubbström (Grubba) | | "refresh":predef::time(1) +
5 + 3*misc->cacheable/4,
|
56f695 | 2009-01-28 | Martin Jonsson | | #ifdef HTTP_COMPRESSION
|
ffc709 | 2009-05-07 | Stephen R. van den Berg | | "encoding" : encoding,
|
56f695 | 2009-01-28 | Martin Jonsson | | #endif
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | | ]),
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | misc->cacheable, this_object());
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | file = ([
|
56f695 | 2009-01-28 | Martin Jonsson | | #ifndef HTTP_COMPRESSION
"data":data,
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | "len":strlen(data),
|
56f695 | 2009-01-28 | Martin Jonsson | | #endif
"raw":file->raw,
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | "error":file->error,
|
29fc82 | 2006-10-27 | Henrik Grubbström (Grubba) | | "type":variant_heads["Content-Type"],
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | ]);
|
56f695 | 2009-01-28 | Martin Jonsson | |
#ifdef HTTP_COMPRESSION
|
cf81c8 | 2009-01-29 | Martin Jonsson | | if(!misc->range && compressed && client_gzip_enabled()) {
|
56f695 | 2009-01-28 | Martin Jonsson | | file->data = compressed;
file->encoding = encoding;
file->compressed = 1;
} else {
file->data = uncompressed;
}
file->len = sizeof(file->data);
variant_heads["Content-Length"] = (string)file->len;
#endif
|
970cc9 | 2006-04-20 | Henrik Grubbström (Grubba) | | cache_status["protstore"] = 1;
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | }
|
451198 | 2006-09-21 | Henrik Grubbström (Grubba) | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | #endif
|
451198 | 2006-09-21 | Henrik Grubbström (Grubba) | |
|
56f695 | 2009-01-28 | Martin Jonsson | | #ifdef HTTP_COMPRESSION
|
cf81c8 | 2009-01-29 | Martin Jonsson | |
|
c99371 | 2010-09-02 | Martin Jonsson | | if(!file->compressed && (file->data || file->file) && !misc->range &&
|
56f695 | 2009-01-28 | Martin Jonsson | | compress_dynamic_requests() && client_gzip_enabled()) {
|
c99371 | 2010-09-02 | Martin Jonsson | | if (mixed compressed =
try_gzip_data(file->data ? file->data : file->file, file->type)) {
if (file->data) {
file->data = compressed;
file->len = sizeof(file->data);
variant_heads["Content-Length"] = (string)file->len;
} else if (file->file) {
file->file = compressed;
m_delete (file, "len");
m_delete (variant_heads, "Content-Length");
}
|
56f695 | 2009-01-28 | Martin Jonsson | | file->encoding = "gzip";
|
c99371 | 2010-09-02 | Martin Jonsson | | file->compressed = 1;
|
56f695 | 2009-01-28 | Martin Jonsson | | }
}
|
375485 | 2009-01-29 | Martin Jonsson | |
if(file->compressed && misc->etag) {
string etag = misc->etag;
if(etag[sizeof(etag)-1..] == "\"")
misc->etag = etag[..sizeof(etag)-2] + ";gzip\"";
}
|
56f695 | 2009-01-28 | Martin Jonsson | | #endif
|
451198 | 2006-09-21 | Henrik Grubbström (Grubba) | |
if( file->error/100 == 2 && file->len <= 0 )
{
variant_heads->Connection = "close";
misc->connection = "close";
}
if (file->error == 200) {
int conditional;
if (none_match) {
if (none_match[misc->etag] || (misc->etag && none_match["*"])) {
if ((<"HEAD", "GET">)[method]) {
conditional = 304;
} else {
conditional = 412;
}
} else {
conditional = -1;
}
|
94e9ac | 2005-12-05 | Henrik Grubbström (Grubba) | | }
|
451198 | 2006-09-21 | Henrik Grubbström (Grubba) | | if(since && misc->last_modified && (conditional >= 0))
{
array(int) since_info = Roxen.parse_since( since );
if ( ((since_info[0] >= misc->last_modified) &&
((since_info[1] == -1) || (since_info[1] == file->len)))
&& (zero_type(misc->cacheable) ||
(misc->cacheable >= INITIAL_CACHEABLE))
)
{
conditional = conditional || 304;
} else {
conditional = -1;
}
}
if (conditional > 0) {
file->error = conditional;
file->file = file->data = file->len = 0;
variant_heads["Content-Length"] = "0";
}
}
if (varies && (prot == "HTTP/1.0")) {
|
49681e | 2006-12-14 | Henrik Grubbström (Grubba) | | #ifndef DISABLE_VARY_EXPIRES_FALLBACK
|
451198 | 2006-09-21 | Henrik Grubbström (Grubba) | | variant_heads["Expires"] = Roxen->http_date(predef::time(1)-31557600);
|
49681e | 2006-12-14 | Henrik Grubbström (Grubba) | | #endif /* !DISABLE_VARY_EXPIRES_FALLBACK */
|
451198 | 2006-09-21 | Henrik Grubbström (Grubba) | | }
if( (method == "HEAD") || (file->error == 204) || (file->error == 304) ||
(file->error < 200))
{
file->len = 1;
file->data = "";
file->file = 0;
} else {
|
56f695 | 2009-01-28 | Martin Jonsson | | #ifdef HTTP_COMPRESSION
if(misc->etag)
variant_heads["ETag"] = misc->etag;
if(file->encoding)
variant_heads["Content-Encoding"] = file->encoding;
#endif
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | if (misc->range) {
|
c6f7be | 2005-11-28 | Henrik Grubbström (Grubba) | | int skip;
string if_range;
if (if_range = request_headers["if-range"]) {
if (has_prefix(if_range, "\"")) {
if (if_range != misc->etag) {
skip = 1;
}
} else {
array(int) since_info = Roxen.parse_since(if_range);
if (!since_info || (since_info[0] < misc->last_modified)) {
skip = 1;
}
}
}
if (!skip) {
handle_byte_ranges(file, variant_heads);
}
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | }
|
0248d4 | 2004-05-25 | Martin Stjernholm | |
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | variant_string = Roxen.make_http_headers(variant_heads);
full_headers = prot + " " + file->error + head_string + variant_string;
low_send_result(full_headers, file->data, file->len, file->file);
}
else {
if(!file->type) file->type="text/plain";
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | |
|
a5c6e9 | 2005-11-25 | Henrik Grubbström (Grubba) | | low_send_result("", file->data, file->len, file->file);
}
MARK_FD("HTTP handled");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(send_result);
|
14179b | 1997-01-29 | Per Hedbor | | }
|
cea62a | 2010-08-19 | Martin Stjernholm | |
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | void handle_request( )
{
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: handle_request()");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(handle_request);
|
24a43a | 2009-06-10 | Martin Stjernholm | |
queue_time = gethrtime() - queue_time;
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | #ifdef MAGIC_ERROR
if(prestate->old_error)
{
|
d8947f | 2002-07-03 | Henrik Grubbström (Grubba) | | array err = get_error(variables->error, variables->error_md5 || "NONE");
|
84732f | 2002-07-02 | Anders Johansson | | if(err && arrayp(err))
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | {
if(prestate->plain)
{
file = ([
|
282739 | 2000-03-26 | Martin Stjernholm | | "type":"text/plain",
|
f28818 | 1998-05-25 | Per Hedbor | | "data":generate_bugreport( @err ),
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | ]);
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(handle_request);
|
8a80d4 | 1999-05-20 | Per Hedbor | | send_result();
return;
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | } else {
if(prestate->find_file)
{
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (!roxen.configuration_authenticate (this_object(), "View Settings"))
|
7dba2f | 2000-05-08 | Martin Nilsson | | file = Roxen.http_auth_required("admin");
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | else
|
8641d4 | 2000-03-24 | Martin Stjernholm | | file = ([
"type":"text/html",
"data":handle_error_file_request( @err ),
]);
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(handle_request);
|
8a80d4 | 1999-05-20 | Per Hedbor | | send_result();
return;
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | }
}
}
}
#endif /* MAGIC_ERROR */
MARK_FD("HTTP handling request");
|
24a43a | 2009-06-10 | Martin Stjernholm | | handle_time = gethrtime();
#if constant(System.CPU_TIME_IS_THREAD_LOCAL)
handle_vtime = gethrvtime();
#endif
|
c51f2b | 2003-11-03 | Martin Stjernholm | | mapping result;
|
24a43a | 2009-06-10 | Martin Stjernholm | | array e = catch(result = conf->handle_request( this_object() ));
|
3045db | 2009-09-21 | Martin Stjernholm | |
|
cea62a | 2010-08-19 | Martin Stjernholm | |
if (this)
destruct_threadbound_session_objects();
|
24a43a | 2009-06-10 | Martin Stjernholm | |
if(e)
|
5496fd | 2003-09-17 | Henrik Grubbström (Grubba) | | INTERNAL_ERROR( e );
|
c51f2b | 2003-11-03 | Martin Stjernholm | |
|
f0e7bc | 2004-01-19 | Martin Stjernholm | | else {
|
9e67a4 | 2007-06-12 | Henrik Grubbström (Grubba) | | if (result && result->pipe) {
REQUEST_WERR("HTTP: handle_request: pipe in progress.");
TIMER_END(handle_request);
|
f0e7bc | 2004-01-19 | Martin Stjernholm | | return;
|
9e67a4 | 2007-06-12 | Henrik Grubbström (Grubba) | | }
|
f0e7bc | 2004-01-19 | Martin Stjernholm | | file = result;
}
|
c51f2b | 2003-11-03 | Martin Stjernholm | |
if( file && file->try_again_later )
{
if( objectp( file->try_again_later ) )
;
else
call_out( roxen.handle, file->try_again_later, handle_request );
|
9e67a4 | 2007-06-12 | Henrik Grubbström (Grubba) | | TIMER_END(handle_request);
|
c51f2b | 2003-11-03 | Martin Stjernholm | | return;
|
d7e1b4 | 2003-06-16 | Henrik Grubbström (Grubba) | | }
|
c51f2b | 2003-11-03 | Martin Stjernholm | |
|
3088b1 | 2003-07-16 | Henrik Grubbström (Grubba) | | TIMER_END(handle_request);
send_result();
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | }
|
14179b | 1997-01-29 | Per Hedbor | | |
abdff2 | 1999-12-27 | Martin Nilsson | | * =================================================
|
14179b | 1997-01-29 | Per Hedbor | | */
|
0d0e95 | 2000-11-13 | Per Hedbor | |
|
4a9840 | 2004-08-18 | Martin Stjernholm | | void got_data(mixed fooid, string s, void|int chained)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
acd724 | 2004-04-27 | Martin Stjernholm | | #ifdef CONNECTION_DEBUG
|
1139a1 | 2006-10-13 | Martin Stjernholm | | werror ("HTTP[%s]: Request ----------------------------------------------\n"
|
7a1424 | 2009-01-07 | Martin Stjernholm | | "%O\n", DEBUG_GET_FD, s);
|
acd724 | 2004-04-27 | Martin Stjernholm | | #else
|
f136c2 | 2002-02-26 | Martin Stjernholm | | REQUEST_WERR(sprintf("HTTP: Got %O", s));
|
acd724 | 2004-04-27 | Martin Stjernholm | | #endif
|
d0739e | 2002-02-14 | Henrik Grubbström (Grubba) | |
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | |
raw_bytes += sizeof(s);
|
0d0e95 | 2000-11-13 | Per Hedbor | | if(wanted_data)
|
d042a8 | 2000-08-31 | Per Hedbor | | {
|
ae2d0e | 2002-11-18 | Henrik Grubbström (Grubba) | |
|
0d0e95 | 2000-11-13 | Per Hedbor | | if(strlen(s) + have_data < wanted_data)
|
d042a8 | 2000-08-31 | Per Hedbor | | {
|
ae2d0e | 2002-11-18 | Henrik Grubbström (Grubba) | | if (!data_buffer) {
|
f133c6 | 2002-11-18 | Henrik Grubbström (Grubba) | |
data_buffer = String.Buffer(wanted_data + 16384);
|
ae2d0e | 2002-11-18 | Henrik Grubbström (Grubba) | | data_buffer->add(data);
data = "";
}
data_buffer->add(s);
|
0d0e95 | 2000-11-13 | Per Hedbor | | have_data += strlen(s);
|
ae2d0e | 2002-11-18 | Henrik Grubbström (Grubba) | |
|
4a9840 | 2004-08-18 | Martin Stjernholm | | REQUEST_WERR("HTTP: We want more data.");
|
e8c710 | 2002-07-10 | Anders Johansson | |
remove_call_out(do_timeout);
call_out(do_timeout, 90);
|
4a9840 | 2004-08-18 | Martin Stjernholm | |
if (chained)
my_fd->set_nonblocking(got_data, 0, close_cb);
|
0d0e95 | 2000-11-13 | Per Hedbor | | return;
}
|
ae2d0e | 2002-11-18 | Henrik Grubbström (Grubba) | | if (data_buffer) {
data_buffer->add(s);
|
1752c3 | 2003-04-22 | Dan Nelson | | data = data_buffer->get();
|
ae2d0e | 2002-11-18 | Henrik Grubbström (Grubba) | | data_buffer = 0;
} else {
data += s;
}
|
3e3f20 | 2009-06-03 | Henrik Grubbström (Grubba) | | } else if (misc->chunked) {
if (!got_chunk_fragment(s)) {
REQUEST_WERR("HTTP: We want more data (chunked).");
remove_call_out(do_timeout);
call_out(do_timeout, 90);
if (chained)
my_fd->set_nonblocking(got_data, 0, close_cb);
return;
}
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | s = "";
|
d042a8 | 2000-08-31 | Per Hedbor | | }
|
acd34a | 2000-01-22 | Martin Stjernholm | | if (mixed err = catch {
|
26b0b9 | 2001-10-02 | Per Hedbor | | MARK_FD("HTTP got data");
raw += s;
|
0d0e95 | 2000-11-13 | Per Hedbor | |
|
26b0b9 | 2001-10-02 | Per Hedbor | |
if( !port_obj )
|
14179b | 1997-01-29 | Per Hedbor | | {
|
b611c6 | 2002-03-27 | Per Hedbor | | if( conf )
conf->connection_drop( this_object() );
|
93aa10 | 2003-11-17 | Martin Stjernholm | | MARK_FD ("HTTP: Port closed.");
call_out (disconnect, 0);
|
26b0b9 | 2001-10-02 | Per Hedbor | | return;
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
26b0b9 | 2001-10-02 | Per Hedbor | | switch( parse_got( s ) )
{
case 0:
REQUEST_WERR("HTTP: Request needs more data.");
|
4a9840 | 2004-08-18 | Martin Stjernholm | | if (chained)
my_fd->set_nonblocking(got_data, 0, close_cb);
|
26b0b9 | 2001-10-02 | Per Hedbor | | return;
|
26f44e | 2000-08-13 | Per Hedbor | |
|
96cf67 | 2009-01-15 | Martin Stjernholm | | case 1: {
string res = (prot||"HTTP/1.0")+" 500 Illegal request\r\n"
"Content-Length: 0\r\n"+
"Date: "+Roxen.http_date(predef::time())+"\r\n"
"\r\n";
#ifdef CONNECTION_DEBUG
werror ("HTTP[%s]: Response (length %d) =================================\n"
"%O\n", DEBUG_GET_FD, sizeof (res), res);
#else
|
f136c2 | 2002-02-26 | Martin Stjernholm | | REQUEST_WERR("HTTP: Stupid Client Error.");
|
96cf67 | 2009-01-15 | Martin Stjernholm | | #endif
my_fd->write (res);
|
26b0b9 | 2001-10-02 | Per Hedbor | | end();
return;
|
96cf67 | 2009-01-15 | Martin Stjernholm | | }
|
26b0b9 | 2001-10-02 | Per Hedbor | |
case 2:
|
f136c2 | 2002-02-26 | Martin Stjernholm | | REQUEST_WERR("HTTP: Done.");
|
26b0b9 | 2001-10-02 | Per Hedbor | | end();
return;
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
acd724 | 2004-04-27 | Martin Stjernholm | | #ifdef CONNECTION_DEBUG
|
1139a1 | 2006-10-13 | Martin Stjernholm | | werror ("HTTP[%s]: Request received -------------------------------------\n",
DEBUG_GET_FD);
|
acd724 | 2004-04-27 | Martin Stjernholm | | #endif
|
be9716 | 2003-11-25 | Anders Johansson | | if( method == "GET" || method == "HEAD" ) {
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | |
|
26b0b9 | 2001-10-02 | Per Hedbor | | misc->cacheable = INITIAL_CACHEABLE;
|
be9716 | 2003-11-25 | Anders Johansson | | #ifdef DEBUG_CACHEABLE
report_debug("===> Request for %s initiated cacheable to %d.\n", raw_url,
misc->cacheable);
#endif
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
26b0b9 | 2001-10-02 | Per Hedbor | | TIMER_START(find_conf);
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | |
|
26b0b9 | 2001-10-02 | Per Hedbor | | string path;
|
a2a5aa | 2000-08-31 | Per Hedbor | |
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | |
|
526f5c | 2009-01-10 | Stephen R. van den Berg | | misc->prot_cache_key = raw_url;
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | | if (has_prefix(raw_url, port_obj->url_prefix)) {
sscanf(raw_url[sizeof(port_obj->url_prefix)..], "%[^/]%s",
misc->host, raw_url);
}
|
198594 | 2009-01-21 | Martin Stjernholm | |
string canon_hostport;
if (string host = misc->host) {
int port = port_obj->default_port;
if (has_prefix(host, "[")) {
|
dc8928 | 2008-12-11 | Jonas Wallden | |
|
198594 | 2009-01-21 | Martin Stjernholm | | sscanf(lower_case(host), "[%s]:%d", host, port);
host = Protocols.IPv6.normalize_addr_basic (host) || host;
canon_hostport = "[" + host + "]:" + port;
|
dc8928 | 2008-12-11 | Jonas Wallden | | } else {
|
198594 | 2009-01-21 | Martin Stjernholm | | sscanf(lower_case(host), "%[^:]:%d", host, port);
canon_hostport = host + ":" + port;
|
dc8928 | 2008-12-11 | Jonas Wallden | | }
|
198594 | 2009-01-21 | Martin Stjernholm | | misc->hostname = host;
misc->port = port;
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | | }
|
198594 | 2009-01-21 | Martin Stjernholm | |
|
8b07f9 | 2005-11-24 | Henrik Grubbström (Grubba) | | if( !conf || !(path = port_obj->path ) ||
(sizeof( path ) && !has_prefix(raw_url, path)) ) {
|
26b0b9 | 2001-10-02 | Per Hedbor | |
|
0b0322 | 2001-11-14 | Henrik Grubbström (Grubba) | |
|
198594 | 2009-01-21 | Martin Stjernholm | | string port_match_url = (port_obj->url_prefix +
(canon_hostport || ("*:" + port_obj->port)) +
raw_url);
|
526f5c | 2009-01-10 | Stephen R. van den Berg | | conf = port_obj->find_configuration_for_url(port_match_url, this);
if (misc->defaulted_conf > 1)
misc->prot_cache_key = port_match_url;
|
26b0b9 | 2001-10-02 | Per Hedbor | | }
else if( strlen(path) )
adjust_for_config_path( path );
|
0aee22 | 2000-08-15 | Martin Stjernholm | |
|
26b0b9 | 2001-10-02 | Per Hedbor | | TIMER_END(find_conf);
|
26f44e | 2000-08-13 | Per Hedbor | |
|
8e89b0 | 2008-10-10 | Martin Stjernholm | |
foreach (conf->get_providers ("http_request_init"), RoxenModule mod)
if (mapping res = mod->http_request_init (this)) {
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | conf->received += raw_bytes - sizeof(leftovers);
|
8e89b0 | 2008-10-10 | Martin Stjernholm | | conf->requests++;
if (!supports) supports = (<>);
send_result (res);
return;
}
|
26b0b9 | 2001-10-02 | Per Hedbor | | if (rawauth)
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
26b0b9 | 2001-10-02 | Per Hedbor | |
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | NO_PROTO_CACHE();
|
26b0b9 | 2001-10-02 | Per Hedbor | | array(string) y = rawauth / " ";
realauth = 0;
auth = 0;
if (sizeof(y) >= 2)
{
y[1] = MIME.decode_base64(y[1]);
realauth = y[1];
}
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
26b0b9 | 2001-10-02 | Per Hedbor | | if( misc->proxyauth )
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
26b0b9 | 2001-10-02 | Per Hedbor | |
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | NO_PROTO_CACHE();
|
26b0b9 | 2001-10-02 | Per Hedbor | | if (sizeof(misc->proxyauth) >= 2)
{
|
2a7405 | 2009-04-28 | Henrik Grubbström (Grubba) | |
|
26b0b9 | 2001-10-02 | Per Hedbor | | if (conf->auth_module)
misc->proxyauth
= conf->auth_module->auth(misc->proxyauth,this_object() );
}
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
2154ca | 1997-08-31 | Per Hedbor | |
|
b611c6 | 2002-03-27 | Per Hedbor | | conf->connection_add( this_object(), connection_stats );
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | conf->received += raw_bytes - sizeof(leftovers);
|
26b0b9 | 2001-10-02 | Per Hedbor | | conf->requests++;
|
39202e | 2003-11-03 | Martin Stjernholm | |
CHECK_FD_SAFE_USE;
|
26b0b9 | 2001-10-02 | Per Hedbor | | my_fd->set_close_callback(0);
my_fd->set_read_callback(0);
|
5f6dae | 2000-08-13 | Per Hedbor | |
|
26b0b9 | 2001-10-02 | Per Hedbor | | remove_call_out(do_timeout);
|
5f6dae | 2000-08-13 | Per Hedbor | | #ifdef RAM_CACHE
|
26b0b9 | 2001-10-02 | Per Hedbor | | TIMER_START(cache_lookup);
array cv;
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | if(misc->cacheable && !misc->no_proto_cache &&
|
526f5c | 2009-01-10 | Stephen R. van den Berg | | (cv = conf->datacache->get(misc->prot_cache_key, this)) )
|
99b98b | 2000-08-14 | Per Hedbor | | {
|
526f5c | 2009-01-10 | Stephen R. van den Berg | | MY_TRACE_ENTER(sprintf("Checking entry %O", misc->prot_cache_key));
|
26b0b9 | 2001-10-02 | Per Hedbor | | if( !cv[1]->key ) {
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | | MY_TRACE_LEAVE("Entry invalid due to zero key");
|
526f5c | 2009-01-10 | Stephen R. van den Berg | | conf->datacache->expire_entry(misc->prot_cache_key, this);
|
c3c632 | 2000-09-20 | Per Hedbor | | }
|
26b0b9 | 2001-10-02 | Per Hedbor | | else
|
0a900b | 2000-08-17 | Per Hedbor | | {
|
26b0b9 | 2001-10-02 | Per Hedbor | | int can_cache = 1;
string d = cv[ 0 ];
|
c7429a | 2009-04-17 | Martin Stjernholm | | #ifdef DEBUG
if (!stringp (d))
error ("Strange value from data cache for %O: %O\n", raw_url, cv);
#endif
|
26b0b9 | 2001-10-02 | Per Hedbor | | file = cv[1];
if( sizeof(file->callbacks) )
{
if( mixed e = catch
{
foreach( file->callbacks, function f ) {
|
814fbc | 2007-09-21 | Henrik Grubbström (Grubba) | | if (!file->key) break;
|
ae7900 | 2008-11-05 | Martin Stjernholm | | MY_TRACE_ENTER (sprintf ("Checking with %O", f));
|
b01723 | 2007-06-12 | Henrik Grubbström (Grubba) | | if( !f(this_object(), file->key ) )
|
26b0b9 | 2001-10-02 | Per Hedbor | | {
MY_TRACE_LEAVE ("Entry invalid according to callback");
MY_TRACE_LEAVE ("");
can_cache = 0;
break;
}
MY_TRACE_LEAVE ("");
}
} )
{
|
3e333f | 2006-01-02 | Henrik Grubbström (Grubba) | |
if (e = catch {
werror("Cache callback internal server error:\n"
"%s\n",
describe_backtrace(e));
|
b01723 | 2007-06-12 | Henrik Grubbström (Grubba) | | destruct(file->key);
|
3e333f | 2006-01-02 | Henrik Grubbström (Grubba) | | }) {
INTERNAL_ERROR( e );
TIMER_END(cache_lookup);
send_result();
return;
}
|
26b0b9 | 2001-10-02 | Per Hedbor | | }
}
|
814fbc | 2007-09-21 | Henrik Grubbström (Grubba) | | if(roxen.invalidp(file->key))
|
26b0b9 | 2001-10-02 | Per Hedbor | | {
|
814fbc | 2007-09-21 | Henrik Grubbström (Grubba) | |
if (!file->key) {
MY_TRACE_LEAVE ("Entry invalid due to zero key");
|
526f5c | 2009-01-10 | Stephen R. van den Berg | | conf->datacache->expire_entry(misc->prot_cache_key, this);
|
814fbc | 2007-09-21 | Henrik Grubbström (Grubba) | | can_cache = 0;
|
a82cb5 | 2008-04-28 | Martin Stjernholm | | } else {
cache_status["stale"] = 1;
if (file->refresh > predef::time(1)) {
if (m_delete(file, "refresh")) {
file->refresh = predef::time(1);
}
|
814fbc | 2007-09-21 | Henrik Grubbström (Grubba) | | }
}
}
|
26b0b9 | 2001-10-02 | Per Hedbor | | if( can_cache )
{
|
a2a5aa | 2000-08-31 | Per Hedbor | | #ifndef RAM_CACHE_ASUME_STATIC_CONTENT
|
26b0b9 | 2001-10-02 | Per Hedbor | | Stat st;
if( !file->rf || !file->mtime ||
((st = file_stat( file->rf )) && st->mtime == file->mtime ))
|
a2a5aa | 2000-08-31 | Per Hedbor | | #endif
|
26b0b9 | 2001-10-02 | Per Hedbor | | {
|
814fbc | 2007-09-21 | Henrik Grubbström (Grubba) | | int refresh;
if (file->refresh && (file->refresh <= predef::time(1))) {
|
7329de | 2007-09-12 | Henrik Grubbström (Grubba) | |
|
814fbc | 2007-09-21 | Henrik Grubbström (Grubba) | | if (refresh = m_delete(file, "refresh")) {
|
7329de | 2007-09-12 | Henrik Grubbström (Grubba) | | refresh = 1 + predef::time(1) - refresh;
}
|
b01723 | 2007-06-12 | Henrik Grubbström (Grubba) | | }
|
27ef7f | 2005-11-18 | Henrik Grubbström (Grubba) | | int code = file->error;
int len = sizeof(d);
|
56f695 | 2009-01-28 | Martin Jonsson | | mapping(string:string) variant_heads = ([]);
#ifdef HTTP_COMPRESSION
|
9cc355 | 2009-05-05 | Martin Jonsson | | if(file->etag)
variant_heads["ETag"] = file->etag;
|
56f695 | 2009-01-28 | Martin Jonsson | | if(file->encoding == "gzip") {
|
cf81c8 | 2009-01-29 | Martin Jonsson | | if(!misc->range && client_gzip_enabled()) {
|
56f695 | 2009-01-28 | Martin Jonsson | | variant_heads["Content-Encoding"] = file->encoding;
if(file->etag) {
string etag = file->etag;
|
655ae9 | 2009-03-21 | Martin Stjernholm | | if(etag[sizeof(etag)-1..] == "\"")
|
56f695 | 2009-01-28 | Martin Jonsson | | etag = etag[..sizeof(etag)-2] + ";gzip\"";
variant_heads["ETag"] = etag;
}
} else {
d = gunzip_data(d);
len = sizeof(d);
}
}
#endif
|
c24a48 | 2005-12-13 | Anders Johansson | |
file += ([]);
|
65e9af | 2008-02-28 | Jonas Wallden | | if (none_match) {
if (none_match[file->etag] || (none_match["*"] && file->etag)) {
code = 304;
d = "";
len = 0;
}
|
e4ae73 | 2007-08-28 | Arjan van Staalduijnen | | } else if (since && file->last_modified) {
|
27ef7f | 2005-11-18 | Henrik Grubbström (Grubba) | | array(int) since_info = Roxen.parse_since( since );
if ((since_info[0] >= file->last_modified) &&
((since_info[1] == -1) ||
(since_info[1] == len))) {
code = 304;
d = "";
len = 0;
}
}
|
c24a48 | 2005-12-13 | Anders Johansson | | file->error = code;
|
27ef7f | 2005-11-18 | Henrik Grubbström (Grubba) | | if (method == "HEAD") {
d = "";
}
|
56f695 | 2009-01-28 | Martin Jonsson | | variant_heads += ([
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | "Date":Roxen.http_date(predef::time(1)),
"Content-Length":(string)len,
"Content-Type":file->type,
|
3ce2fa | 2005-12-05 | Henrik Grubbström (Grubba) | | "Connection":misc->connection,
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | ]);
|
334414 | 2008-05-13 | Martin Stjernholm | |
if (cache_status->stale) {
variant_heads["Cache-Control"] = "no-cache";
variant_heads["Warning"] = "110 " +
replace (my_fd->query_address (1) || "roxen", " ", ":") +
" \"Response is stale - update is underway\" "
"\"" + variant_heads["Date"] + "\"";
}
else if (string cc = file->cache_control)
variant_heads["Cache-Control"] = cc;
|
c691fe | 2005-12-07 | Henrik Grubbström (Grubba) | | string expires;
|
334414 | 2008-05-13 | Martin Stjernholm | | if (expires = (cache_status->stale
|
802115 | 2008-05-12 | Henrik Grubbström (Grubba) | | #ifndef DISABLE_VARY_EXPIRES_FALLBACK
|
334414 | 2008-05-13 | Martin Stjernholm | | || (file->varies && (prot == "HTTP/1.0"))
|
802115 | 2008-05-12 | Henrik Grubbström (Grubba) | | #endif /* !DISABLE_VARY_EXPIRES_FALLBACK */
|
334414 | 2008-05-13 | Martin Stjernholm | | ? Roxen->http_date(predef::time(1)-31557600) :
|
c691fe | 2005-12-07 | Henrik Grubbström (Grubba) | | file->expires)) {
variant_heads["Expires"] = expires;
}
|
451198 | 2006-09-21 | Henrik Grubbström (Grubba) | |
if( file->error/100 == 2 && file->len <= 0 )
{
variant_heads->Connection = "close";
misc->connection = "close";
}
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | if (misc->range) {
|
c6f7be | 2005-11-28 | Henrik Grubbström (Grubba) | | int skip;
string if_range;
if (if_range = request_headers["if-range"]) {
if (has_prefix(if_range, "\"")) {
if (if_range != file->etag) {
skip = 1;
}
} else {
array(int) since_info = Roxen.parse_since(if_range);
if (!since_info || (since_info[0] < file->last_modified)) {
skip = 1;
}
}
}
if (!skip) {
file->data = d;
file->len = len;
handle_byte_ranges(file, variant_heads);
d = file->data;
code = file->error;
}
|
496c84 | 2005-11-25 | Henrik Grubbström (Grubba) | | }
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | string full_headers = "";
if (prot != "HTTP/0.9") {
full_headers = prot + " " + code + file->hs +
Roxen.make_http_headers(variant_heads);
}
|
c1413f | 2005-10-28 | Henrik Grubbström (Grubba) | |
|
433771 | 2008-01-09 | Martin Stjernholm | | MY_TRACE_LEAVE ("Using entry from protocol cache");
|
26b0b9 | 2001-10-02 | Per Hedbor | | cache_status["protcache"] = 1;
|
3d2ce8 | 2005-11-24 | Henrik Grubbström (Grubba) | |
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | if (!refresh) {
|
7329de | 2007-09-12 | Henrik Grubbström (Grubba) | |
|
0c272f | 2009-03-17 | Martin Jonsson | |
if (objectp(cookies)) {
real_cookies = cookies = ~cookies;
}
|
354cdd | 2007-09-04 | Henrik Grubbström (Grubba) | | TIMER_END(cache_lookup);
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | low_send_result(full_headers, d, sizeof(d));
return;
}
RequestID id = clone_me();
id->hrtime = hrtime;
id->my_fd = my_fd;
id->file = file;
id->kept_alive = kept_alive;
id->cache_status = cache_status + (<>);
id->eval_status = eval_status + (<>);
id->output_charset = output_charset;
id->input_charset = input_charset;
id->auth = auth;
id->throttle = throttle + ([]);
id->throttler = throttler;
conf->connection_add( id, connection_stats );
|
354cdd | 2007-09-04 | Henrik Grubbström (Grubba) | | TIMER_END(cache_lookup);
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | id->low_send_result(full_headers, d, sizeof(d));
|
61cb19 | 2008-01-08 | Martin Stjernholm | |
|
802115 | 2008-05-12 | Henrik Grubbström (Grubba) | | method = "GET";
|
61cb19 | 2008-01-08 | Martin Stjernholm | | remoteaddr = "127.0.0.1";
host = 0;
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | | my_fd = 0;
|
7329de | 2007-09-12 | Henrik Grubbström (Grubba) | | misc->connection = "close";
|
f2eaa3 | 2007-09-03 | Henrik Grubbström (Grubba) | |
|
b01723 | 2007-06-12 | Henrik Grubbström (Grubba) | | MY_TRACE_ENTER (
|
334414 | 2008-05-13 | Martin Stjernholm | | sprintf("Starting refresh of stale entry "
|
ae7900 | 2008-11-05 | Martin Stjernholm | | "(%d seconds past refresh time)", refresh - 1));
|
b01723 | 2007-06-12 | Henrik Grubbström (Grubba) | | cache_status["protcache"] = 0;
cache_status["refresh"] = 1;
|
a82cb5 | 2008-04-28 | Martin Stjernholm | | cache_status["stale"] = 0;
|
b01723 | 2007-06-12 | Henrik Grubbström (Grubba) | | MY_TRACE_LEAVE("");
|
26b0b9 | 2001-10-02 | Per Hedbor | | }
|
773ac6 | 2001-03-20 | Martin Stjernholm | | #ifndef RAM_CACHE_ASUME_STATIC_CONTENT
|
26b0b9 | 2001-10-02 | Per Hedbor | | else
MY_TRACE_LEAVE (
sprintf ("Entry out of date (disk: %s, cache: mtime %d)",
st ? "mtime " + st->mtime : "gone", file->mtime));
|
773ac6 | 2001-03-20 | Martin Stjernholm | | #endif
|
d7427c | 2006-04-20 | Henrik Grubbström (Grubba) | | }
|
26b0b9 | 2001-10-02 | Per Hedbor | | file = 0;
}
|
99b98b | 2000-08-14 | Per Hedbor | | }
|
26b0b9 | 2001-10-02 | Per Hedbor | | TIMER_END(cache_lookup);
|
46d4cb | 2001-08-22 | Martin Stjernholm | | #endif // RAM_CACHE
|
26b0b9 | 2001-10-02 | Per Hedbor | | TIMER_START(parse_request);
|
dcc895 | 2001-10-09 | Marcus Wellhardh | | if( things_to_do_when_not_sending_from_cache( ) )
return;
|
9caa2d | 2003-03-31 | Martin Stjernholm | | REQUEST_WERR(sprintf("HTTP: cooked headers %O", request_headers));
REQUEST_WERR(sprintf("HTTP: cooked variables %O", real_variables));
REQUEST_WERR(sprintf("HTTP: cooked cookies %O", cookies));
|
26b0b9 | 2001-10-02 | Per Hedbor | | TIMER_END(parse_request);
|
a86c3b | 2000-08-28 | Per Hedbor | |
|
f136c2 | 2002-02-26 | Martin Stjernholm | | REQUEST_WERR("HTTP: Calling roxen.handle().");
|
24a43a | 2009-06-10 | Martin Stjernholm | | queue_time = gethrtime();
|
e82400 | 2009-06-24 | Martin Stjernholm | | queue_length = roxen.handle_queue_length();
|
26b0b9 | 2001-10-02 | Per Hedbor | | roxen.handle(handle_request);
|
653d7d | 2000-02-14 | Per Hedbor | | })
{
|
acd34a | 2000-01-22 | Martin Stjernholm | | report_error("Internal server error: " + describe_backtrace(err));
disconnect();
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
abdff2 | 1999-12-27 | Martin Nilsson | | |
b1fca0 | 1996-11-12 | Per Hedbor | | * 'simulated' requests. */
object clone_me()
{
|
14179b | 1997-01-29 | Per Hedbor | | object c,t;
|
a3ebea | 2000-08-12 | Per Hedbor | | c=object_program(t=this_object())(0, port_obj, conf);
|
cbe6c6 | 2000-03-18 | Martin Stjernholm | | #ifdef ID_OBJ_DEBUG
|
8bf31a | 2000-03-20 | Martin Stjernholm | | werror ("clone %O -> %O\n", t, c);
|
cbe6c6 | 2000-03-18 | Martin Stjernholm | | #endif
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
0e5b1a | 1999-10-10 | Per Hedbor | | c->port_obj = port_obj;
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->conf = conf;
|
ae727d | 2001-07-16 | Martin Nilsson | | c->root_id = root_id;
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->time = time;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->raw_url = raw_url;
|
99cb5e | 2001-02-05 | Per Hedbor | |
c->real_variables = copy_value( real_variables );
c->variables = FakedVariables( c->real_variables );
|
a2a5aa | 2000-08-31 | Per Hedbor | | c->misc = copy_value( misc );
|
48fa36 | 1997-04-05 | Per Hedbor | | c->misc->orig = t;
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
99e65a | 2003-06-18 | Tomas Nilsson | | c->connection_misc = connection_misc;
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->prestate = prestate;
c->supports = supports;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->config = config;
|
dc5f17 | 2000-04-28 | Martin Nilsson | | c->client_var = client_var;
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->remoteaddr = remoteaddr;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->host = host;
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->client = client;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->referer = referer;
c->pragma = pragma;
|
11be9a | 2009-04-28 | Martin Jonsson | | if (objectp(cookies)) {
c->cookies = c->CookieJar(real_cookies + ([]));
|
2a7405 | 2009-04-28 | Henrik Grubbström (Grubba) | | } else if (cookies) {
c->cookies = c->real_cookies = real_cookies + ([]);
|
11be9a | 2009-04-28 | Martin Jonsson | | } else {
|
e70c75 | 2009-04-28 | Henrik Grubbström (Grubba) | | c->cookies = c->real_cookies = 0;
|
11be9a | 2009-04-28 | Martin Jonsson | | }
|
e47407 | 2004-05-13 | Henrik Grubbström (Grubba) | | c->request_headers = request_headers + ([]);
|
f6d62d | 1997-03-26 | Per Hedbor | | c->my_fd = 0;
c->prot = prot;
|
1afe37 | 1997-06-12 | Henrik Grubbström (Grubba) | | c->clientprot = clientprot;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->method = method;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
f6d62d | 1997-03-26 | Per Hedbor | | c->rest_query = rest_query;
c->raw = raw;
|
e885f7 | 2010-06-29 | Henrik Grubbström (Grubba) | | c->raw_bytes = raw_bytes;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->query = query;
c->not_query = not_query;
c->data = data;
|
746c3b | 1998-09-16 | Peter J. Holzer | | c->extra_extension = extra_extension;
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->auth = auth;
c->realauth = realauth;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->rawauth = rawauth;
c->since = since;
|
b1fca0 | 1996-11-12 | Per Hedbor | | return c;
}
void clean()
{
|
4b71f5 | 1998-03-25 | David Hedbor | | if(!(my_fd && objectp(my_fd)))
end();
|
e2df6a | 2001-01-03 | Per Hedbor | | else if((predef::time(1) - time) > 4800)
|
323569 | 1998-03-26 | Per Hedbor | | end();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create(object f, object c, object cc)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
14179b | 1997-01-29 | Per Hedbor | | if(f)
{
|
db38c1 | 2005-03-01 | Henrik Grubbström (Grubba) | | #if 0
|
5678e1 | 2003-11-04 | Martin Stjernholm | | if (f->query_accept_callback)
|
1050aa | 2004-02-20 | Martin Stjernholm | | f->set_nonblocking(got_data, f->query_write_callback(), close_cb, 0, 0,
|
5678e1 | 2003-11-04 | Martin Stjernholm | | f->query_accept_callback());
else
|
db38c1 | 2005-03-01 | Henrik Grubbström (Grubba) | | #endif /* 0 */
|
1050aa | 2004-02-20 | Martin Stjernholm | | f->set_nonblocking(got_data, f->query_write_callback(), close_cb);
|
14179b | 1997-01-29 | Per Hedbor | | my_fd = f;
|
f0e7bc | 2004-01-19 | Martin Stjernholm | | CHECK_FD_SAFE_USE;
|
f136c2 | 2002-02-26 | Martin Stjernholm | | MARK_FD("HTTP connection");
|
a3ebea | 2000-08-12 | Per Hedbor | | if( c ) port_obj = c;
if( cc ) conf = cc;
|
e2df6a | 2001-01-03 | Per Hedbor | | time = predef::time(1);
|
e40934 | 2006-09-21 | Marcus Wellhardh | | hrtime = gethrtime();
|
491abc | 2000-08-17 | Per Hedbor | | call_out(do_timeout, 90);
|
14179b | 1997-01-29 | Per Hedbor | | }
|
ae727d | 2001-07-16 | Martin Nilsson | | root_id = this_object();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
ceb927 | 1997-05-15 | David Hedbor | |
|
ebb1c5 | 1998-02-24 | Per Hedbor | | void chain(object f, object c, string le)
{
my_fd = f;
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | |
|
5cf99d | 2005-11-18 | Henrik Grubbström (Grubba) | | #if defined(DEBUG) && defined(THREADS)
|
4a9840 | 2004-08-18 | Martin Stjernholm | | if (this_thread() != roxen->backend_thread)
error ("Not called from backend\n");
#endif
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | | CHECK_FD_SAFE_USE;
|
870a9e | 1999-10-04 | Per Hedbor | | port_obj = c;
|
f136c2 | 2002-02-26 | Martin Stjernholm | | MARK_FD("HTTP kept alive");
|
a9feea | 2003-11-03 | Martin Stjernholm | | time = predef::time();
|
8e5fa4 | 2006-09-21 | Marcus Wellhardh | | hrtime = 0;
|
5f6dae | 2000-08-13 | Per Hedbor | |
|
b692e0 | 2004-08-11 | Henrik Grubbström (Grubba) | | if ( le && strlen( le ) ) {
REQUEST_WERR(sprintf("HTTP: %d bytes left over.\n", sizeof(le)));
|
4a9840 | 2004-08-18 | Martin Stjernholm | | got_data(0, le, 1);
|
b692e0 | 2004-08-11 | Henrik Grubbström (Grubba) | | }
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | | else
{
remove_call_out(do_timeout);
call_out(do_timeout, 90);
|
4a9840 | 2004-08-18 | Martin Stjernholm | |
my_fd->set_nonblocking(got_data, 0, close_cb);
|
b30340 | 2004-08-11 | Henrik Grubbström (Grubba) | | }
|
ebb1c5 | 1998-02-24 | Per Hedbor | | }
|
08bd3c | 1999-11-02 | Per Hedbor | |
|
84fb68 | 2000-02-03 | Per Hedbor | | Stdio.File connection( )
{
return my_fd;
}
Configuration configuration()
{
return conf;
}
|