From df8b579d249d42ac4c7231e67c754b72e35a33f2 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 24 Jan 2024 13:11:47 -0500 Subject: [PATCH] feat: add Response_code.is_success --- src/Tiny_httpd_server.ml | 2 ++ src/Tiny_httpd_server.mli | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/Tiny_httpd_server.ml b/src/Tiny_httpd_server.ml index 444ae533..397da035 100644 --- a/src/Tiny_httpd_server.ml +++ b/src/Tiny_httpd_server.ml @@ -42,6 +42,8 @@ module Response_code = struct | 501 -> "Not implemented" | 503 -> "Service unavailable" | n -> "Unknown response code " ^ string_of_int n (* TODO *) + + let[@inline] is_success n = n >= 200 && n < 400 end type 'a resp_result = ('a, Response_code.t * string) result diff --git a/src/Tiny_httpd_server.mli b/src/Tiny_httpd_server.mli index 45dca8fb..67270cdf 100644 --- a/src/Tiny_httpd_server.mli +++ b/src/Tiny_httpd_server.mli @@ -195,6 +195,10 @@ module Response_code : sig val descr : t -> string (** A description of some of the error codes. NOTE: this is not complete (yet). *) + + val is_success : t -> bool + (** [is_success code] is true iff [code] is in the [2xx] or [3xx] range. + @since NEXT_RELEASE *) end (** {2 Responses}