Request — A HTTP request

class smisk.core.Request

A HTTP request

input

Input stream.

If you send any data which is neither x-www-form-urlencoded nor multipart format, you will be able to read the raw POST body from this stream.

You could read x-www-form-urlencoded or multipart POST requests in raw format, but you have to read from this stream before calling any of post or files, since they will otherwise trigger the built-in parser and read all data from the stream.

Example, parsing a JSON request:

from smisk.core import *
from smisk.serialization.json import json_decode
class App(Application):
  def service(self):
    if request.env['REQUEST_METHOD'] == 'POST':
      response('Input: ', repr(json_decode(self.request.input.read())), "\n")

App().run()

You could then send a request using curl for example:

curl --data-binary '{"Url": "http://www.example.com/image/481989943", "Position": [125, "100"]}' http://localhost:8080/
Type:Stream
error
Type:Stream
env

HTTP transaction environment.

Type:dict
url

Reconstructed URL

For example; if you need to know if running under SSL:

if request.url.scheme == 'https':
  response('Secure connection')
else:
  response('Big brother is watching you')
Type:URL
get

Parameters passed in the query string part of the URL

Type:dict
post

Parameters passed in the body of a POST request

Type:dict
files

Any files uploaded via a POST request

Type:dict
cookies

Any cookies that was attached to the request

Type:dict
session

Current session.

Any modifications to the session must be done before output has begun, as it will add a Set-Cookie: header to the response.

Type:object
session_id

Current session id

Type:str
is_active

Indicates if the request is active, if we are in the middle of a HTTP transaction

Type:bool
referring_url

New in version 1.1.

Type:URL
method

New in version 1.1.1.

HTTP method (“GET”, “POST”, etc.).

See:RFC 2616, HTTP 1.1, Method Definitions
Type:str
max_multipart_size

New in version 1.1.2.

Limits the amount of data which Smisk normally automatically parses received in a POST or PUT request. For example uploaded files.

Only applies to payloads with a mime-type matching :samp:`multipart/*‘ – if the payload is defined as another media type, is form data or does not specify a content type – Smisk will not touch the input thus no limits apply (it’s up to the code which eventually read the input to set limits).

System Message: WARNING/2 (/Users/rasmus/src/smisk/docs/source/library/smisk.core.Request.rst, line 138); backlink

Inline interpreted text or phrase reference start-string without end-string.

System Message: WARNING/2 (/Users/rasmus/src/smisk/docs/source/library/smisk.core.Request.rst, line 138); backlink

Inline emphasis start-string without end-string.

Setting the value to -1 or lower disables the limit. Note that this is different from max_formdata_size (which can no be disabled).

Setting the value to 0 (zero) disables automatic multipart parsing (any multipart input will be left intact/unread).

Type:long
Default:2147483648 (2 GB)
See:max_formdata_size.
max_formdata_size

New in version 1.1.2.

Limits the amount of data which Smisk will accept in a */x-www-form-urlencoded payload.

Setting the value to 0 (zero) disables automatic form data parsing (any form data input will be left intact/unread).

Note that – in contrast to max_multipart_size – this limit can not be disabled, only adjusted.

Type:long
Default:10737418 (10 MB)
See:max_multipart_size
log_error(message)

Log something through error including process name and id.

Normally, error ends up in the host server error log.