Leaked source code of windows server 2003
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.

183 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1999-2002 Microsoft Corporation
  3. Module Name:
  4. engine.h
  5. Abstract:
  6. The public definition of HTTP protocol interfaces.
  7. Author:
  8. Michael Courage (mcourage) 17-Sep-1999
  9. Revision History:
  10. --*/
  11. #ifndef _ENGINE_H_
  12. #define _ENGINE_H_
  13. typedef enum _UL_CONN_HDR
  14. {
  15. ConnHdrNone,
  16. ConnHdrClose,
  17. ConnHdrKeepAlive,
  18. ConnHdrMax
  19. } UL_CONN_HDR, *PUL_CONN_HDR;
  20. __inline
  21. UL_CONN_HDR
  22. UlChooseConnectionHeader(
  23. IN HTTP_VERSION Version,
  24. IN BOOLEAN Disconnect
  25. )
  26. {
  27. UL_CONN_HDR ConnHeader;
  28. //
  29. // Sanity check
  30. //
  31. PAGED_CODE();
  32. ConnHeader = ConnHdrNone;
  33. if (Disconnect)
  34. {
  35. if (HTTP_GREATER_EQUAL_VERSION(Version, 1, 0)
  36. || HTTP_EQUAL_VERSION(Version, 0, 0))
  37. {
  38. //
  39. // Connection: close
  40. //
  41. ConnHeader = ConnHdrClose;
  42. }
  43. }
  44. else if (HTTP_EQUAL_VERSION(Version, 1, 0))
  45. {
  46. //
  47. // Connection: keep-alive
  48. //
  49. ConnHeader = ConnHdrKeepAlive;
  50. }
  51. return ConnHeader;
  52. } // UlChooseConnectionHeader
  53. __inline
  54. BOOLEAN
  55. UlCheckDisconnectInfo(
  56. IN PUL_INTERNAL_REQUEST pRequest
  57. )
  58. {
  59. BOOLEAN Disconnect;
  60. //
  61. // Sanity check
  62. //
  63. PAGED_CODE();
  64. ASSERT( UL_IS_VALID_INTERNAL_REQUEST( pRequest ) );
  65. if (
  66. //
  67. // pre-version 1.0
  68. //
  69. (HTTP_LESS_VERSION(pRequest->Version, 1, 0)) ||
  70. //
  71. // or version 1.0 with no Connection: Keep-Alive
  72. // CODEWORK: and no Keep-Alive header
  73. //
  74. (HTTP_EQUAL_VERSION(pRequest->Version, 1, 0) &&
  75. (pRequest->HeaderValid[HttpHeaderConnection] == FALSE ||
  76. !(pRequest->Headers[HttpHeaderConnection].HeaderLength
  77. == STRLEN_LIT("keep-alive") &&
  78. (_stricmp(
  79. (const char*) pRequest->Headers[HttpHeaderConnection].pHeader,
  80. "keep-alive"
  81. ) == 0)))) ||
  82. //
  83. // or version 1.1 with a Connection: close
  84. // CODEWORK: move to parser or just make better in general..
  85. //
  86. (HTTP_EQUAL_VERSION(pRequest->Version, 1, 1) &&
  87. pRequest->HeaderValid[HttpHeaderConnection] &&
  88. pRequest->Headers[HttpHeaderConnection].HeaderLength
  89. == STRLEN_LIT("close") &&
  90. _stricmp(
  91. (const char*) pRequest->Headers[HttpHeaderConnection].pHeader,
  92. "close"
  93. ) == 0)
  94. )
  95. {
  96. Disconnect = TRUE;
  97. }
  98. else
  99. {
  100. Disconnect = FALSE;
  101. }
  102. return Disconnect;
  103. } // UlCheckDisconnectInfo
  104. __inline
  105. BOOLEAN
  106. UlNeedToGenerateContentLength(
  107. IN HTTP_VERB Verb,
  108. IN USHORT StatusCode,
  109. IN ULONG Flags
  110. )
  111. {
  112. //
  113. // Fast path: If there is more data on the way, then don't generate
  114. // the header.
  115. //
  116. if ((Flags & HTTP_SEND_RESPONSE_FLAG_MORE_DATA) != 0)
  117. {
  118. return FALSE;
  119. }
  120. //
  121. // RFC2616 section 4.3.
  122. //
  123. if ((100 <= StatusCode && StatusCode <= 199) || // 1xx (informational)
  124. (StatusCode == 204) || // 204 (no content)
  125. (StatusCode == 304)) // 304 (not modified)
  126. {
  127. return FALSE;
  128. }
  129. if (Verb == HttpVerbHEAD)
  130. {
  131. return FALSE;
  132. }
  133. //
  134. // Otherwise, we can generate a content-length header.
  135. //
  136. return TRUE;
  137. } // UlNeedToGenerateContentLength
  138. #endif // _ENGINE_H_