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

http/response_message.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 response_message
#
# -----------------------------------------------------------------------


# HTTP response message
#
module:public response_message(
  # NYI: CLEANUP: remove this arg?
  # the request message for which this response was generated
  public req option http.request_message,
  # the major version
  public version_major i64,
  # the minor version
  public version_minor i64,
  # the status code of the response
  public status_code i64,
  # the reason-phrase of the response
  public reason_phrase String,
  # the header fields
  public redef header container.Map String String,
  # the body of the response
  public redef body i64 -> choice (Sequence u8) io.end_of_file error) : Message
is
  # the start line of the message, for a response this is also called status line
  public redef start_line String => status_line

  # the status line of the response message
  public status_line String =>
    "$(version_str version_major version_minor) $status_code $reason_phrase$crlf"


  public type.new(
    # the request message for which this response was generated
    req option http.request_message,
    # the major version
    version_major i64,
    # the minor version
    version_minor i64,
    # the status code of the response
    status_code i64,
    # the reason-phrase of the response
    reason_phrase String,
    # the header fields
    header Sequence (String,String),
    # the body of the response
    body i64 -> choice (Sequence u8) io.end_of_file error) http.response_message
  =>
    http.response_message req version_major version_minor status_code reason_phrase (as_header_map header) body


  # create an http response using a default values
  #
  # request_message => nil
  # major => 1
  # minor => 1
  # reason_phrase via status code from reason phrases map
  #
  public type.new(
    # the status code of the response
    status_code i64,
    # the header fields
    header Sequence (String,String),
    # the body of the response
    body i64 -> choice (Sequence u8) io.end_of_file error) http.response_message
    pre
      debug: http.reason_phrases[status_code].ok
  =>
    http.response_message nil 1 1 status_code http.reason_phrases[status_code].or_panic (as_header_map header) body

last changed: 2026-10-07