isapi.html 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!-- NOTE: This HTML is displayed inside the CHM file - hence some hrefs
  2. will only work in that environment
  3. -->
  4. <HTML>
  5. <BODY>
  6. <TITLE>Introduction to Python ISAPI support</TITLE>
  7. <h2>Introduction to Python ISAPI support</h2>
  8. <h3>See also</h3>
  9. <ul>
  10. <li><a href="/isapi_modules.html">The isapi related modules</a>
  11. </li>
  12. <li><a href="/isapi_objects.html">The isapi related objects</a>
  13. </li>
  14. </ul>
  15. <p><i>Note: if you are viewing this documentation directly from disk,
  16. most links in this document will fail - you can also find this document in the
  17. CHM file that comes with pywin32, where the links will work</i>
  18. <h3>Introduction</h3>
  19. This documents Python support for hosting ISAPI exensions and filters inside
  20. Microsoft Internet Information Server (IIS). It assumes a basic understanding
  21. of the ISAPI filter and extension mechanism.
  22. <p>
  23. In summary, to implement a filter or extension, you provide a Python module
  24. which defines a Filter and/or Extension class. Once your class has been
  25. loaded, IIS/ISAPI will, via an extension DLL, call methods on your class.
  26. <p>
  27. A filter and a class instance need only provide 3 methods - for filters they
  28. are called <code>GetFilterVersion</code>, <code>HttpFilterProc</code> and
  29. <code>TerminateFilter</code>. For extensions they
  30. are named <code>GetExtensionVersion</code>, <code>HttpExtensionProc</code> and
  31. <code>TerminateExtension</code>. If you are familiar with writing ISAPI
  32. extensions in C/C++, these names and their purpose will be familiar.
  33. <p>
  34. Most of the work is done in the <code>HttpFilterProc</code> and
  35. <code>HttpExtensionProc</code> methods. These both take a single
  36. parameter - an <a href="/HTTP_FILTER_CONTEXT.html">HTTP_FILTER_CONTEXT</a> and
  37. <a href="/EXTENSION_CONTROL_BLOCK.html">EXTENSION_CONTROL_BLOCK</a>
  38. object respectively.
  39. <p>
  40. In addition to these components, there is an 'isapi' package, containing
  41. support facilities (base-classes, exceptions, etc) which can be leveraged
  42. by the extension.
  43. <h4>Base classes</h4>
  44. There are a number of base classes provided to make writing extensions a little
  45. simpler. Of particular note is <code>isapi.threaded_extension.ThreadPoolExtension</code>.
  46. This implements a thread-pool and informs IIS that the request is progressing
  47. in the background. Your sub-class need only provide a <code>Dispatch</code>
  48. method, which is called on one of the worker threads rather than the thread
  49. that the request came in on.
  50. <p>
  51. There is base-class for a filter in <code>isapi.simple</code>, but there is no
  52. equivilent threaded filter - filters work under a different model, where
  53. background processing is not possible.
  54. <h4>Samples</h4>
  55. Please see the <code>isapi/samples</code> directory for some sample filters
  56. and extensions.
  57. <H3>Implementation</H3>
  58. A Python ISAPI filter extension consists of 2 main components:
  59. <UL>
  60. <LI>A DLL used by ISAPI to interface with Python.</LI>
  61. <LI>A Python script used by that DLL to implement the filter or extension
  62. functionality</LI>
  63. </UL>
  64. <h4>Extension DLL</h4>
  65. The DLL is usually managed automatically by the isapi.install module. As the
  66. Python script for the extension is installed, a generic DLL provided with
  67. the isapi package is installed next to the script, and IIS configured to
  68. use this DLL.
  69. <p>
  70. The name of the DLL always has the same base name as the Python script, but
  71. with a leading underscore (_), and an extension of .dll. For example, the
  72. sample "redirector.py" will, when installed, have "_redirector.dll" created
  73. in the same directory.
  74. <p/>
  75. The Python script may provide 2 entry points - methods named __FilterFactory__
  76. and __ExtensionFactory__, both taking no arguments and returning a filter or
  77. extension object.
  78. <h3>Using py2exe and the isapi package</h3>
  79. You can instruct py2exe to create a 'frozen' Python ISAPI filter/extension.
  80. In this case, py2exe will create a package with everything you need in one
  81. directory, and the Python source file embedded in the .zip file.
  82. <p>
  83. In general, you will want to build a seperate installation executable along
  84. with the ISAPI extension. This executable will be built from the same script.
  85. See the ISAPI sample in the py2exe distribution.