89
89
# HTTP status codes
92
HTTP_SWITCHING_PROTOCOLS = 101
97
HTTP_NON_AUTHORITATIVE = 203
99
HTTP_RESET_CONTENT = 205
100
HTTP_PARTIAL_CONTENT = 206
101
HTTP_MULTI_STATUS = 207
102
HTTP_MULTIPLE_CHOICES = 300
103
HTTP_MOVED_PERMANENTLY = 301
92
104
HTTP_MOVED_TEMPORARILY = 302
106
HTTP_NOT_MODIFIED = 304
108
HTTP_TEMPORARY_REDIRECT = 307
109
HTTP_BAD_REQUEST = 400
110
HTTP_UNAUTHORIZED = 401
111
HTTP_PAYMENT_REQUIRED = 402
93
112
HTTP_FORBIDDEN = 403
94
113
HTTP_NOT_FOUND = 404
114
HTTP_METHOD_NOT_ALLOWED = 405
115
HTTP_NOT_ACCEPTABLE = 406
116
HTTP_PROXY_AUTHENTICATION_REQUIRED= 407
117
HTTP_REQUEST_TIME_OUT = 408
120
HTTP_LENGTH_REQUIRED = 411
121
HTTP_PRECONDITION_FAILED = 412
122
HTTP_REQUEST_ENTITY_TOO_LARGE = 413
123
HTTP_REQUEST_URI_TOO_LARGE = 414
124
HTTP_UNSUPPORTED_MEDIA_TYPE = 415
125
HTTP_RANGE_NOT_SATISFIABLE = 416
126
HTTP_EXPECTATION_FAILED = 417
127
HTTP_UNPROCESSABLE_ENTITY = 422
129
HTTP_FAILED_DEPENDENCY = 424
95
130
HTTP_INTERNAL_SERVER_ERROR = 500
131
HTTP_NOT_IMPLEMENTED = 501
132
HTTP_BAD_GATEWAY = 502
133
HTTP_SERVICE_UNAVAILABLE = 503
134
HTTP_GATEWAY_TIME_OUT = 504
135
HTTP_VERSION_NOT_SUPPORTED = 505
136
HTTP_VARIANT_ALSO_VARIES = 506
137
HTTP_INSUFFICIENT_STORAGE = 507
138
HTTP_NOT_EXTENDED = 510
97
140
def __init__(self, req, config):
98
141
"""Create an IVLE request from a mod_python one.
118
161
self.uri = req.uri
119
162
# Split the given path into the app (top-level dir) and sub-path
120
163
# (after first stripping away the root directory)
121
(self.app, self.path) = (ivle.util.split_path(req.uri))
164
path = self.unmake_path(req.uri)
165
(self.app, self.path) = (ivle.util.split_path(path))
123
167
self.hostname = req.hostname
124
168
self.headers_in = req.headers_in
238
282
return os.path.join(self.config['urls']['root'], path)
284
def unmake_path(self, path):
285
"""Strip the IVLE URL prefix from the given path, if present.
287
Also normalises the path.
289
This method is DEPRECATED. We no longer support use of a prefix.
291
path = os.path.normpath(path)
292
root = os.path.normpath(self.config['urls']['root'])
294
if path.startswith(root):
295
path = path[len(root):]
296
# Take out the slash as well
297
if len(path) > 0 and path[0] == os.sep:
240
302
def get_session(self):
241
303
"""Returns a mod_python Session object for this request.
242
304
Note that this is dependent on mod_python and may need to change
269
331
self.got_common_vars = True
270
332
return self.apache_req.subprocess_env
335
def get_http_codename(code):
336
"""Given a HTTP error code int, returns a (name, description)
337
pair, suitable for displaying to the user.
338
May return (None,None) if code is unknown.
339
Only lists common 4xx and 5xx codes (since this is just used
340
to display throw_error error messages).
343
return http_codenames[code]
347
# Human strings for HTTP response codes
349
Request.HTTP_BAD_REQUEST:
351
"Your browser sent a request IVLE did not understand."),
352
Request.HTTP_UNAUTHORIZED:
354
"You are not allowed to view this part of IVLE."),
355
Request.HTTP_FORBIDDEN:
357
"You are not allowed to view this part of IVLE."),
358
Request.HTTP_NOT_FOUND:
360
"The application or file you requested does not exist."),
361
Request.HTTP_METHOD_NOT_ALLOWED:
362
("Method Not Allowed",
363
"Your browser is interacting with IVLE in the wrong way."
364
"This is probably a bug in IVLE. "
365
"Please report it to the administrators."),
366
Request.HTTP_INTERNAL_SERVER_ERROR:
367
("Internal Server Error",
368
"An unknown error occured in IVLE."),
369
Request.HTTP_NOT_IMPLEMENTED:
371
"The application or file you requested has not been implemented "
373
Request.HTTP_SERVICE_UNAVAILABLE:
374
("Service Unavailable",
375
"IVLE is currently experiencing technical difficulties. "
376
"Please try again later."),