# ``twisted`.`web`.`http`.`HTTPFactory``

class documentation

`class HTTPFactory(protocol.ServerFactory): (source)`

Known subclasses: `twisted.web.server.Site`

View In Hierarchy

Factory for HTTP server.

Method | `__init__` |
Method | `buildProtocol` | Create an instance of a subclass of Protocol.
Method | `log` | Write a line representing `request` to the access log file.
Method | `startFactory` | Set up request logging if necessary.
Method | `stopFactory` | This will be called before I stop listening on all Ports/Connectors.
Instance Variable | `logFile` | Undocumented
Instance Variable | `logPath` | Undocumented
Instance Variable | `reactor` | An `IReactorTime` provider used to manage connection timeouts and compute logging timestamps.
Instance Variable | `timeOut` | Undocumented
Method | `_openLogFile` | Override in subclasses, e.g. to use `twisted.python.logfile`.
Method | `_updateLogDateTime` | Update log datetime periodically, so we aren't always recalculating it.
Instance Variable | `_logDateTime` | A cached datetime string for log messages, updated by `_logDateTimeCall`.
Instance Variable | `_logDateTimeCall` | A delayed call for the next update to the cached log datetime string.
Instance Variable | `_logFormatter` | See the `logFormatter` parameter to `__init__`
Instance Variable | `_nativeize` | A flag that indicates whether the log file being written to wants native strings (`True`) or bytes (`False`). This is only to support writing to `twisted.python.log` which, unfortunately, works with native strings.

Inherited from `Factory` (via `ServerFactory`):

Class Method | `forProtocol` | Create a factory for the given protocol.
Method | `doStart` | Make sure startFactory is called.
Method | `doStop` | Make sure stopFactory is called.
Method | `logPrefix` | Describe this factory for log messages.
Class Variable | `noisy` | Undocumented
Class Variable | `protocol` | Undocumented
Instance Variable | `numPorts` | Undocumented

def __init__(self, logPath=None, timeout=_REQUEST_TIMEOUT, logFormatter=None, reactor=None): (source)
overridden in `twisted.web.server.Site`

Parameters
logPath:`str` or `bytes` | File path to which access log messages will be written or `None` to disable logging.
timeout:`float` | The initial value of `timeOut`, which defines the idle connection timeout in seconds, or `None` to disable the idle timeout.
logFormatter:`IAccessLogFormatter` provider | An object to format requests into log lines for the access log. `combinedLogFormatter` when `None` is passed.
reactor | An `IReactorTime` provider used to manage connection timeouts and compute logging timestamps. Defaults to the global reactor.

def buildProtocol(self, addr): (source)
from `twisted.internet.interfaces.IProtocolFactory`
overrides `twisted.internet.protocol.Factory.buildProtocol`
overridden in `twisted.web.server.Site`

Create an instance of a subclass of Protocol.

The returned instance will handle input on an incoming server connection, and an attribute "factory" pointing to the creating factory.

Alternatively, `None` may be returned to immediately close the new connection.

Override this method to alter how Protocol instances get created.

Parameters
addr | an object implementing `IAddress`

def log(self, request): (source)
Write a line representing `request` to the access log file.

Parameters
request:`Request` | The request object about which to log.

def startFactory(self): (source)
overrides `twisted.internet.protocol.Factory.startFactory`
Set up request logging if necessary.
def stopFactory(self): (source)
overrides `twisted.internet.protocol.Factory.stopFactory`

This will be called before I stop listening on all Ports/Connectors.

This can be overridden to perform 'shutdown' tasks such as disconnecting database connections, closing files, etc.

It will be called, for example, before an application shuts down, if it was connected to a port. User code should not call this function directly.

logFile = (source)

Undocumented

logPath = (source)

Undocumented

reactor = (source)
An `IReactorTime` provider used to manage connection timeouts and compute logging timestamps.
timeOut = (source)

Undocumented

def _openLogFile(self, path): (source)
overridden in `twisted.web.server.Site`
Override in subclasses, e.g. to use `twisted.python.logfile`.
def _updateLogDateTime(self): (source)
Update log datetime periodically, so we aren't always recalculating it.
_logDateTime: `str` = (source)
A cached datetime string for log messages, updated by `_logDateTimeCall`.
_logDateTimeCall: `IDelayedCall` provided = (source)
A delayed call for the next update to the cached log datetime string.
_logFormatter = (source)
See the `logFormatter` parameter to `__init__`
_nativeize = (source)
A flag that indicates whether the log file being written to wants native strings (`True`) or bytes (`False`). This is only to support writing to `twisted.python.log` which, unfortunately, works with native strings.