Request — A HTTP request

class smisk.core.Request
A HTTP request

Instance attributes

smisk.core.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
smisk.core.Request.error
Type:Stream
smisk.core.Request.env

HTTP transaction environment.

Type:dict
smisk.core.Request.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
smisk.core.Request.get

Parameters passed in the query string part of the URL

Type:dict
smisk.core.Request.post

Parameters passed in the body of a POST request

Type:dict
smisk.core.Request.files

Any files uploaded via a POST request

Type:dict
smisk.core.Request.cookies

Any cookies that was attached to the request

Type:dict
smisk.core.Request.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
smisk.core.Request.session_id

Current session id

Type:string
smisk.core.Request.is_active

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

Type:bool
smisk.core.Request.referring_url

New in version 1.1.

Type:URL

Instance methods

smisk.core.Request.log_error(message)

Log something through error including process name and id.

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