package dream
Source file method.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60(* This file is part of Dream, released under the MIT license. See LICENSE.md for details, or visit https://github.com/aantron/dream. Copyright 2021 Anton Bachin *) (* See also: - SEARCH, https://tools.ietf.org/html/draft-snell-search-method-02 - Other WebDAV methods: COPY, LOCK, MKCOL, MOVE, PROPFIND, PROPPATCH, UNLOCK. *) type method_ = [ | `GET | `POST | `PUT | `DELETE | `HEAD | `CONNECT | `OPTIONS | `TRACE | `PATCH | `Method of string ] let method_to_string = function | `GET -> "GET" | `POST -> "POST" | `PUT -> "PUT" | `DELETE -> "DELETE" | `HEAD -> "HEAD" | `CONNECT -> "CONNECT" | `OPTIONS -> "OPTIONS" | `TRACE -> "TRACE" | `PATCH -> "PATCH" | `Method method_ -> method_ let string_to_method = function | "GET" -> `GET | "POST" -> `POST | "PUT" -> `PUT | "DELETE" -> `DELETE | "HEAD" -> `HEAD | "CONNECT" -> `CONNECT | "OPTIONS" -> `OPTIONS | "TRACE" -> `TRACE | "PATCH" -> `PATCH | method_ -> `Method method_ (* TODO Test this. *) (* TODO Technically, this does one allocation in case the string can't be converted to a variant, which can be saved by inlining string_to_method. However, this is probably extremely rare. *) let normalize_method = function | `Method method_ -> string_to_method method_ | method_ -> method_ let methods_equal method_1 method_2 = normalize_method method_1 = normalize_method method_2