You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

iweb.py 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. # -*- test-case-name: twisted.web.test -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Interface definitions for L{twisted.web}.
  6. @var UNKNOWN_LENGTH: An opaque object which may be used as the value of
  7. L{IBodyProducer.length} to indicate that the length of the entity
  8. body is not known in advance.
  9. """
  10. from zope.interface import Interface, Attribute
  11. from twisted.internet.interfaces import IPushProducer
  12. from twisted.cred.credentials import IUsernameDigestHash
  13. class IRequest(Interface):
  14. """
  15. An HTTP request.
  16. @since: 9.0
  17. """
  18. method = Attribute("A L{bytes} giving the HTTP method that was used.")
  19. uri = Attribute(
  20. "A L{bytes} giving the full encoded URI which was requested (including"
  21. " query arguments).")
  22. path = Attribute(
  23. "A L{bytes} giving the encoded query path of the request URI (not "
  24. "including query arguments).")
  25. args = Attribute(
  26. "A mapping of decoded query argument names as L{bytes} to "
  27. "corresponding query argument values as L{list}s of L{bytes}. "
  28. "For example, for a URI with C{foo=bar&foo=baz&quux=spam} "
  29. "for its query part, C{args} will be C{{b'foo': [b'bar', b'baz'], "
  30. "b'quux': [b'spam']}}.")
  31. prepath = Attribute(
  32. "The URL path segments which have been processed during resource "
  33. "traversal, as a list of {bytes}.")
  34. postpath = Attribute(
  35. "The URL path segments which have not (yet) been processed "
  36. "during resource traversal, as a list of L{bytes}.")
  37. requestHeaders = Attribute(
  38. "A L{http_headers.Headers} instance giving all received HTTP request "
  39. "headers.")
  40. content = Attribute(
  41. "A file-like object giving the request body. This may be a file on "
  42. "disk, an L{io.BytesIO}, or some other type. The implementation is "
  43. "free to decide on a per-request basis.")
  44. responseHeaders = Attribute(
  45. "A L{http_headers.Headers} instance holding all HTTP response "
  46. "headers to be sent.")
  47. def getHeader(key):
  48. """
  49. Get an HTTP request header.
  50. @type key: L{bytes} or L{str}
  51. @param key: The name of the header to get the value of.
  52. @rtype: L{bytes} or L{str} or L{None}
  53. @return: The value of the specified header, or L{None} if that header
  54. was not present in the request. The string type of the result
  55. matches the type of C{key}.
  56. """
  57. def getCookie(key):
  58. """
  59. Get a cookie that was sent from the network.
  60. @type key: L{bytes}
  61. @param key: The name of the cookie to get.
  62. @rtype: L{bytes} or L{None}
  63. @returns: The value of the specified cookie, or L{None} if that cookie
  64. was not present in the request.
  65. """
  66. def getAllHeaders():
  67. """
  68. Return dictionary mapping the names of all received headers to the last
  69. value received for each.
  70. Since this method does not return all header information,
  71. C{requestHeaders.getAllRawHeaders()} may be preferred.
  72. """
  73. def getRequestHostname():
  74. """
  75. Get the hostname that the user passed in to the request.
  76. This will either use the Host: header (if it is available) or the
  77. host we are listening on if the header is unavailable.
  78. @returns: the requested hostname
  79. @rtype: L{str}
  80. """
  81. def getHost():
  82. """
  83. Get my originally requesting transport's host.
  84. @return: An L{IAddress<twisted.internet.interfaces.IAddress>}.
  85. """
  86. def getClientAddress():
  87. """
  88. Return the address of the client who submitted this request.
  89. The address may not be a network address. Callers must check
  90. its type before using it.
  91. @since: 18.4
  92. @return: the client's address.
  93. @rtype: an L{IAddress} provider.
  94. """
  95. def getClientIP():
  96. """
  97. Return the IP address of the client who submitted this request.
  98. This method is B{deprecated}. See L{getClientAddress} instead.
  99. @returns: the client IP address or L{None} if the request was submitted
  100. over a transport where IP addresses do not make sense.
  101. @rtype: L{str} or L{None}
  102. """
  103. def getUser():
  104. """
  105. Return the HTTP user sent with this request, if any.
  106. If no user was supplied, return the empty string.
  107. @returns: the HTTP user, if any
  108. @rtype: L{str}
  109. """
  110. def getPassword():
  111. """
  112. Return the HTTP password sent with this request, if any.
  113. If no password was supplied, return the empty string.
  114. @returns: the HTTP password, if any
  115. @rtype: L{str}
  116. """
  117. def isSecure():
  118. """
  119. Return True if this request is using a secure transport.
  120. Normally this method returns True if this request's HTTPChannel
  121. instance is using a transport that implements ISSLTransport.
  122. This will also return True if setHost() has been called
  123. with ssl=True.
  124. @returns: True if this request is secure
  125. @rtype: C{bool}
  126. """
  127. def getSession(sessionInterface=None):
  128. """
  129. Look up the session associated with this request or create a new one if
  130. there is not one.
  131. @return: The L{Session} instance identified by the session cookie in
  132. the request, or the C{sessionInterface} component of that session
  133. if C{sessionInterface} is specified.
  134. """
  135. def URLPath():
  136. """
  137. @return: A L{URLPath<twisted.python.urlpath.URLPath>} instance
  138. which identifies the URL for which this request is.
  139. """
  140. def prePathURL():
  141. """
  142. At any time during resource traversal or resource rendering,
  143. returns an absolute URL to the most nested resource which has
  144. yet been reached.
  145. @see: {twisted.web.server.Request.prepath}
  146. @return: An absolute URL.
  147. @type: L{bytes}
  148. """
  149. def rememberRootURL():
  150. """
  151. Remember the currently-processed part of the URL for later
  152. recalling.
  153. """
  154. def getRootURL():
  155. """
  156. Get a previously-remembered URL.
  157. @return: An absolute URL.
  158. @type: L{bytes}
  159. """
  160. # Methods for outgoing response
  161. def finish():
  162. """
  163. Indicate that the response to this request is complete.
  164. """
  165. def write(data):
  166. """
  167. Write some data to the body of the response to this request. Response
  168. headers are written the first time this method is called, after which
  169. new response headers may not be added.
  170. @param data: Bytes of the response body.
  171. @type data: L{bytes}
  172. """
  173. def addCookie(k, v, expires=None, domain=None, path=None, max_age=None, comment=None, secure=None):
  174. """
  175. Set an outgoing HTTP cookie.
  176. In general, you should consider using sessions instead of cookies, see
  177. L{twisted.web.server.Request.getSession} and the
  178. L{twisted.web.server.Session} class for details.
  179. """
  180. def setResponseCode(code, message=None):
  181. """
  182. Set the HTTP response code.
  183. @type code: L{int}
  184. @type message: L{bytes}
  185. """
  186. def setHeader(k, v):
  187. """
  188. Set an HTTP response header. Overrides any previously set values for
  189. this header.
  190. @type k: L{bytes} or L{str}
  191. @param k: The name of the header for which to set the value.
  192. @type v: L{bytes} or L{str}
  193. @param v: The value to set for the named header. A L{str} will be
  194. UTF-8 encoded, which may not interoperable with other
  195. implementations. Avoid passing non-ASCII characters if possible.
  196. """
  197. def redirect(url):
  198. """
  199. Utility function that does a redirect.
  200. The request should have finish() called after this.
  201. """
  202. def setLastModified(when):
  203. """
  204. Set the C{Last-Modified} time for the response to this request.
  205. If I am called more than once, I ignore attempts to set Last-Modified
  206. earlier, only replacing the Last-Modified time if it is to a later
  207. value.
  208. If I am a conditional request, I may modify my response code to
  209. L{NOT_MODIFIED<http.NOT_MODIFIED>} if appropriate for the time given.
  210. @param when: The last time the resource being returned was modified, in
  211. seconds since the epoch.
  212. @type when: L{int}, L{long} or L{float}
  213. @return: If I am a C{If-Modified-Since} conditional request and the time
  214. given is not newer than the condition, I return
  215. L{CACHED<http.CACHED>} to indicate that you should write no body.
  216. Otherwise, I return a false value.
  217. """
  218. def setETag(etag):
  219. """
  220. Set an C{entity tag} for the outgoing response.
  221. That's "entity tag" as in the HTTP/1.1 I{ETag} header, "used for
  222. comparing two or more entities from the same requested resource."
  223. If I am a conditional request, I may modify my response code to
  224. L{NOT_MODIFIED<http.NOT_MODIFIED>} or
  225. L{PRECONDITION_FAILED<http.PRECONDITION_FAILED>}, if appropriate for the
  226. tag given.
  227. @param etag: The entity tag for the resource being returned.
  228. @type etag: L{str}
  229. @return: If I am a C{If-None-Match} conditional request and the tag
  230. matches one in the request, I return L{CACHED<http.CACHED>} to
  231. indicate that you should write no body. Otherwise, I return a
  232. false value.
  233. """
  234. def setHost(host, port, ssl=0):
  235. """
  236. Change the host and port the request thinks it's using.
  237. This method is useful for working with reverse HTTP proxies (e.g. both
  238. Squid and Apache's mod_proxy can do this), when the address the HTTP
  239. client is using is different than the one we're listening on.
  240. For example, Apache may be listening on https://www.example.com, and
  241. then forwarding requests to http://localhost:8080, but we don't want
  242. HTML produced by Twisted to say 'http://localhost:8080', they should
  243. say 'https://www.example.com', so we do::
  244. request.setHost('www.example.com', 443, ssl=1)
  245. """
  246. class INonQueuedRequestFactory(Interface):
  247. """
  248. A factory of L{IRequest} objects that does not take a ``queued`` parameter.
  249. """
  250. def __call__(channel):
  251. """
  252. Create an L{IRequest} that is operating on the given channel. There
  253. must only be one L{IRequest} object processing at any given time on a
  254. channel.
  255. @param channel: A L{twisted.web.http.HTTPChannel} object.
  256. @type channel: L{twisted.web.http.HTTPChannel}
  257. @return: A request object.
  258. @rtype: L{IRequest}
  259. """
  260. class IAccessLogFormatter(Interface):
  261. """
  262. An object which can represent an HTTP request as a line of text for
  263. inclusion in an access log file.
  264. """
  265. def __call__(timestamp, request):
  266. """
  267. Generate a line for the access log.
  268. @param timestamp: The time at which the request was completed in the
  269. standard format for access logs.
  270. @type timestamp: L{unicode}
  271. @param request: The request object about which to log.
  272. @type request: L{twisted.web.server.Request}
  273. @return: One line describing the request without a trailing newline.
  274. @rtype: L{unicode}
  275. """
  276. class ICredentialFactory(Interface):
  277. """
  278. A credential factory defines a way to generate a particular kind of
  279. authentication challenge and a way to interpret the responses to these
  280. challenges. It creates
  281. L{ICredentials<twisted.cred.credentials.ICredentials>} providers from
  282. responses. These objects will be used with L{twisted.cred} to authenticate
  283. an authorize requests.
  284. """
  285. scheme = Attribute(
  286. "A L{str} giving the name of the authentication scheme with which "
  287. "this factory is associated. For example, C{'basic'} or C{'digest'}.")
  288. def getChallenge(request):
  289. """
  290. Generate a new challenge to be sent to a client.
  291. @type peer: L{twisted.web.http.Request}
  292. @param peer: The request the response to which this challenge will be
  293. included.
  294. @rtype: L{dict}
  295. @return: A mapping from L{str} challenge fields to associated L{str}
  296. values.
  297. """
  298. def decode(response, request):
  299. """
  300. Create a credentials object from the given response.
  301. @type response: L{str}
  302. @param response: scheme specific response string
  303. @type request: L{twisted.web.http.Request}
  304. @param request: The request being processed (from which the response
  305. was taken).
  306. @raise twisted.cred.error.LoginFailed: If the response is invalid.
  307. @rtype: L{twisted.cred.credentials.ICredentials} provider
  308. @return: The credentials represented by the given response.
  309. """
  310. class IBodyProducer(IPushProducer):
  311. """
  312. Objects which provide L{IBodyProducer} write bytes to an object which
  313. provides L{IConsumer<twisted.internet.interfaces.IConsumer>} by calling its
  314. C{write} method repeatedly.
  315. L{IBodyProducer} providers may start producing as soon as they have an
  316. L{IConsumer<twisted.internet.interfaces.IConsumer>} provider. That is, they
  317. should not wait for a C{resumeProducing} call to begin writing data.
  318. L{IConsumer.unregisterProducer<twisted.internet.interfaces.IConsumer.unregisterProducer>}
  319. must not be called. Instead, the
  320. L{Deferred<twisted.internet.defer.Deferred>} returned from C{startProducing}
  321. must be fired when all bytes have been written.
  322. L{IConsumer.write<twisted.internet.interfaces.IConsumer.write>} may
  323. synchronously invoke any of C{pauseProducing}, C{resumeProducing}, or
  324. C{stopProducing}. These methods must be implemented with this in mind.
  325. @since: 9.0
  326. """
  327. # Despite the restrictions above and the additional requirements of
  328. # stopProducing documented below, this interface still needs to be an
  329. # IPushProducer subclass. Providers of it will be passed to IConsumer
  330. # providers which only know about IPushProducer and IPullProducer, not
  331. # about this interface. This interface needs to remain close enough to one
  332. # of those interfaces for consumers to work with it.
  333. length = Attribute(
  334. """
  335. C{length} is a L{int} indicating how many bytes in total this
  336. L{IBodyProducer} will write to the consumer or L{UNKNOWN_LENGTH}
  337. if this is not known in advance.
  338. """)
  339. def startProducing(consumer):
  340. """
  341. Start producing to the given
  342. L{IConsumer<twisted.internet.interfaces.IConsumer>} provider.
  343. @return: A L{Deferred<twisted.internet.defer.Deferred>} which stops
  344. production of data when L{Deferred.cancel} is called, and which
  345. fires with L{None} when all bytes have been produced or with a
  346. L{Failure<twisted.python.failure.Failure>} if there is any problem
  347. before all bytes have been produced.
  348. """
  349. def stopProducing():
  350. """
  351. In addition to the standard behavior of
  352. L{IProducer.stopProducing<twisted.internet.interfaces.IProducer.stopProducing>}
  353. (stop producing data), make sure the
  354. L{Deferred<twisted.internet.defer.Deferred>} returned by
  355. C{startProducing} is never fired.
  356. """
  357. class IRenderable(Interface):
  358. """
  359. An L{IRenderable} is an object that may be rendered by the
  360. L{twisted.web.template} templating system.
  361. """
  362. def lookupRenderMethod(name):
  363. """
  364. Look up and return the render method associated with the given name.
  365. @type name: L{str}
  366. @param name: The value of a render directive encountered in the
  367. document returned by a call to L{IRenderable.render}.
  368. @return: A two-argument callable which will be invoked with the request
  369. being responded to and the tag object on which the render directive
  370. was encountered.
  371. """
  372. def render(request):
  373. """
  374. Get the document for this L{IRenderable}.
  375. @type request: L{IRequest} provider or L{None}
  376. @param request: The request in response to which this method is being
  377. invoked.
  378. @return: An object which can be flattened.
  379. """
  380. class ITemplateLoader(Interface):
  381. """
  382. A loader for templates; something usable as a value for
  383. L{twisted.web.template.Element}'s C{loader} attribute.
  384. """
  385. def load():
  386. """
  387. Load a template suitable for rendering.
  388. @return: a L{list} of L{list}s, L{unicode} objects, C{Element}s and
  389. other L{IRenderable} providers.
  390. """
  391. class IResponse(Interface):
  392. """
  393. An object representing an HTTP response received from an HTTP server.
  394. @since: 11.1
  395. """
  396. version = Attribute(
  397. "A three-tuple describing the protocol and protocol version "
  398. "of the response. The first element is of type L{str}, the second "
  399. "and third are of type L{int}. For example, C{(b'HTTP', 1, 1)}.")
  400. code = Attribute("The HTTP status code of this response, as a L{int}.")
  401. phrase = Attribute(
  402. "The HTTP reason phrase of this response, as a L{str}.")
  403. headers = Attribute("The HTTP response L{Headers} of this response.")
  404. length = Attribute(
  405. "The L{int} number of bytes expected to be in the body of this "
  406. "response or L{UNKNOWN_LENGTH} if the server did not indicate how "
  407. "many bytes to expect. For I{HEAD} responses, this will be 0; if "
  408. "the response includes a I{Content-Length} header, it will be "
  409. "available in C{headers}.")
  410. request = Attribute(
  411. "The L{IClientRequest} that resulted in this response.")
  412. previousResponse = Attribute(
  413. "The previous L{IResponse} from a redirect, or L{None} if there was no "
  414. "previous response. This can be used to walk the response or request "
  415. "history for redirections.")
  416. def deliverBody(protocol):
  417. """
  418. Register an L{IProtocol<twisted.internet.interfaces.IProtocol>} provider
  419. to receive the response body.
  420. The protocol will be connected to a transport which provides
  421. L{IPushProducer}. The protocol's C{connectionLost} method will be
  422. called with:
  423. - ResponseDone, which indicates that all bytes from the response
  424. have been successfully delivered.
  425. - PotentialDataLoss, which indicates that it cannot be determined
  426. if the entire response body has been delivered. This only occurs
  427. when making requests to HTTP servers which do not set
  428. I{Content-Length} or a I{Transfer-Encoding} in the response.
  429. - ResponseFailed, which indicates that some bytes from the response
  430. were lost. The C{reasons} attribute of the exception may provide
  431. more specific indications as to why.
  432. """
  433. def setPreviousResponse(response):
  434. """
  435. Set the reference to the previous L{IResponse}.
  436. The value of the previous response can be read via
  437. L{IResponse.previousResponse}.
  438. """
  439. class _IRequestEncoder(Interface):
  440. """
  441. An object encoding data passed to L{IRequest.write}, for example for
  442. compression purpose.
  443. @since: 12.3
  444. """
  445. def encode(data):
  446. """
  447. Encode the data given and return the result.
  448. @param data: The content to encode.
  449. @type data: L{str}
  450. @return: The encoded data.
  451. @rtype: L{str}
  452. """
  453. def finish():
  454. """
  455. Callback called when the request is closing.
  456. @return: If necessary, the pending data accumulated from previous
  457. C{encode} calls.
  458. @rtype: L{str}
  459. """
  460. class _IRequestEncoderFactory(Interface):
  461. """
  462. A factory for returing L{_IRequestEncoder} instances.
  463. @since: 12.3
  464. """
  465. def encoderForRequest(request):
  466. """
  467. If applicable, returns a L{_IRequestEncoder} instance which will encode
  468. the request.
  469. """
  470. class IClientRequest(Interface):
  471. """
  472. An object representing an HTTP request to make to an HTTP server.
  473. @since: 13.1
  474. """
  475. method = Attribute(
  476. "The HTTP method for this request, as L{bytes}. For example: "
  477. "C{b'GET'}, C{b'HEAD'}, C{b'POST'}, etc.")
  478. absoluteURI = Attribute(
  479. "The absolute URI of the requested resource, as L{bytes}; or L{None} "
  480. "if the absolute URI cannot be determined.")
  481. headers = Attribute(
  482. "Headers to be sent to the server, as "
  483. "a L{twisted.web.http_headers.Headers} instance.")
  484. class IAgent(Interface):
  485. """
  486. An agent makes HTTP requests.
  487. The way in which requests are issued is left up to each implementation.
  488. Some may issue them directly to the server indicated by the net location
  489. portion of the request URL. Others may use a proxy specified by system
  490. configuration.
  491. Processing of responses is also left very widely specified. An
  492. implementation may perform no special handling of responses, or it may
  493. implement redirect following or content negotiation, it may implement a
  494. cookie store or automatically respond to authentication challenges. It may
  495. implement many other unforeseen behaviors as well.
  496. It is also intended that L{IAgent} implementations be composable. An
  497. implementation which provides cookie handling features should re-use an
  498. implementation that provides connection pooling and this combination could
  499. be used by an implementation which adds content negotiation functionality.
  500. Some implementations will be completely self-contained, such as those which
  501. actually perform the network operations to send and receive requests, but
  502. most or all other implementations should implement a small number of new
  503. features (perhaps one new feature) and delegate the rest of the
  504. request/response machinery to another implementation.
  505. This allows for great flexibility in the behavior an L{IAgent} will
  506. provide. For example, an L{IAgent} with web browser-like behavior could be
  507. obtained by combining a number of (hypothetical) implementations::
  508. baseAgent = Agent(reactor)
  509. redirect = BrowserLikeRedirectAgent(baseAgent, limit=10)
  510. authenticate = AuthenticateAgent(
  511. redirect, [diskStore.credentials, GtkAuthInterface()])
  512. cookie = CookieAgent(authenticate, diskStore.cookie)
  513. decode = ContentDecoderAgent(cookie, [(b"gzip", GzipDecoder())])
  514. cache = CacheAgent(decode, diskStore.cache)
  515. doSomeRequests(cache)
  516. """
  517. def request(method, uri, headers=None, bodyProducer=None):
  518. """
  519. Request the resource at the given location.
  520. @param method: The request method to use, such as C{"GET"}, C{"HEAD"},
  521. C{"PUT"}, C{"POST"}, etc.
  522. @type method: L{bytes}
  523. @param uri: The location of the resource to request. This should be an
  524. absolute URI but some implementations may support relative URIs
  525. (with absolute or relative paths). I{HTTP} and I{HTTPS} are the
  526. schemes most likely to be supported but others may be as well.
  527. @type uri: L{bytes}
  528. @param headers: The headers to send with the request (or L{None} to
  529. send no extra headers). An implementation may add its own headers
  530. to this (for example for client identification or content
  531. negotiation).
  532. @type headers: L{Headers} or L{None}
  533. @param bodyProducer: An object which can generate bytes to make up the
  534. body of this request (for example, the properly encoded contents of
  535. a file for a file upload). Or, L{None} if the request is to have
  536. no body.
  537. @type bodyProducer: L{IBodyProducer} provider
  538. @return: A L{Deferred} that fires with an L{IResponse} provider when
  539. the header of the response has been received (regardless of the
  540. response status code) or with a L{Failure} if there is any problem
  541. which prevents that response from being received (including
  542. problems that prevent the request from being sent).
  543. @rtype: L{Deferred}
  544. """
  545. class IPolicyForHTTPS(Interface):
  546. """
  547. An L{IPolicyForHTTPS} provides a policy for verifying the certificates of
  548. HTTPS connections, in the form of a L{client connection creator
  549. <twisted.internet.interfaces.IOpenSSLClientConnectionCreator>} per network
  550. location.
  551. @since: 14.0
  552. """
  553. def creatorForNetloc(hostname, port):
  554. """
  555. Create a L{client connection creator
  556. <twisted.internet.interfaces.IOpenSSLClientConnectionCreator>}
  557. appropriate for the given URL "netloc"; i.e. hostname and port number
  558. pair.
  559. @param hostname: The name of the requested remote host.
  560. @type hostname: L{bytes}
  561. @param port: The number of the requested remote port.
  562. @type port: L{int}
  563. @return: A client connection creator expressing the security
  564. requirements for the given remote host.
  565. @rtype: L{client connection creator
  566. <twisted.internet.interfaces.IOpenSSLClientConnectionCreator>}
  567. """
  568. class IAgentEndpointFactory(Interface):
  569. """
  570. An L{IAgentEndpointFactory} provides a way of constructing an endpoint
  571. used for outgoing Agent requests. This is useful in the case of needing to
  572. proxy outgoing connections, or to otherwise vary the transport used.
  573. @since: 15.0
  574. """
  575. def endpointForURI(uri):
  576. """
  577. Construct and return an L{IStreamClientEndpoint} for the outgoing
  578. request's connection.
  579. @param uri: The URI of the request.
  580. @type uri: L{twisted.web.client.URI}
  581. @return: An endpoint which will have its C{connect} method called to
  582. issue the request.
  583. @rtype: an L{IStreamClientEndpoint} provider
  584. @raises twisted.internet.error.SchemeNotSupported: If the given
  585. URI's scheme cannot be handled by this factory.
  586. """
  587. UNKNOWN_LENGTH = u"twisted.web.iweb.UNKNOWN_LENGTH"
  588. __all__ = [
  589. "IUsernameDigestHash", "ICredentialFactory", "IRequest",
  590. "IBodyProducer", "IRenderable", "IResponse", "_IRequestEncoder",
  591. "_IRequestEncoderFactory", "IClientRequest",
  592. "UNKNOWN_LENGTH"]