Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

http.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature http
#
# -----------------------------------------------------------------------

# HTTP/1.1 as defined in
# * HTTP/1.1        https://datatracker.ietf.org/doc/html/rfc9112
# * HTTP Semantics  https://datatracker.ietf.org/doc/html/rfc9110
# * HTTP Caching    https://datatracker.ietf.org/doc/html/rfc9111
#
#
public http is


# create case insensitive Map from array of key/values
#
module as_header_map(kvs Sequence (String,String)) =>
  lm : mutate is
  lm ! ()->
    fields := (container.mutable_tree_map lm String String) .empty
    for kv in kvs do
      fields.put kv.0.lower_case kv.1
    fields.as_map


# line separator in the HTTP header
#
module crlf => "\r\n"


# When a major version of HTTP does not define any minor versions,
# the minor version "0" is implied. The "0" is used when referring
# to that protocol within elements that require a minor version identifier.
# https://datatracker.ietf.org/doc/html/rfc9110#section-2.5-6
#
module parse_http_version(ver String) =>
  err(_ error) => error "broken format of HTTP version '$(ver)'"
  v := ver.substring 5
  match v.find "."
    nil => (v.parse_i32.or_cause unit err, 0)
    i i32 =>
      (v.substring 0 i .parse_i32.or_cause unit err, v.substring i+1 .parse_i32.or_cause unit err)


last changed: 2026-06-17