Module Simple_httpd.HeadersSource

Module to handle request and response headers

Headers

Headers are metadata associated with a request or response. This module provide the necessary function to read and modify headers

A module defining all the legal header names, generated from the csv at iana. last update: 29.06.2023. Other headers are ignored!

type header = Simple_httpd__Headers_.header =
  1. | X_Real_IP
  2. | X_Forwarded_For
  3. | X_CSRF_Token
  4. | Filename_Multipart
  5. | CF_Connecting_IP
  6. | A_IM
  7. | Accept
  8. | Accept_Additions
  9. | Accept_CH
  10. | Accept_Charset
    (*
    • deprecated Header Accept-Charset is deprecated
    *)
  11. | Accept_Datetime
  12. | Accept_Encoding
  13. | Accept_Features
  14. | Accept_Language
  15. | Accept_Patch
  16. | Accept_Post
  17. | Accept_Ranges
  18. | Accept_Signature
  19. | Access_Control_Allow_Credentials
  20. | Access_Control_Allow_Headers
  21. | Access_Control_Allow_Methods
  22. | Access_Control_Allow_Origin
  23. | Access_Control_Expose_Headers
  24. | Access_Control_Max_Age
  25. | Access_Control_Request_Headers
  26. | Access_Control_Request_Method
  27. | Age
  28. | Allow
  29. | ALPN
  30. | Alt_Svc
  31. | Alt_Used
  32. | Alternates
  33. | AMP_Cache_Transform
  34. | Apply_To_Redirect_Ref
  35. | Authentication_Control
  36. | Authentication_Info
  37. | Authorization
  38. | Available_Dictionary
  39. | C_PEP_Info
    (*
    • deprecated Header C-PEP-Info is deprecated
    *)
  40. | Cache_Control
  41. | Cache_Status
  42. | Cal_Managed_ID
  43. | CalDAV_Timezones
  44. | Capsule_Protocol
  45. | CDN_Cache_Control
  46. | CDN_Loop
  47. | Cert_Not_After
  48. | Cert_Not_Before
  49. | Clear_Site_Data
  50. | Client_Cert
  51. | Client_Cert_Chain
  52. | Close
  53. | CMCD_Object
  54. | CMCD_Request
  55. | CMCD_Session
  56. | CMCD_Status
  57. | CMSD_Dynamic
  58. | CMSD_Static
  59. | Concealed_Auth_Export
  60. | Configuration_Context
  61. | Connection
  62. | Content_Digest
  63. | Content_Disposition
  64. | Content_Encoding
  65. | Content_ID
    (*
    • deprecated Header Content-ID is deprecated
    *)
  66. | Content_Language
  67. | Content_Length
  68. | Content_Location
  69. | Content_Range
  70. | Content_Security_Policy
  71. | Content_Security_Policy_Report_Only
  72. | Content_Type
  73. | Cookie
  74. | Cross_Origin_Embedder_Policy
  75. | Cross_Origin_Embedder_Policy_Report_Only
  76. | Cross_Origin_Opener_Policy
  77. | Cross_Origin_Opener_Policy_Report_Only
  78. | Cross_Origin_Resource_Policy
  79. | CTA_Common_Access_Token
  80. | DASL
  81. | Date
  82. | DAV
  83. | Delta_Base
  84. | Deprecation
  85. | Depth
  86. | Destination
  87. | Differential_ID
    (*
    • deprecated Header Differential-ID is deprecated
    *)
  88. | Dictionary_ID
  89. | DPoP
  90. | DPoP_Nonce
  91. | Early_Data
  92. | EDIINT_Features
  93. | ETag
  94. | Expect
  95. | Expect_CT
    (*
    • deprecated Header Expect-CT is deprecated
    *)
  96. | Expires
  97. | Forwarded
  98. | From
  99. | Hobareg
  100. | Host
  101. | If
  102. | If_Match
  103. | If_Modified_Since
  104. | If_None_Match
  105. | If_Range
  106. | If_Schedule_Tag_Match
  107. | If_Unmodified_Since
  108. | IM
  109. | Include_Referred_Token_Binding_ID
  110. | Isolation
  111. | Keep_Alive
  112. | Label
  113. | Last_Event_ID
  114. | Last_Modified
  115. | Location
  116. | Lock_Token
  117. | Max_Forwards
  118. | Memento_Datetime
  119. | Meter
  120. | MIME_Version
  121. | Negotiate
  122. | NEL
  123. | OData_EntityId
  124. | OData_Isolation
  125. | OData_MaxVersion
  126. | OData_Version
  127. | Optional_WWW_Authenticate
  128. | Ordering_Type
  129. | Origin
  130. | Origin_Agent_Cluster
  131. | OSCORE
  132. | OSLC_Core_Version
  133. | Overwrite
  134. | Permissions_Policy
  135. | Ping_From
  136. | Ping_To
  137. | Position
  138. | Pragma
    (*
    • deprecated Header Pragma is deprecated
    *)
  139. | Prefer
  140. | Preference_Applied
  141. | Priority
  142. | Protocol_Info
    (*
    • deprecated Header Protocol-Info is deprecated
    *)
  143. | Protocol_Query
    (*
    • deprecated Header Protocol-Query is deprecated
    *)
  144. | Proxy_Authenticate
  145. | Proxy_Authentication_Info
  146. | Proxy_Authorization
  147. | Proxy_Status
  148. | Public_Key_Pins
  149. | Public_Key_Pins_Report_Only
  150. | Range
  151. | Redirect_Ref
  152. | Referer
  153. | Referrer_Policy
  154. | Refresh
  155. | Repeatability_Client_ID
  156. | Repeatability_First_Sent
  157. | Repeatability_Request_ID
  158. | Repeatability_Result
  159. | Replay_Nonce
  160. | Reporting_Endpoints
  161. | Repr_Digest
  162. | Retry_After
  163. | Schedule_Reply
  164. | Schedule_Tag
  165. | Sec_GPC
  166. | Sec_Purpose
  167. | Sec_Token_Binding
  168. | Sec_WebSocket_Accept
  169. | Sec_WebSocket_Extensions
  170. | Sec_WebSocket_Key
  171. | Sec_WebSocket_Protocol
  172. | Sec_WebSocket_Version
  173. | Server
  174. | Server_Timing
  175. | Signature
  176. | Signature_Input
  177. | SLUG
  178. | SoapAction
  179. | Status_URI
  180. | Strict_Transport_Security
  181. | Sunset
  182. | Surrogate_Capability
  183. | Surrogate_Control
  184. | TCN
  185. | TE
  186. | Timeout
  187. | Timing_Allow_Origin
  188. | Topic
  189. | Traceparent
  190. | Tracestate
  191. | Trailer
  192. | Transfer_Encoding
  193. | TTL
  194. | Upgrade
  195. | Urgency
  196. | Use_As_Dictionary
  197. | User_Agent
  198. | Variant_Vary
  199. | Vary
  200. | Via
  201. | Want_Content_Digest
  202. | Want_Repr_Digest
  203. | WWW_Authenticate
  204. | X_Content_Type_Options
  205. | X_Frame_Options
val eq : header -> header -> bool
val to_string : header -> string
exception Invalid_header of string
exception End_of_headers
val parse : Input.t -> header
Sourcetype t = (header * string) list

The header files of a request or response.

Neither the key nor the value can contain '\r' or '\n'. See https://tools.ietf.org/html/rfc7230#section-3.2

Sourceval empty : t

Empty list of headers

Sourceval get : ?f:(string -> string) -> header -> t -> string option

get k headers looks for the header field with key k.

  • parameter f

    if provided, will transform the value before it is returned.

Sourceval get_exn : ?f:(string -> string) -> header -> t -> string

get_exn k headers same as above but raise Not_found if the headers is not present.

Sourceval set : header -> string -> t -> t

set k v headers sets the key k to value v. It erases any previous entry for k

Sourceval set_cookies : Cookies.t -> t -> t

Encode all the cookies in the header

Sourceval remove : header -> t -> t

Remove the key from the headers, if present.

Sourceval contains : header -> t -> bool

Is there a header with the given key?

Sourceval pp : Format.formatter -> t -> unit

Pretty print the headers.