utilada_2.8.0_0d266031/src/sys/http/util-http-mimes.adb

 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
-----------------------------------------------------------------------
--  util-http-mimes -- HTTP Headers
--  Copyright (C) 2022 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--  SPDX-License-Identifier: Apache-2.0
-----------------------------------------------------------------------
with Ada.Characters.Handling;
with Ada.Strings.Equal_Case_Insensitive;
package body Util.Http.Mimes is

   use Ada.Characters.Handling;
   use Ada.Strings;

   function Is_Mime (Header : in String;
                     Mime   : in String) return Boolean is
      Sep : Natural;
   begin
      Sep := Util.Strings.Index (Header, ';');
      if Sep = 0 then
         Sep := Header'Last;
      else
         Sep := Sep - 1;
         while Sep > Header'First and then Is_Space (Header (Sep)) loop
            Sep := Sep - 1;
         end loop;
      end if;
      return Equal_Case_Insensitive (Header (Header'First .. Sep), Mime);
   end Is_Mime;

end Util.Http.Mimes;