emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/plz-media-type 7bba4e846d 01/26: Initial commit


From: ELPA Syncer
Subject: [elpa] externals/plz-media-type 7bba4e846d 01/26: Initial commit
Date: Wed, 1 May 2024 09:58:59 -0400 (EDT)

branch: externals/plz-media-type
commit 7bba4e846d0e9b31825526eab0ae74da9cbac313
Author: Roman Scherer <roman@burningswell.com>
Commit: Roman Scherer <roman@burningswell.com>

    Initial commit
---
 .elpaignore                                        |    8 +
 .github/workflows/test.yml                         |   93 ++
 .gitignore                                         |    7 +
 LICENSE                                            |  674 +++++++++++
 Makefile                                           |   59 +
 README.org                                         |  414 +++++++
 checkout                                           |   11 +
 makem.sh                                           | 1265 ++++++++++++++++++++
 plz-media-type.el                                  |  656 ++++++++++
 plz-media-type.info                                |  471 ++++++++
 tests/plz-media-type-test.el                       |  165 +++
 tests/response/application/json/vertex-hello.txt   |  110 ++
 tests/response/application/json/vertex-poem.txt    |  335 ++++++
 .../application/json/vertext-unauthenticated.txt   |   31 +
 .../response/application/x-ndjson/ollama-hello.txt |   32 +
 tests/response/text/event-stream/openai-emoji.txt  |   30 +
 tests/response/text/event-stream/openai-hello.txt  |   46 +
 tests/test-plz-media-type.el                       |  366 ++++++
 18 files changed, 4773 insertions(+)

diff --git a/.elpaignore b/.elpaignore
new file mode 100644
index 0000000000..49acf3c1f2
--- /dev/null
+++ b/.elpaignore
@@ -0,0 +1,8 @@
+.elpaignore
+Makefile
+makem.sh
+NOTES.org
+.github/
+images/
+tests/
+README.info
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000000..915f9eee9c
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,93 @@
+# * test.yml --- Test Emacs packages using makem.sh on GitHub Actions
+
+# URL: https://github.com/alphapapa/makem.sh
+# Version: 0.6-pre
+
+# * Commentary:
+
+# Based on Steve Purcell's examples at
+# 
<https://github.com/purcell/setup-emacs/blob/master/.github/workflows/test.yml>,
+# 
<https://github.com/purcell/package-lint/blob/master/.github/workflows/test.yml>.
+
+# * License:
+
+# This program 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, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+# * Code:
+
+name: "CI"
+on:
+  pull_request:
+  push:
+    # Comment out this section to enable testing of all branches.
+    # branches:
+    #   - master
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        emacs_version:
+          - 27.1
+          - 27.2
+          - 28.1
+          - 28.2
+          - 29.1
+          - 29.2
+          - snapshot
+    steps:
+    - uses: purcell/setup-emacs@master
+      with:
+        version: ${{ matrix.emacs_version }}
+
+    - uses: actions/checkout@v2
+
+    - name: Checkout unreleased dependencies
+      run: |
+        ./checkout
+
+    - name: Install packages
+      run: |
+        sudo apt-get install curl ispell pv
+
+    - name: Initialize sandbox
+      run: |
+        SANDBOX_DIR=$(mktemp -d) || exit 1
+        echo "SANDBOX_DIR=$SANDBOX_DIR" >> $GITHUB_ENV
+        ./makem.sh -vv --sandbox=$SANDBOX_DIR --install-deps --install-linters
+
+    - name: Run httpbin with Docker
+      run: docker run -d -p 80:80 -P kennethreitz/httpbin
+
+    # The "all" rule is not used, because it treats compilation warnings
+    # as failures, so linting and testing are run as separate steps.
+
+    - name: Lint
+      # NOTE: Uncomment this line to treat lint failures as passing so
+      #       the job doesn't show failure.  (Enabled for now because
+      #       Emacs 29 indents some cl- forms differently, which
+      #       causes lint-indent to fail, and what matters most is
+      #       that the tests pass.)
+      continue-on-error: true
+      run: ./makem.sh -vv --sandbox=$SANDBOX_DIR lint
+
+    - name: Test
+      if: always()  # Run test even if linting fails.
+      run: ./makem.sh -vv --sandbox=$SANDBOX_DIR test
+
+# Local Variables:
+# eval: (outline-minor-mode)
+# End:
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..174f6561b3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+*.elc
+/scratch.el
+.#*
+/sandbox/
+/.sandbox/
+/worktrees/
+/vendor/
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000..94a9ed024d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program 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, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000000..64c4516119
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,59 @@
+# * makem.sh/Makefile --- Script to aid building and testing Emacs Lisp 
packages
+
+# URL: https://github.com/alphapapa/makem.sh
+# Version: 0.5
+
+# * Arguments
+
+# For consistency, we use only var=val options, not hyphen-prefixed options.
+
+# NOTE: I don't like duplicating the arguments here and in makem.sh,
+# but I haven't been able to find a way to pass arguments which
+# conflict with Make's own arguments through Make to the script.
+# Using -- doesn't seem to do it.
+
+ifdef install-deps
+       INSTALL_DEPS = "--install-deps"
+endif
+ifdef install-linters
+       INSTALL_LINTERS = "--install-linters"
+endif
+
+ifdef sandbox
+       ifeq ($(sandbox), t)
+               SANDBOX = --sandbox
+       else
+               SANDBOX = --sandbox=$(sandbox)
+       endif
+endif
+
+ifdef debug
+       DEBUG = "--debug"
+endif
+
+# ** Verbosity
+
+# Since the "-v" in "make -v" gets intercepted by Make itself, we have
+# to use a variable.
+
+verbose = $(v)
+
+ifneq (,$(findstring vvv,$(verbose)))
+       VERBOSE = "-vvv"
+else ifneq (,$(findstring vv,$(verbose)))
+       VERBOSE = "-vv"
+else ifneq (,$(findstring v,$(verbose)))
+       VERBOSE = "-v"
+endif
+
+# * Rules
+
+# TODO: Handle cases in which "test" or "tests" are called and a
+# directory by that name exists, which can confuse Make.
+
+%:
+       @./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) 
$(INSTALL_LINTERS) $(@)
+
+.DEFAULT: init
+init:
+       @./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) 
$(INSTALL_LINTERS)
diff --git a/README.org b/README.org
new file mode 100644
index 0000000000..4881b037fc
--- /dev/null
+++ b/README.org
@@ -0,0 +1,414 @@
+#+TITLE: plz-media-type
+
+#+PROPERTY: LOGGING nil
+
+# Note: This readme works with the org-make-toc
+# <https://github.com/alphapapa/org-make-toc> package, which
+# automatically updates the table of contents.
+
+[[http://elpa.gnu.org/packages/plz-media-type.html][http://elpa.gnu.org/packages/plz-media-type.svg]]
+[[https://github.com/r0man/plz-media-type/actions/workflows/test.yml][https://github.com/r0man/plz-media-type/actions/workflows/test.yml/badge.svg]]
+
+~plz-media-type~ is an Emacs Lisp library that enhances MIME type
+handling for HTTP requests within Emacs. It leverages the 
[[https://github.com/alphapapa/plz.el][plz.el]] HTTP
+library for networking calls and introduces a mechanism to process
+responses based on the content type header. This library defines
+various classes and methods for parsing and processing standard MIME
+types, including JSON, XML, HTML, and binary data. It is used in the
+[[https://github.com/ahyatt/llm][LLM]] library to handle decoding of various 
streaming and non-streaming
+media type formats.
+
+👷🏽 NOTE: This is work in progress. The library is not yet on ELPA.
+
+* Contents :noexport:
+:PROPERTIES:
+:TOC:      :include siblings
+:END:
+:CONTENTS:
+- [[#installation][Installation]]
+- [[#usage][Usage]]
+  - [[#quick-start][Quick Start]]
+  - [[#media-types][Media Types]]
+  - [[#error-handling][Error Handling]]
+- [[#credits][Credits]]
+  - [[#copyright-assignment][Copyright assignment]]
+:END:
+
+* Installation
+:PROPERTIES:
+:TOC:      :depth 0
+:END:
+
+** GNU ELPA
+
+~plz-media-type~ is available in 
[[http://elpa.gnu.org/packages/plz-media-type.html][GNU ELPA]].  It may be 
installed in
+Emacs using the ~package-install~ command.
+
+* Usage
+:PROPERTIES:
+:TOC:      :depth 1
+:END:
+
+The main function, ~plz-media-type-request~, works similarly to the
+[[https://github.com/alphapapa/plz.el?tab=readme-ov-file#functions][plz]] 
function but with an additional feature. When the ~:as~ option is
+set to ~(media-types MEDIA-TYPES)~, the HTTP response is decoded based
+on the content type header. The ~MEDIA-TYPES~ association list defines
+a mapping from content type symbols to instances of media type
+classes. These classes determine how the response is processed.
+
+When using the media type option:
+
++ Synchronous requests return a ~plz-response~ structure or signal an
+  error.
+
++ Asynchronous requests return a process object and pass a
+  ~plz-response~ structure to the ~THEN~ callback and a ~plz-error~
+  structure to the ~ELSE~ callback.
+
+** Quick Start
+
+The ~plz-media-types~ variable contains a list of pre-configured media
+type mappings. The following code makes a synchronous ~GET~ request to
+a URL and returns a ~plz-response~ structure. Since the response is
+returned with the content type header set to ~application/json~, the
+~plz-media-type:application/json~ class will be used to decode the
+HTTP body.
+
+#+BEGIN_SRC elisp :exports both :results value code :cache yes
+  (plz-media-type-request
+    'get "https://httpbin.org/json";
+    :as `(media-types ,plz-media-types))
+#+END_SRC
+
+#+RESULTS[cf5b78b0f688eaca9b641d3cb6b9dbb16b873b79]:
+#+begin_src elisp
+#s(plz-response 2 200
+                ((date . "Sun, 24 Mar 2024 10:41:18 GMT")
+                 (content-type . "application/json")
+                 (content-length . "429")
+                 (server . "gunicorn/19.9.0")
+                 (access-control-allow-origin . "*")
+                 (access-control-allow-credentials . "true"))
+                ((slideshow
+                  (author . "Yours Truly")
+                  (date . "date of publication")
+                  (slides .
+                          [((title . "Wake up to WonderWidgets!")
+                            (type . "all"))
+                           ((items .
+                                   ["Why <em>WonderWidgets</em> are great" 
"Who <em>buys</em> WonderWidgets"])
+                            (title . "Overview")
+                            (type . "all"))])
+                  (title . "Sample Slide Show"))))
+#+end_src
+
+** Media Types
+
+The following table shows the media type classes provided by the
+~plz-media-type~ library. The ~Content Type~ and ~Default~ columns
+indicate which media type is part of the default ~plz-media-types~ and
+which content type header values trigger their use. The ~Stream~
+column specifies whether the class consumes data in a streaming or
+non-streaming way.
+
+| EIEIO Class                               | Content Type               | 
Default | Stream |
+|-------------------------------------------+----------------------------+---------+--------|
+| ~plz-media-type:application/json-array~   | -                          | No  
    | Yes    |
+| ~plz-media-type:application/json~         | ~application/json~         | Yes 
    | No     |
+| ~plz-media-type:application/octet-stream~ | ~application/octet-stream~ | Yes 
    | No     |
+| ~plz-media-type:application/x-ndjson~     | -                          | No  
    | Yes    |
+| ~plz-media-type:application/xml~          | ~application/xml~          | Yes 
    | No     |
+| ~plz-media-type:text/html~                | ~text/html~                | Yes 
    | No     |
+
+*** JSON
+
+The ~plz-media-type:application/json~ media type class handles JSON
+responses. It parses the response body using ~json-parse-buffer~ after
+receiving the entire response.
+
+*Customization:*
+
+Instances of this class can be customized by setting the following
+slots:
+
++ ~:array-type~: Lisp type used for arrays (~array~ or ~list~, default ~array~)
++ ~:false-object~: Object representing JSON ~false~ (default ~:json-false~)
++ ~:null-object~: Object representing JSON ~null~ (default ~nil~)
++ ~:object-type~: Lisp type used for objects (~hash-table~, ~alist~, or 
~plist~, default ~alist~)
+
+*Example:*
+
+#+BEGIN_SRC elisp :exports both :results value code :cache yes
+  (plz-media-type-request
+    'get "https://httpbin.org/json";
+    :as `(media-types
+          ((application/json
+            . ,(plz-media-type:application/json :array-type 'list)))))
+#+END_SRC
+
+#+RESULTS[3a4374f60fc325e3b8ffb9e4abd9e4a170ab42ff]:
+#+begin_src elisp
+#s(plz-response 2 200
+                ((date . "Sun, 24 Mar 2024 10:05:19 GMT")
+                 (content-type . "application/json")
+                 (content-length . "429")
+                 (server . "gunicorn/19.9.0")
+                 (access-control-allow-origin . "*")
+                 (access-control-allow-credentials . "true"))
+                ((slideshow
+                  (author . "Yours Truly")
+                  (date . "date of publication")
+                  (slides
+                   ((title . "Wake up to WonderWidgets!")
+                    (type . "all"))
+                   ((items "Why <em>WonderWidgets</em> are great" "Who 
<em>buys</em> WonderWidgets")
+                    (title . "Overview")
+                    (type . "all")))
+                  (title . "Sample Slide Show"))))
+#+end_src
+
+*** Newline Delimited JSON Stream
+
+The ~plz-media-type:application/x-ndjson~ media type class handles
+newline-delimited JSON responses in a streaming fashion. It parses
+each line using ~json-parse-buffer~ and calls the ~:handler~ function
+for each decoded object. The body slot of the ~plz-response~ structure
+will always be ~nil~.
+
+*Customization:*
+
++ ~:handler~: Function called for each JSON object.
+
+*Example:*
+
+#+BEGIN_SRC elisp :exports both :results value code :cache yes
+(plz-media-type-request
+  'get "https://httpbin.org/stream/5";
+  :as `(media-types
+        ((application/json
+          . ,(plz-media-type:application/x-ndjson
+              :handler (lambda (object)
+                         (message "%s" object)))))))
+#+END_SRC
+
+#+RESULTS[172054f7310092434fb22359719e360a44017a0c]:
+#+begin_src elisp
+#s(plz-response 2 200
+                ((date . "Sun, 24 Mar 2024 10:06:51 GMT")
+                 (content-type . "application/json")
+                 (server . "gunicorn/19.9.0")
+                 (access-control-allow-origin . "*")
+                 (access-control-allow-credentials . "true"))
+                nil)
+#+end_src
+
+*** JSON Array Stream
+
+The ~plz-media-type:application/json-array~ media type class handles
+JSON responses where the top-level object is an array. It parses each
+object in the array using ~json-parse-buffer~ and calls the ~:handler~
+function for each decoded object.
+
+*Customization:*
+
++ ~:handler~: Function called for each JSON object.
+
+*Example:*
+
+#+BEGIN_SRC elisp :exports code :noeval
+  (plz-media-type-request
+    'get "https://localhost/json-array";
+    :as `(media-types
+          ((application/json
+            . ,(plz-media-type:application/json-array
+                :handler (lambda (object)
+                           (message "%s" object)))))))
+#+END_SRC
+
+*** XML
+
+The ~plz-media-type:application/xml~ media type class handles XML
+responses. It parses the response body using
+~libxml-parse-html-region~ after receiving the entire response.
+
+*Customization:* None
+
+*Example:*
+
+#+BEGIN_SRC elisp :exports both :results value code :cache yes
+  (plz-media-type-request
+    'get "https://httpbin.org/xml";
+    :as `(media-types ((application/xml . ,(plz-media-type:application/xml)))))
+#+END_SRC
+
+#+RESULTS[3360a40d0942c00e62ee68428d42d73f3041b845]:
+#+begin_src elisp
+#s(plz-response 2 200
+                ((date . "Sun, 24 Mar 2024 10:17:57 GMT")
+                 (content-type . "application/xml")
+                 (content-length . "522")
+                 (server . "gunicorn/19.9.0")
+                 (access-control-allow-origin . "*")
+                 (access-control-allow-credentials . "true"))
+                (top nil
+                     (comment nil "  A SAMPLE set of slides  ")
+                     (html nil
+                           (body nil
+                                 (slideshow
+                                  ((title . "Sample Slide Show")
+                                   (date . "Date of publication")
+                                   (author . "Yours Truly"))
+                                  (comment nil " TITLE SLIDE ")
+                                  (slide
+                                   ((type . "all"))
+                                   (title nil "Wake up to WonderWidgets!"))
+                                  (comment nil " OVERVIEW ")
+                                  (slide
+                                   ((type . "all"))
+                                   (title nil "Overview")
+                                   (item nil "Why "
+                                         (em nil "WonderWidgets")
+                                         " are great")
+                                   (item nil)
+                                   (item nil "Who "
+                                         (em nil "buys")
+                                         " WonderWidgets")))))))
+#+end_src
+
+*** HTML
+
+The ~plz-media-type:text/html~ media type class handles HTML
+responses. It parses the response body using
+~libxml-parse-html-region~ after receiving the entire response.
+
+*Customization:* None
+
+*Example:*
+
+#+BEGIN_SRC elisp :exports both :results value code :cache yes
+  (plz-media-type-request
+    'get "https://httpbin.org/html";
+    :as `(media-types ((text/html . ,(plz-media-type:application/xml)))))
+#+END_SRC
+
+#+RESULTS[a07472ac35e4fd275ce6881919a1d52cd8491ba2]:
+#+begin_src elisp
+#s(plz-response 2 200
+                ((date . "Sun, 24 Mar 2024 10:18:40 GMT")
+                 (content-type . "text/html; charset=utf-8")
+                 (content-length . "3741")
+                 (server . "gunicorn/19.9.0")
+                 (access-control-allow-origin . "*")
+                 (access-control-allow-credentials . "true"))
+                (html nil
+                      (head nil)
+                      (body nil "\n      "
+                            (h1 nil "Herman Melville - Moby-Dick")
+                            "\n\n      "
+                            (div nil "\n        "
+                                 (p nil "\n          Availing himself of the 
mild, summer-cool weather that now reigned in these latitudes, and in 
preparation for the peculiarly active pursuits shortly to be anticipated, 
Perth, the begrimed, blistered old blacksmith, had not removed his portable 
forge to the hold again, after concluding his contributory work for Ahab's leg, 
but still retained it on deck, fast lashed to ringbolts by the foremast; being 
now almost incessantly invoked by th [...]
+                                 "\n      ")
+                            "\n  ")))
+#+end_src
+
+*** Octet Stream
+
+The ~plz-media-type:application/octet-stream~ media type class handles
+any other response and is used as the default media type hanlder. It
+does not parse the response body in any way.
+
+#+BEGIN_SRC elisp :exports both :results value code :cache yes
+  (plz-media-type-request
+    'get "https://httpbin.org/json";
+    :as `(media-types ((t . ,(plz-media-type:application/octet-stream)))))
+#+END_SRC
+
+#+RESULTS[b74610a7b1208327e35354dffea7bad33788ff32]:
+#+begin_src elisp
+#s(plz-response 2 200
+                ((date . "Sun, 24 Mar 2024 10:28:40 GMT")
+                 (content-type . "application/json")
+                 (content-length . "429")
+                 (server . "gunicorn/19.9.0")
+                 (access-control-allow-origin . "*")
+                 (access-control-allow-credentials . "true"))
+                "{\n  \"slideshow\": {\n    \"author\": \"Yours Truly\", \n    
\"date\": \"date of publication\", \n    \"slides\": [\n      {\n        
\"title\": \"Wake up to WonderWidgets!\", \n        \"type\": \"all\"\n      }, 
\n      {\n        \"items\": [\n          \"Why <em>WonderWidgets</em> are 
great\", \n          \"Who <em>buys</em> WonderWidgets\"\n        ], \n        
\"title\": \"Overview\", \n        \"type\": \"all\"\n      }\n    ], \n    
\"title\": \"Sample Slide Sho [...]
+#+end_src
+
+** Error Handling
+
+This library uses a process filter to handle streaming HTTP responses
+retrieved with curl. Media types that stream data typically trigger
+callbacks that execute user-defined code. If an error occurs within
+this code, the process will be terminated. Synchronous requests will
+signal a ~plz-media-type-filter-error~ with the error message, HTTP
+response, and cause included as error data. Asynchronous requests will
+receive a ~plz-media-type-filter-error~ structure in the ~ELSE~
+callback. This structure, derived from ~plz-error~, contains an
+additional ~cause~ slot.
+
+* Credits
+
+- Thanks to [[https://github.com/ahyatt][ahyatt]] and 
[[https://github.com/alphapapa][alphapapa]] for their help and advice.
+
+** Copyright assignment
+
+This package is part of [[https://www.gnu.org/software/emacs/][GNU Emacs]], 
being distributed in [[https://elpa.gnu.org/][GNU ELPA]].
+Contributions to this project must follow GNU guidelines, which means
+that, as with other parts of Emacs, patches of more than a few lines
+must be accompanied by having assigned copyright for the contribution
+to the FSF.  Contributors who wish to do so may contact
+[[mailto:emacs-devel@gnu.org][emacs-devel@gnu.org]] to request the assignment 
form.
+
+* License
+:PROPERTIES:
+:TOC:      :ignore (this)
+:END:
+
+GPLv3
+
+* COMMENT Export setup :noexport:
+:PROPERTIES:
+:TOC:      :ignore (this descendants)
+:END:
+
+# Copied from org-super-agenda's readme, in which much was borrowed
+# from Org's =org-manual.org=.
+
+#+OPTIONS: broken-links:t *:t
+
+** Info export options
+
+#+TEXINFO_DIR_CATEGORY: Emacs
+#+TEXINFO_DIR_TITLE: Plz Event Source: (plz-media-type)
+#+TEXINFO_DIR_DESC: A plz.el media type to handle Server-Sent Events
+
+# NOTE: We could use these, but that causes a pointless error,
+# "org-compile-file: File "..README.info" wasn't produced...", so we
+# just rename the files in the after-save-hook instead.
+
+# #+TEXINFO_FILENAME: plz-media-type.info
+# #+EXPORT_FILE_NAME: plz-media-type.texi
+
+** File-local variables
+
+# NOTE: Setting org-comment-string buffer-locally is a nasty hack to
+# work around GitHub's org-ruby's HTML rendering, which does not
+# respect noexport tags.  The only way to hide this tree from its
+# output is to use the COMMENT keyword, but that prevents Org from
+# processing the export options declared in it.  So since these
+# file-local variables don't affect org-ruby, wet set
+# org-comment-string to an unused keyword, which prevents Org from
+# deleting this tree from the export buffer, which allows it to find
+# the export options in it.  And since org-export does respect the
+# noexport tag, the tree is excluded from the info page.
+
+# Local Variables:
+# eval: (require 'org-make-toc)
+# after-save-hook: (lambda nil (when (and (require 'ox-texinfo nil t) 
(org-texinfo-export-to-info)) (delete-file "README.texi") (rename-file 
"README.info" "plz-media-type.info" t)))
+# before-save-hook: org-make-toc
+# org-export-with-properties: ()
+# org-export-with-title: t
+# org-export-initial-scope: buffer
+# org-comment-string: "NOTCOMMENT"
+# End:
diff --git a/checkout b/checkout
new file mode 100755
index 0000000000..bb2f71b2e2
--- /dev/null
+++ b/checkout
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+set -e
+set -o pipefail
+mkdir -p vendor
+wget -q -O vendor/plz.el 
https://raw.githubusercontent.com/r0man/plz.el/plz-stream/plz.el
+if [[ ! -z "$GITHUB_ENV" ]]; then
+    echo "EMACSLOADPATH=vendor:$EMACSLOADPATH" >> $GITHUB_ENV
+else
+    echo "Please add the vendor directory to your shell profile:"
+    echo 'export EMACSLOADPATH="vendor:$EMACSLOADPATH"'
+fi
diff --git a/makem.sh b/makem.sh
new file mode 100755
index 0000000000..3985ff7dda
--- /dev/null
+++ b/makem.sh
@@ -0,0 +1,1265 @@
+#!/usr/bin/env bash
+
+# * makem.sh --- Script to aid building and testing Emacs Lisp packages
+
+# URL: https://github.com/alphapapa/makem.sh
+# Version: 0.6-pre
+
+# * Commentary:
+
+# makem.sh is a script that helps to build, lint, and test Emacs Lisp
+# packages.  It aims to make linting and testing as simple as possible
+# without requiring per-package configuration.
+
+# It works similarly to a Makefile in that "rules" are called to
+# perform actions such as byte-compiling, linting, testing, etc.
+
+# Source and test files are discovered automatically from the
+# project's Git repo, and package dependencies within them are parsed
+# automatically.
+
+# Output is simple: by default, there is no output unless errors
+# occur.  With increasing verbosity levels, more detail gives positive
+# feedback.  Output is colored by default to make reading easy.
+
+# The script can run Emacs with the developer's local Emacs
+# configuration, or with a clean, "sandbox" configuration that can be
+# optionally removed afterward.  This is especially helpful when
+# upstream dependencies may have released new versions that differ
+# from those installed in the developer's personal configuration.
+
+# * License:
+
+# This program 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, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+# * Functions
+
+function usage {
+    cat <<EOF
+$0 [OPTIONS] RULES...
+
+Linter- and test-specific rules will error when their linters or tests
+are not found.  With -vv, rules that run multiple rules will show a
+message for unavailable linters or tests.
+
+Rules:
+  all      Run all lints and tests.
+  compile  Byte-compile source files.
+
+  lint           Run all linters, ignoring unavailable ones.
+  lint-checkdoc  Run checkdoc.
+  lint-compile   Byte-compile source files with warnings as errors.
+  lint-declare   Run check-declare.
+  lint-elsa      Run Elsa (not included in "lint" rule).
+  lint-indent    Lint indentation.
+  lint-package   Run package-lint.
+  lint-regexps   Run relint.
+
+  test, tests           Run all tests, ignoring missing test types.
+  test-buttercup        Run Buttercup tests.
+  test-ert              Run ERT tests.
+  test-ert-interactive  Run ERT tests interactively.
+
+  batch        Run Emacs in batch mode, loading project source and test files
+               automatically, with remaining args (after "--") passed to Emacs.
+  interactive  Run Emacs interactively, loading project source and test files
+               automatically, with remaining args (after "--") passed to Emacs.
+
+Options:
+  -d, --debug    Print debug info.
+  -h, --help     I need somebody!
+  -v, --verbose  Increase verbosity, up to -vvv.
+  --no-color     Disable color output.
+
+  --debug-load-path  Print load-path from inside Emacs.
+
+  -E, --emacs PATH  Run Emacs at PATH.
+
+  -e, --exclude FILE  Exclude FILE from linting and testing.
+  -f, --file FILE     Check FILE in addition to discovered files.
+
+  -c, --compile-batch  Batch-compile files (instead of separately; quicker, but
+                                            may hide problems).
+  -C, --no-compile     Don't compile files automatically.
+
+Sandbox options:
+  -s[DIR], --sandbox[=DIR]  Run Emacs with an empty config in a sandbox DIR.
+                            If DIR does not exist, make it.  If DIR is not
+                            specified, use a temporary sandbox directory and
+                            delete it afterward, implying --install-deps and
+                            --install-linters.
+  --install-deps            Automatically install package dependencies.
+  --install-linters         Automatically install linters.
+  -i, --install PACKAGE     Install PACKAGE before running rules.
+
+  An Emacs version-specific subdirectory is automatically made inside
+  the sandbox, allowing testing with multiple Emacs versions.  When
+  specifying a sandbox directory, use options --install-deps and
+  --install-linters on first-run and omit them afterward to save time.
+
+Source files are automatically discovered from git, or may be
+specified with options.  Package dependencies are discovered from
+"Package-Requires" headers in source files, from -pkg.el files, and
+from a Cask file.
+EOF
+}
+
+# ** Elisp
+
+# These functions return a path to an elisp file which can be loaded
+# by Emacs on the command line with -l or --load.
+
+function elisp-buttercup-file {
+    # The function buttercup-run, which is called by buttercup-run-discover,
+    # signals an error if it can't find any Buttercup test suites.  We don't
+    # want that to be an error, so we define advice which ignores that error.
+    local file=$(mktemp)
+    cat >$file <<EOF
+(defun makem-buttercup-run (oldfun &rest r)
+  "Call buttercup-run only if \`buttercup-suites' is non-nil."
+  (when buttercup-suites
+    (apply oldfun r)))
+
+(advice-add #'buttercup-run :around #'makem-buttercup-run)
+EOF
+    echo $file
+}
+
+function elisp-elint-file {
+    local file=$(mktemp)
+    cat >$file <<EOF
+(require 'cl-lib)
+(require 'elint)
+(defun makem-elint-file (file)
+  (let ((errors 0))
+    (cl-letf (((symbol-function 'orig-message) (symbol-function 'message))
+              ((symbol-function 'message) (symbol-function 'ignore))
+              ((symbol-function 'elint-output)
+               (lambda (string)
+                 (cl-incf errors)
+                 (orig-message "%s" string))))
+      (elint-file file)
+      ;; NOTE: \`errors' is not actually the number of errors, because
+      ;; it's incremented for non-error header strings as well.
+      (kill-emacs errors))))
+EOF
+    echo "$file"
+}
+
+function elisp-checkdoc-file {
+    # Since checkdoc doesn't have a batch function that exits non-zero
+    # when errors are found, we make one.
+    local file=$(mktemp)
+
+    cat >$file <<EOF
+(defvar makem-checkdoc-errors-p nil)
+
+(defun makem-checkdoc-files-and-exit ()
+  "Run checkdoc-file on files remaining on command line, exiting non-zero if 
there are warnings."
+  (let* ((files (mapcar #'expand-file-name command-line-args-left))
+         (checkdoc-create-error-function
+          (lambda (text start end &optional unfixable)
+            (let ((msg (concat (checkdoc-buffer-label) ":"
+                               (int-to-string (count-lines (point-min) (or 
start (point-min))))
+                               ": " text)))
+              (message msg)
+              (setq makem-checkdoc-errors-p t)
+              ;; Return nil because we *are* generating a buffered list of 
errors.
+              nil))))
+    (mapcar #'checkdoc-file files)
+    (when makem-checkdoc-errors-p
+      (kill-emacs 1))))
+
+(setq checkdoc-spellcheck-documentation-flag t)
+(makem-checkdoc-files-and-exit)
+EOF
+    echo $file
+}
+
+function elisp-byte-compile-file {
+    # This seems to be the only way to make byte-compilation signal
+    # errors for warnings AND display all warnings rather than only
+    # the first one.
+    local file=$(mktemp)
+    # TODO: Add file to $paths_temp in other elisp- functions.
+    paths_temp+=("$file")
+
+    cat >"$file" <<EOF
+(defun makem-batch-byte-compile (&rest args)
+  ""
+  (let ((num-errors 0))
+    ;; NOTE: Only accepts files as args, not directories.
+    (dolist (file command-line-args-left)
+      (unless (makem-byte-compile-file file)
+        (cl-incf num-errors)))
+    (zerop num-errors)))
+
+(defun makem-byte-compile-file (filename &optional load)
+  "Call \`byte-compile-warn', returning nil if there are any warnings."
+  (let ((num-warnings 0))
+    (cl-letf (((symbol-function 'byte-compile-warn)
+               (lambda (format &rest args)
+                 ;; Copied from \`byte-compile-warn'.
+                 (cl-incf num-warnings)
+                 (setq format (apply #'format-message format args))
+                 (byte-compile-log-warning format t :warning))))
+      (byte-compile-file filename load))
+    (zerop num-warnings)))
+EOF
+    echo "$file"
+}
+
+function elisp-check-declare-file {
+    # Since check-declare doesn't have a batch function that exits
+    # non-zero when errors are found, we make one.
+    local file=$(mktemp)
+
+    cat >$file <<EOF
+(require 'check-declare)
+
+(defun makem-check-declare-files-and-exit ()
+  "Run check-declare-files on files remaining on command line, exiting 
non-zero if there are warnings."
+  (let* ((files (mapcar #'expand-file-name command-line-args-left))
+         (errors (apply #'check-declare-files files)))
+    (when errors
+      (with-current-buffer check-declare-warning-buffer
+        (print (buffer-string)))
+      (kill-emacs 1))))
+EOF
+    echo $file
+}
+
+function elisp-lint-indent-file {
+    # This function prints warnings for indentation errors and exits
+    # non-zero when errors are found.
+    local file=$(mktemp)
+
+    cat >"$file" <<EOF
+(require 'cl-lib)
+
+(defun makem-lint-indent-batch-and-exit ()
+  "Print warnings for files which are not indented properly, then exit.
+Exits non-zero if mis-indented lines are found.  Checks files in
+'command-line-args-left'."
+  (let ((errors-p))
+    (cl-labels ((lint-file (file)
+                           (find-file file)
+                           (let ((inhibit-message t))
+                             (indent-region (point-min) (point-max)))
+                           (when buffer-undo-list
+                             ;; Indentation changed: warn for each line.
+                             (dolist (line (undo-lines buffer-undo-list))
+                               (message "%s:%s: Indentation mismatch" 
(buffer-name) line))
+                             (setf errors-p t)))
+                (undo-pos (entry)
+                           (cl-typecase (car entry)
+                             (number (car entry))
+                             (string (abs (cdr entry)))))
+                (undo-lines (undo-list)
+                            ;; Return list of lines changed in UNDO-LIST.
+                            (nreverse (cl-loop for elt in undo-list
+                                               for pos = (undo-pos elt)
+                                               when pos
+                                               collect (line-number-at-pos 
pos)))))
+      (mapc #'lint-file (mapcar #'expand-file-name command-line-args-left))
+      (when errors-p
+        (kill-emacs 1)))))
+EOF
+
+    echo "$file"
+}
+
+function elisp-package-initialize-file {
+    local file=$(mktemp)
+
+    cat >$file <<EOF
+(require 'package)
+(setq package-archives (list (cons "gnu" "https://elpa.gnu.org/packages/";)
+                             (cons "melpa" "https://melpa.org/packages/";)
+                             (cons "melpa-stable" 
"https://stable.melpa.org/packages/";)))
+$elisp_org_package_archive
+(package-initialize)
+EOF
+    echo $file
+}
+
+# ** Emacs
+
+function run_emacs {
+    # NOTE: The sandbox args need to come before the package
+    # initialization so Emacs will use the sandbox's packages.
+    local emacs_command=(
+        "${emacs_command[@]}"
+        -Q
+        --eval "(setq load-prefer-newer t)"
+        "${args_debug[@]}"
+        "${args_sandbox[@]}"
+        -l $package_initialize_file
+        $arg_batch
+        "${args_load_paths[@]}"
+    )
+
+    # Show debug message with load-path from inside Emacs.
+    [[ $debug_load_path ]] \
+        && debug $("${emacs_command[@]}" \
+                       --batch \
+                       --eval "(message \"LOAD-PATH: %s\" load-path)" \
+                    2>&1)
+
+    # Set output file.
+    output_file=$(mktemp) || die "Unable to make output file."
+    paths_temp+=("$output_file")
+
+    # Run Emacs.
+    debug "run_emacs: ${emacs_command[@]} $@ &>\"$output_file\""
+    "${emacs_command[@]}" "$@" &>"$output_file"
+
+    # Check exit code and output.
+    exit=$?
+    [[ $exit != 0 ]] \
+        && debug "Emacs exited non-zero: $exit"
+
+    [[ $verbose -gt 1 || $exit != 0 ]] \
+        && cat $output_file
+
+    return $exit
+}
+
+# ** Compilation
+
+function batch-byte-compile {
+    debug "batch-byte-compile: ERROR-ON-WARN:$compile_error_on_warn"
+
+    [[ $compile_error_on_warn ]] && local error_on_warn=(--eval "(setq 
byte-compile-error-on-warn t)")
+
+    run_emacs \
+        --load "$(elisp-byte-compile-file)" \
+        "${error_on_warn[@]}" \
+        --eval "(unless (makem-batch-byte-compile) (kill-emacs 1))" \
+        "$@"
+}
+
+function byte-compile-file {
+    debug "byte-compile: ERROR-ON-WARN:$compile_error_on_warn"
+    local file="$1"
+
+    [[ $compile_error_on_warn ]] && local error_on_warn=(--eval "(setq 
byte-compile-error-on-warn t)")
+
+    # FIXME: Why is the line starting with "&& verbose 3" not indented 
properly?  Emacs insists on indenting it back a level.
+    run_emacs \
+        --load "$(elisp-byte-compile-file)" \
+        "${error_on_warn[@]}" \
+        --eval "(unless (makem-byte-compile-file \"$file\") (kill-emacs 1))" \
+        && verbose 3 "Compiling $file finished without errors." \
+            || { verbose 3 "Compiling file failed: $file"; return 1; }
+}
+
+# ** Files
+
+function dirs-project {
+    # Echo list of directories to be used in load path.
+    files-project-feature | dirnames
+    files-project-test | dirnames
+}
+
+function files-project-elisp {
+    # Echo list of Elisp files in project.
+    git ls-files 2>/dev/null \
+        | egrep "\.el$" \
+        | filter-files-exclude-default \
+        | filter-files-exclude-args
+}
+
+function files-project-feature {
+    # Echo list of Elisp files that are not tests and provide a feature.
+    files-project-elisp \
+        | egrep -v "$test_files_regexp" \
+        | filter-files-feature
+}
+
+function files-project-test {
+    # Echo list of Elisp test files.
+    files-project-elisp | egrep "$test_files_regexp"
+}
+
+function dirnames {
+    # Echo directory names for files on STDIN.
+    while read file
+    do
+        dirname "$file"
+    done
+}
+
+function filter-files-exclude-default {
+    # Filter out paths (STDIN) which should be excluded by default.
+    egrep -v "(/\.cask/|-autoloads.el|.dir-locals)"
+}
+
+function filter-files-exclude-args {
+    # Filter out paths (STDIN) which are excluded with --exclude.
+    if [[ ${files_exclude[@]} ]]
+    then
+        (
+            # We use a subshell to set IFS temporarily so we can send
+            # the list of files to grep -F.  This is ugly but more
+            # correct than replacing spaces with line breaks.  Note
+            # that, for some reason, using IFS="\n" or IFS='\n' doesn't
+            # work, and a literal line break seems to be required.
+            IFS="
+"
+            grep -Fv "${files_exclude[*]}"
+        )
+    else
+        cat
+    fi
+}
+
+function filter-files-feature {
+    # Read paths on STDIN and echo ones that (provide 'a-feature).
+    while read path
+    do
+        egrep "^\\(provide '" "$path" &>/dev/null \
+            && echo "$path"
+    done
+}
+
+function args-load-files {
+    # For file in $@, echo "--load $file".
+    for file in "$@"
+    do
+        sans_extension=${file%%.el}
+        printf -- '--load %q ' "$sans_extension"
+    done
+}
+
+function args-load-path {
+    # Echo load-path arguments.
+    for path in $(dirs-project | sort -u)
+    do
+        printf -- '-L %q ' "$path"
+    done
+}
+
+function test-files-p {
+    # Return 0 if $files_project_test is non-empty.
+    [[ "${files_project_test[@]}" ]]
+}
+
+function buttercup-tests-p {
+    # Return 0 if Buttercup tests are found.
+    test-files-p || die "No tests found."
+    debug "Checking for Buttercup tests..."
+
+    grep "(require 'buttercup)" "${files_project_test[@]}" &>/dev/null
+}
+
+function ert-tests-p {
+    # Return 0 if ERT tests are found.
+    test-files-p || die "No tests found."
+    debug "Checking for ERT tests..."
+
+    # We check for this rather than "(require 'ert)", because ERT may
+    # already be loaded in Emacs and might not be loaded with
+    # "require" in a test file.
+    grep "(ert-deftest" "${files_project_test[@]}" &>/dev/null
+}
+
+function package-main-file {
+    # Echo the package's main file.
+    file_pkg=$(git ls-files ./*-pkg.el 2>/dev/null)
+
+    if [[ $file_pkg ]]
+    then
+        # Use *-pkg.el file if it exists.
+        echo "$file_pkg"
+    else
+        # Use shortest filename (a sloppy heuristic that will do for now).
+        for file in "${files_project_feature[@]}"
+        do
+            echo ${#file} "$file"
+        done \
+            | sort -h \
+            | head -n1 \
+            | sed -r 's/^[[:digit:]]+ //'
+    fi
+}
+
+function dependencies {
+    # Echo list of package dependencies.
+
+    # Search package headers.  Use -a so grep won't think that an Elisp file 
containing
+    # control characters (rare, but sometimes necessary) is binary and refuse 
to search it.
+    egrep -a -i '^;; Package-Requires: ' $(files-project-feature) 
$(files-project-test) \
+        | egrep -o '\([^([:space:]][^)]*\)' \
+        | egrep -o '^[^[:space:])]+' \
+        | sed -r 's/\(//g' \
+        | egrep -v '^emacs$'  # Ignore Emacs version requirement.
+
+    # Search Cask file.
+    if [[ -r Cask ]]
+    then
+        egrep '\(depends-on "[^"]+"' Cask \
+            | sed -r -e 's/\(depends-on "([^"]+)".*/\1/g'
+    fi
+
+    # Search -pkg.el file.
+    if [[ $(git ls-files ./*-pkg.el 2>/dev/null) ]]
+    then
+        sed -nr 's/.*\(([-[:alnum:]]+)[[:blank:]]+"[.[:digit:]]+"\).*/\1/p' 
$(git ls-files ./*-pkg.el 2>/dev/null)
+    fi
+}
+
+# ** Sandbox
+
+function sandbox {
+    verbose 2 "Initializing sandbox..."
+
+    # *** Sandbox arguments
+
+    # MAYBE: Optionally use branch-specific sandbox?
+
+    # Check or make user-emacs-directory.
+    if [[ $sandbox_dir ]]
+    then
+        # Directory given as argument: ensure it exists.
+        if ! [[ -d $sandbox_dir ]]
+        then
+            debug "Making sandbox directory: $sandbox_dir"
+            mkdir -p "$sandbox_dir" || die "Unable to make sandbox dir."
+        fi
+
+        # Add Emacs version-specific subdirectory, creating if necessary.
+        sandbox_dir="$sandbox_dir/$(emacs-version)"
+        if ! [[ -d $sandbox_dir ]]
+        then
+            mkdir "$sandbox_dir" || die "Unable to make sandbox subdir: 
$sandbox_dir"
+        fi
+    else
+        # Not given: make temp directory, and delete it on exit.
+        local sandbox_dir=$(mktemp -d) || die "Unable to make sandbox dir."
+        paths_temp+=("$sandbox_dir")
+    fi
+
+    # Make argument to load init file if it exists.
+    init_file="$sandbox_dir/init.el"
+
+    # Set sandbox args.  This is a global variable used by the run_emacs 
function.
+    args_sandbox=(
+        --title "makem.sh: $(basename $(pwd)) (sandbox: $sandbox_dir)"
+        --eval "(setq user-emacs-directory (file-truename \"$sandbox_dir\"))"
+        --load package
+        --eval "(setq package-user-dir (expand-file-name \"elpa\" 
user-emacs-directory))"
+        --eval "(setq user-init-file (file-truename \"$init_file\"))"
+    )
+
+    # Add package-install arguments for dependencies.
+    if [[ $install_deps ]]
+    then
+        local deps=($(dependencies))
+        debug "Installing dependencies: ${deps[@]}"
+
+        for package in "${deps[@]}"
+        do
+            args_sandbox_package_install+=(--eval "(package-install 
'$package)")
+        done
+    fi
+
+    # Add package-install arguments for linters.
+    if [[ $install_linters ]]
+    then
+        debug "Installing linters: package-lint relint"
+
+        args_sandbox_package_install+=(
+            --eval "(package-install 'elsa)"
+            --eval "(package-install 'package-lint)"
+            --eval "(package-install 'relint)")
+    fi
+
+    # *** Install packages into sandbox
+
+    if [[ ${args_sandbox_package_install[@]} ]]
+    then
+        # Initialize the sandbox (installs packages once rather than for every 
rule).
+        verbose 1 "Installing packages into sandbox..."
+
+        run_emacs \
+            --eval "(package-refresh-contents)" \
+            "${args_sandbox_package_install[@]}" \
+            && success "Packages installed." \
+                || die "Unable to initialize sandbox."
+    fi
+
+    verbose 2 "Sandbox initialized."
+}
+
+# ** Utility
+
+function cleanup {
+    # Remove temporary paths (${paths_temp[@]}).
+
+    for path in "${paths_temp[@]}"
+    do
+        if [[ $debug ]]
+        then
+            debug "Debugging enabled: not deleting temporary path: $path"
+        elif [[ -r $path ]]
+        then
+            rm -rf "$path"
+        else
+            debug "Temporary path doesn't exist, not deleting: $path"
+        fi
+    done
+}
+
+function echo-unset-p {
+    # Echo 0 if $1 is set, otherwise 1.  IOW, this returns the exit
+    # code of [[ $1 ]] as STDOUT.
+    [[ $1 ]]
+    echo $?
+}
+
+function ensure-package-available {
+    # If package $1 is available, return 0.  Otherwise, return 1, and
+    # if $2 is set, give error otherwise verbose.  Outputting messages
+    # here avoids repetition in callers.
+    local package=$1
+    local direct_p=$2
+
+    if ! run_emacs --load $package &>/dev/null
+    then
+        if [[ $direct_p ]]
+        then
+            error "$package not available."
+        else
+            verbose 2 "$package not available."
+        fi
+        return 1
+    fi
+}
+
+function ensure-tests-available {
+    # If tests of type $1 (like "ERT") are available, return 0.  Otherwise, if
+    # $2 is set, give an error and return 1; otherwise give verbose message.  
$1
+    # should have a corresponding predicate command, like ert-tests-p for ERT.
+    local test_name=$1
+    local test_command="${test_name,,}-tests-p"  # Converts name to lowercase.
+    local direct_p=$2
+
+    if ! $test_command
+    then
+        if [[ $direct_p ]]
+        then
+            error "$test_name tests not found."
+        else
+            verbose 2 "$test_name tests not found."
+        fi
+        return 1
+    fi
+}
+
+function echo_color {
+    # This allows bold, italic, etc. without needing a function for
+    # each variation.
+    local color_code="COLOR_$1"
+    shift
+
+    if [[ $color ]]
+    then
+        echo -e "${!color_code}${@}${COLOR_off}"
+    else
+        echo "$@"
+    fi
+}
+function debug {
+    if [[ $debug ]]
+    then
+        function debug {
+            echo_color yellow "DEBUG ($(ts)): $@" >&2
+        }
+        debug "$@"
+    else
+        function debug {
+            true
+        }
+    fi
+}
+function error {
+    echo_color red "ERROR ($(ts)): $@" >&2
+    ((errors++))
+    return 1
+}
+function die {
+    [[ $@ ]] && error "$@"
+    exit $errors
+}
+function log {
+    echo "LOG ($(ts)): $@" >&2
+}
+function log_color {
+    local color_name=$1
+    shift
+    echo_color $color_name "LOG ($(ts)): $@" >&2
+}
+function success {
+    if [[ $verbose -ge 2 ]]
+    then
+        log_color green "$@" >&2
+    fi
+}
+function verbose {
+    # $1 is the verbosity level, rest are echoed when appropriate.
+    if [[ $verbose -ge $1 ]]
+    then
+        [[ $1 -eq 1 ]] && local color_name=blue
+        [[ $1 -eq 2 ]] && local color_name=cyan
+        [[ $1 -ge 3 ]] && local color_name=white
+
+        shift
+        log_color $color_name "$@" >&2
+    fi
+}
+
+function ts {
+    date "+%Y-%m-%d %H:%M:%S"
+}
+
+function emacs-version {
+    # Echo Emacs version number.
+
+    # Don't use run_emacs function, which does more than we need.
+    "${emacs_command[@]}" -Q --batch --eval "(princ emacs-version)" \
+        || die "Unable to get Emacs version."
+}
+
+function rule-p {
+    # Return 0 if $1 is a rule.
+    [[ $1 =~ ^(lint-?|tests?)$ ]] \
+        || [[ $1 =~ ^(batch|interactive)$ ]] \
+        || [[ $(type -t "$2" 2>/dev/null) =~ function ]]
+}
+
+# * Rules
+
+# These functions are intended to be called as rules, like a Makefile.
+# Some rules test $1 to determine whether the rule is being called
+# directly or from a meta-rule; if directly, an error is given if the
+# rule can't be run, otherwise it's skipped.
+
+function all {
+    verbose 1 "Running all rules..."
+
+    lint
+    tests
+}
+
+function compile-batch {
+    [[ $compile ]] || return 0
+    unset compile  # Only compile once.
+
+    verbose 1 "Compiling..."
+    verbose 2 "Batch-compiling files..."
+    debug "Byte-compile files: ${files_project_byte_compile[@]}"
+
+    batch-byte-compile "${files_project_byte_compile[@]}"
+}
+
+function compile-each {
+    [[ $compile ]] || return 0
+    unset compile  # Only compile once.
+
+    verbose 1 "Compiling..."
+    debug "Byte-compile files: ${files_project_byte_compile[@]}"
+
+    local compile_errors
+    for file in "${files_project_byte_compile[@]}"
+    do
+        verbose 2 "Compiling file: $file..."
+        byte-compile-file "$file" \
+            || compile_errors=t
+    done
+
+    [[ ! $compile_errors ]]
+}
+
+function compile {
+    if [[ $compile = batch ]]
+    then
+        compile-batch "$@"
+    else
+        compile-each "$@"
+    fi
+    local status=$?
+
+    if [[ $compile_error_on_warn ]]
+    then
+        # Linting: just return status code, because lint rule will print 
messages.
+        [[ $status = 0 ]]
+    else
+        # Not linting: print messages here.
+        [[ $status = 0 ]] \
+            && success "Compiling finished without errors." \
+                || error "Compiling failed."
+    fi
+}
+
+function batch {
+    # Run Emacs in batch mode with ${args_batch_interactive[@]} and
+    # with project source and test files loaded.
+    verbose 1 "Executing Emacs with arguments: ${args_batch_interactive[@]}"
+
+    run_emacs \
+        $(args-load-files "${files_project_feature[@]}" 
"${files_project_test[@]}") \
+        "${args_batch_interactive[@]}"
+}
+
+function interactive {
+    # Run Emacs interactively.  Most useful with --sandbox and --install-deps.
+    local load_file_args=$(args-load-files "${files_project_feature[@]}" 
"${files_project_test[@]}")
+    verbose 1 "Running Emacs interactively..."
+    verbose 2 "Loading files: ${load_file_args//--load /}"
+
+    [[ $compile ]] && compile
+
+    unset arg_batch
+    run_emacs \
+        $load_file_args \
+        --eval "(load user-init-file)" \
+        "${args_batch_interactive[@]}"
+    arg_batch="--batch"
+}
+
+function lint {
+    verbose 1 "Linting..."
+
+    lint-checkdoc
+    lint-compile
+    lint-declare
+    # NOTE: Elint doesn't seem very useful at the moment.  See comment
+    # in lint-elint function.
+    # lint-elint
+    lint-indent
+    lint-package
+    lint-regexps
+}
+
+function lint-checkdoc {
+    verbose 1 "Linting checkdoc..."
+
+    local checkdoc_file="$(elisp-checkdoc-file)"
+    paths_temp+=("$checkdoc_file")
+
+    run_emacs \
+        --load="$checkdoc_file" \
+        "${files_project_feature[@]}" \
+        && success "Linting checkdoc finished without errors." \
+            || error "Linting checkdoc failed."
+}
+
+function lint-compile {
+    verbose 1 "Linting compilation..."
+
+    compile_error_on_warn=true
+    compile "${files_project_byte_compile[@]}" \
+        && success "Linting compilation finished without errors." \
+            || error "Linting compilation failed."
+    unset compile_error_on_warn
+}
+
+function lint-declare {
+    verbose 1 "Linting declarations..."
+
+    local check_declare_file="$(elisp-check-declare-file)"
+    paths_temp+=("$check_declare_file")
+
+    run_emacs \
+        --load "$check_declare_file" \
+        -f makem-check-declare-files-and-exit \
+        "${files_project_feature[@]}" \
+        && success "Linting declarations finished without errors." \
+            || error "Linting declarations failed."
+}
+
+function lint-elsa {
+    verbose 1 "Linting with Elsa..."
+
+    # MAYBE: Install Elsa here rather than in sandbox init, to avoid installing
+    # it when not needed.  However, we should be careful to be clear about when
+    # packages are installed, because installing them does execute code.
+    run_emacs \
+        --load elsa \
+        -f elsa-run-files-and-exit \
+        "${files_project_feature[@]}" \
+        && success "Linting with Elsa finished without errors." \
+            || error "Linting with Elsa failed."
+}
+
+function lint-elint {
+    # NOTE: Elint gives a lot of spurious warnings, apparently because it 
doesn't load files
+    # that are `require'd, so its output isn't very useful.  But in case it's 
improved in
+    # the future, and since this wrapper code already works, we might as well 
leave it in.
+    verbose 1 "Linting with Elint..."
+
+    local errors=0
+    for file in "${files_project_feature[@]}"
+    do
+        verbose 2 "Linting with Elint: $file..."
+        run_emacs \
+            --load "$(elisp-elint-file)" \
+            --eval "(makem-elint-file \"$file\")" \
+            && verbose 3 "Linting with Elint found no errors." \
+                || { error "Linting with Elint failed: $file"; ((errors++)) ; }
+    done
+
+    [[ $errors = 0 ]] \
+        && success "Linting with Elint finished without errors." \
+            || error "Linting with Elint failed."
+}
+
+function lint-indent {
+    verbose 1 "Linting indentation..."
+
+    # We load project source files as well, because they may contain
+    # macros with (declare (indent)) rules which must be loaded to set
+    # indentation.
+
+    run_emacs \
+        --load "$(elisp-lint-indent-file)" \
+        $(args-load-files "${files_project_feature[@]}" 
"${files_project_test[@]}") \
+        --funcall makem-lint-indent-batch-and-exit \
+        "${files_project_feature[@]}" "${files_project_test[@]}" \
+        && success "Linting indentation finished without errors." \
+            || error "Linting indentation failed."
+}
+
+function lint-package {
+    ensure-package-available package-lint $1 || return $(echo-unset-p $1)
+
+    verbose 1 "Linting package..."
+
+    run_emacs \
+        --load package-lint \
+        --eval "(setq package-lint-main-file \"$(package-main-file)\")" \
+        --funcall package-lint-batch-and-exit \
+        "${files_project_feature[@]}" \
+        && success "Linting package finished without errors." \
+            || error "Linting package failed."
+}
+
+function lint-regexps {
+    ensure-package-available relint $1 || return $(echo-unset-p $1)
+
+    verbose 1 "Linting regexps..."
+
+    run_emacs \
+        --load relint \
+        --funcall relint-batch \
+        "${files_project_source[@]}" \
+        && success "Linting regexps finished without errors." \
+            || error "Linting regexps failed."
+}
+
+function tests {
+    verbose 1 "Running all tests..."
+
+    test-ert
+    test-buttercup
+}
+
+function test-ert-interactive {
+    verbose 1 "Running ERT tests interactively..."
+
+    unset arg_batch
+    run_emacs \
+        $(args-load-files "${files_project_test[@]}") \
+        --eval "(ert-run-tests-interactively t)"
+    arg_batch="--batch"
+}
+
+function test-buttercup {
+    ensure-tests-available Buttercup $1 || return $(echo-unset-p $1)
+    compile || die
+
+    verbose 1 "Running Buttercup tests..."
+
+    local buttercup_file="$(elisp-buttercup-file)"
+    paths_temp+=("$buttercup_file")
+
+    run_emacs \
+        $(args-load-files "${files_project_test[@]}") \
+        -f buttercup-run \
+        && success "Buttercup tests finished without errors." \
+            || error "Buttercup tests failed."
+}
+
+function test-ert {
+    ensure-tests-available ERT $1 || return $(echo-unset-p $1)
+    compile || die
+
+    verbose 1 "Running ERT tests..."
+    debug "Test files: ${files_project_test[@]}"
+
+    run_emacs \
+        $(args-load-files "${files_project_test[@]}") \
+        -f ert-run-tests-batch-and-exit \
+        && success "ERT tests finished without errors." \
+            || error "ERT tests failed."
+}
+
+# * Defaults
+
+test_files_regexp='^((tests?|t)/)|-tests?.el$|^test-'
+
+emacs_command=("emacs")
+errors=0
+verbose=0
+compile=true
+arg_batch="--batch"
+compile=each
+
+# MAYBE: Disable color if not outputting to a terminal.  (OTOH, the
+# colorized output is helpful in CI logs, and I don't know if,
+# e.g. GitHub Actions logging pretends to be a terminal.)
+color=true
+
+# TODO: Using the current directory (i.e. a package's repo root directory) in
+# load-path can cause weird errors in case of--you guessed it--stale .ELC 
files,
+# the zombie problem that just won't die.  It's incredible how many different 
ways
+# this problem presents itself.  In this latest example, an old .ELC file, for 
a
+# .EL file that had since been renamed, was present on my local system, which 
meant
+# that an example .EL file that hadn't been updated was able to "require" that 
.ELC
+# file's feature without error.  But on another system (in this case, trying to
+# setup CI using GitHub Actions), the old .ELC was not present, so the example 
.EL
+# file was not able to load the feature, which caused a byte-compilation error.
+
+# In this case, I will prevent such example files from being compiled.  But in
+# general, this can cause weird problems that are tedious to debug.  I guess
+# the best way to fix it would be to actually install the repo's code as a
+# package into the sandbox, but doing that would require additional tooling,
+# pulling in something like Quelpa or package-build--and if the default recipe
+# weren't being used, the actual recipe would have to be fetched off MELPA or
+# something, which seems like getting too smart for our own good.
+
+# TODO: Emit a warning if .ELC files that don't match any .EL files are 
detected.
+
+# ** Colors
+
+COLOR_off='\e[0m'
+COLOR_black='\e[0;30m'
+COLOR_red='\e[0;31m'
+COLOR_green='\e[0;32m'
+COLOR_yellow='\e[0;33m'
+COLOR_blue='\e[0;34m'
+COLOR_purple='\e[0;35m'
+COLOR_cyan='\e[0;36m'
+COLOR_white='\e[0;37m'
+
+# ** Package system args
+
+args_package_archives=(
+    --eval "(add-to-list 'package-archives '(\"gnu\" . 
\"https://elpa.gnu.org/packages/\";) t)"
+    --eval "(add-to-list 'package-archives '(\"melpa\" . 
\"https://melpa.org/packages/\";) t)"
+)
+
+args_org_package_archives=(
+    --eval "(add-to-list 'package-archives '(\"org\" . 
\"https://orgmode.org/elpa/\";) t)"
+)
+
+args_package_init=(
+    --eval "(package-initialize)"
+)
+
+elisp_org_package_archive="(add-to-list 'package-archives '(\"org\" . 
\"https://orgmode.org/elpa/\";) t)"
+
+# * Args
+
+args=$(getopt -n "$0" \
+              -o dhce:E:i:s::vf:CO \
+              -l 
compile-batch,exclude:,emacs:,install-deps,install-linters,debug,debug-load-path,help,install:,verbose,file:,no-color,no-compile,no-org-repo,sandbox::
 \
+              -- "$@") \
+    || { usage; exit 1; }
+eval set -- "$args"
+
+while true
+do
+    case "$1" in
+        --install-deps)
+            install_deps=true
+            ;;
+        --install-linters)
+            install_linters=true
+            ;;
+        -d|--debug)
+            debug=true
+            verbose=2
+            args_debug=(--eval "(setq init-file-debug t)"
+                        --eval "(setq debug-on-error t)")
+            ;;
+        --debug-load-path)
+            debug_load_path=true
+            ;;
+        -h|--help)
+            usage
+            exit
+            ;;
+        -c|--compile-batch)
+            debug "Compiling files in batch mode"
+            compile=batch
+            ;;
+        -E|--emacs)
+            shift
+            emacs_command=($1)
+            ;;
+        -i|--install)
+            shift
+            args_sandbox_package_install+=(--eval "(package-install '$1)")
+            ;;
+        -s|--sandbox)
+            sandbox=true
+            shift
+            sandbox_dir="$1"
+
+            if ! [[ $sandbox_dir ]]
+            then
+                debug "No sandbox dir: installing dependencies."
+                install_deps=true
+            else
+                debug "Sandbox dir: $1"
+            fi
+            ;;
+        -v|--verbose)
+            ((verbose++))
+            ;;
+        -e|--exclude)
+            shift
+            debug "Excluding file: $1"
+            files_exclude+=("$1")
+            ;;
+        -f|--file)
+            shift
+            args_files+=("$1")
+            ;;
+        -O|--no-org-repo)
+            unset elisp_org_package_archive
+            ;;
+        --no-color)
+            unset color
+            ;;
+        -C|--no-compile)
+            unset compile
+            ;;
+        --)
+            # Remaining args (required; do not remove)
+            shift
+            rest=("$@")
+            break
+            ;;
+    esac
+
+    shift
+done
+
+debug "ARGS: $args"
+debug "Remaining args: ${rest[@]}"
+
+# Set package elisp (which depends on --no-org-repo arg).
+package_initialize_file="$(elisp-package-initialize-file)"
+paths_temp+=("$package_initialize_file")
+
+# * Main
+
+trap cleanup EXIT INT TERM
+
+# Discover project files.
+files_project_feature=($(files-project-feature))
+files_project_test=($(files-project-test))
+files_project_byte_compile=("${files_project_feature[@]}" 
"${files_project_test[@]}")
+
+if [[ ${args_files[@]} ]]
+then
+    # Add specified files.
+    files_project_feature+=("${args_files[@]}")
+    files_project_byte_compile+=("${args_files[@]}")
+fi
+
+debug "EXCLUDING FILES: ${files_exclude[@]}"
+debug "FEATURE FILES: ${files_project_feature[@]}"
+debug "TEST FILES: ${files_project_test[@]}"
+debug "BYTE-COMPILE FILES: ${files_project_byte_compile[@]}"
+debug "PACKAGE-MAIN-FILE: $(package-main-file)"
+
+if ! [[ ${files_project_feature[@]} ]]
+then
+    error "No files specified and not in a git repo."
+    exit 1
+fi
+
+# Set load path.
+args_load_paths=($(args-load-path))
+debug "LOAD PATH ARGS: ${args_load_paths[@]}"
+
+# If rules include linters and sandbox-dir is unspecified, install
+# linters automatically.
+if [[ $sandbox && ! $sandbox_dir ]] && [[ "${rest[@]}" =~ lint ]]
+then
+    debug "Installing linters automatically."
+    install_linters=true
+fi
+
+# Initialize sandbox.
+[[ $sandbox ]] && sandbox
+
+# Run rules.
+for rule in "${rest[@]}"
+do
+    if [[ $batch || $interactive ]]
+    then
+        debug "Adding batch/interactive argument: $rule"
+        args_batch_interactive+=("$rule")
+
+    elif [[ $rule = batch ]]
+    then
+        # Remaining arguments are passed to Emacs.
+        batch=true
+    elif [[ $rule = interactive ]]
+    then
+        # Remaining arguments are passed to Emacs.
+        interactive=true
+
+    elif type -t "$rule" 2>/dev/null | grep function &>/dev/null
+    then
+        # Pass called-directly as $1 to indicate that the rule is
+        # being called directly rather than from a meta-rule.
+        $rule called-directly
+    elif [[ $rule = test ]]
+    then
+        # Allow the "tests" rule to be called as "test".  Since "test"
+        # is a shell builtin, this workaround is required.
+        tests
+    else
+        error "Invalid rule: $rule"
+    fi
+done
+
+# Batch/interactive rules.
+[[ $batch ]] && batch
+[[ $interactive ]] && interactive
+
+if [[ $errors -gt 0 ]]
+then
+    log_color red "Finished with $errors errors."
+else
+    success "Finished without errors."
+fi
+
+exit $errors
diff --git a/plz-media-type.el b/plz-media-type.el
new file mode 100644
index 0000000000..4216cba7b9
--- /dev/null
+++ b/plz-media-type.el
@@ -0,0 +1,656 @@
+;;; plz-media-type.el --- plz content types -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2019-2023  Free Software Foundation, Inc.
+
+;; Author: r0man <roman@burningswell.com>
+;; Maintainer: r0man <roman@burningswell.com>
+;; URL: https://github.com/r0man/plz-media-type.el
+;; Version: 0.1-pre
+;; Package-Requires: ((emacs "26.3"))
+;; Keywords: comm, network, http
+
+;; This file is part of GNU Emacs.
+
+;;; License:
+
+;; This program 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, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library provides enhanced handling of MIME types for HTTP
+;; requests within Emacs.  It utilizes the 'plz' library for
+;; networking calls, extending it to process responses based on the
+;; Content-Type header.  This library defines various classes and
+;; methods for parsing and processing standard MIME types, including
+;; JSON, XML, HTML, and binary data.  It allows for extensible
+;; processing of additional types through subclassing.
+
+;;; Code:
+
+;;;; Requirements
+
+(require 'cl-lib)
+(require 'eieio)
+(require 'plz)
+
+(define-error 'plz-media-type-filter-error
+              "plz-media-type: Error in process filter"
+              'plz-error)
+
+(cl-defstruct (plz-media-type-filter-error (:include plz-error))
+  cause)
+
+(defclass plz-media-type ()
+  ((type
+    :documentation "The media type."
+    :initarg :type
+    :type symbol)
+   (subtype
+    :documentation "The media subtype."
+    :initarg :subtype
+    :subtype symbol)
+   (parameters
+    :documentation "The parameters of the media type."
+    :initarg :parameters
+    :initform nil
+    :subtype list))
+  "A class that hold information about the type, subtype and
+parameters of a media type.  It is meant to be sub-classed to
+handle the processing of different media types and supports the
+processing of streaming and non-streaming HTTP responses.")
+
+(defun plz-media-type-charset (media-type)
+  "Return the character set of the MEDIA-TYPE."
+  (with-slots (parameters) media-type
+    (alist-get "charset" parameters nil nil #'equal)))
+
+(defun plz-media-type-coding-system (media-type)
+  "Return the coding system of the MEDIA-TYPE."
+  (coding-system-from-name (or (plz-media-type-charset media-type) "UTF-8")))
+
+(defun plz-media-type-name (media-type)
+  "Return the name of the MEDIA-TYPE as a string."
+  (with-slots (type subtype) media-type
+    (format "%s/%s" type subtype)))
+
+(defun plz-media-type-symbol (media-type)
+  "Return the name of the MEDIA-TYPE as a symbol."
+  (intern (plz-media-type-name media-type)))
+
+(cl-defgeneric plz-media-type-else (media-type error)
+  "Transform the ERROR into a format suitable for MEDIA-TYPE.")
+
+(cl-defgeneric plz-media-type-then (media-type response)
+  "Transform the RESPONSE into a format suitable for MEDIA-TYPE.")
+
+(cl-defgeneric plz-media-type-process (media-type process chunk)
+  "Process the CHUNK according to MEDIA-TYPE using PROCESS.")
+
+(cl-defmethod plz-media-type-else ((_ (eql nil)) error)
+  "Transform the ERROR into a format suitable for MEDIA-TYPE."
+  error)
+
+(defun plz-media-type-parse (header)
+  "Parse the Content-Type HEADER.
+
+Return a cons cell where the car is the MIME type, and the cdr is
+an alist of parameters."
+  (unless (or (null header) (string-blank-p header))
+    (let* ((components (split-string header ";"))
+           (mime-type (string-trim (car components)))
+           (parameters-list (cdr components))
+           (parameters-alist '()))
+      (dolist (param parameters-list parameters-alist)
+        (let* ((key-value (split-string param "="))
+               (key (string-trim (car key-value)))
+               (value (string-trim (cadr key-value) "\"")))
+          (setq parameters-alist (cons (cons key value) parameters-alist))))
+      (let ((parts (split-string mime-type "/")))
+        (plz-media-type
+         :type (intern (car parts))
+         :subtype (intern (cadr parts))
+         :parameters (nreverse parameters-alist))))))
+
+(defun plz-media-type--content-type (response)
+  "Return the content type header of RESPONSE, or nil if it's not set."
+  (let ((headers (plz-response-headers response)))
+    (when-let (header (cdr (assoc 'content-type headers)))
+      (plz-media-type-parse header))))
+
+(defun plz-media--type-find (media-types media-type)
+  "Lookup the MEDIA-TYPE in MEDIA-TYPES."
+  (or (alist-get (plz-media-type-symbol media-type) media-types)
+      (alist-get t media-types)
+      (plz-media-type:application/octet-stream)))
+
+(defun plz-media-type--of-response (media-types response)
+  "Lookup the content type of RESPONSE in MEDIA-TYPES."
+  (let ((media-type (plz-media-type--content-type response)))
+    (clone (plz-media--type-find media-types media-type))))
+
+(defvar-local plz-media-type--current nil
+  "The media type of the process buffer.")
+
+(defvar-local plz-media-type--position nil
+  "The position in the process buffer.")
+
+(defvar-local plz-media-type--response nil
+  "The response of the process buffer.")
+
+(defun plz-media-type-process-filter (process media-types chunk)
+  "The process filter that handles different content types.
+
+PROCESS is the process.
+
+MEDIA-TYPES is an association list from media type to an
+instance of a content type class.
+
+CHUNK is a part of the HTTP body."
+  (when (buffer-live-p (process-buffer process))
+    (with-current-buffer (process-buffer process)
+      (let ((moving (= (point) (process-mark process))))
+        (if-let (media-type plz-media-type--current)
+            (let ((coding-system (plz-media-type-coding-system media-type))
+                  (response plz-media-type--response))
+              (setf (plz-response-body response)
+                    (decode-coding-string chunk coding-system))
+              (plz-media-type-process media-type process response))
+          (progn
+            (save-excursion
+              (goto-char (process-mark process))
+              (insert chunk)
+              (set-marker (process-mark process) (point)))
+            (goto-char (point-min))
+            (when (re-search-forward plz-http-end-of-headers-regexp nil t)
+              (let ((body-start (point)))
+                (goto-char (point-min))
+                (let* ((response (prog1 (plz--response) (widen)))
+                       (media-type (plz-media-type--of-response media-types 
response))
+                       (coding-system (plz-media-type-coding-system 
media-type)))
+                  (setq-local plz-media-type--current media-type)
+                  (setq-local plz-media-type--response
+                              (make-plz-response
+                               :headers (plz-response-headers response)
+                               :status (plz-response-status response)
+                               :version (plz-response-version response)))
+                  (when-let (body (plz-response-body response))
+                    (when (> (length body) 0)
+                      (setf (plz-response-body response)
+                            (decode-coding-string body coding-system))
+                      (delete-region body-start (point-max))
+                      (set-marker (process-mark process) (point))
+                      (plz-media-type-process media-type process 
response))))))))
+        (when moving
+          (goto-char (process-mark process)))))))
+
+;; Content Type: application/octet-stream
+
+(defclass plz-media-type:application/octet-stream (plz-media-type)
+  ((type :initform 'application)
+   (subtype :initform 'octet-stream))
+  "Media type class that handles the processing of octet stream
+HTTP responses.  The media type sets the body slot of the
+plz-response structure to the unmodified value of the HTTP response
+body.  It is used as the default media type processor.")
+
+(cl-defmethod plz-media-type-else
+  ((media-type plz-media-type:application/octet-stream) error)
+  "Transform the ERROR into a format suitable for MEDIA-TYPE."
+  (when-let (response (plz-error-response error))
+    (setf (plz-error-response error) (plz-media-type-then media-type 
response)))
+  error)
+
+(cl-defmethod plz-media-type-then
+  ((media-type plz-media-type:application/octet-stream) response)
+  "Transform the RESPONSE into a format suitable for MEDIA-TYPE."
+  (ignore media-type)
+  (setf (plz-response-body response) (buffer-string))
+  response)
+
+(cl-defmethod plz-media-type-process
+  ((media-type plz-media-type:application/octet-stream) process chunk)
+  "Process the CHUNK according to MEDIA-TYPE using PROCESS."
+  (ignore media-type)
+  (save-excursion
+    (goto-char (process-mark process))
+    (insert (plz-response-body chunk))
+    (set-marker (process-mark process) (point))))
+
+;; Content Type: application/json
+
+(defclass plz-media-type:application/json 
(plz-media-type:application/octet-stream)
+  ((subtype :initform 'json)
+   (array-type
+    :documentation "Specifies which Lisp type is used to represent arrays.  It 
can be
+`array' (the default) or `list'."
+    :initarg :array-type
+    :initform 'array
+    :type symbol)
+   (false-object
+    :documentation "Specifies which object to use to represent a JSON false 
value. It
+defaults to `:json-false'."
+    :initarg :false-object
+    :initform :json-false)
+   (null-object
+    :documentation "Specifies which object to use to represent a JSON null 
value.  It
+defaults to `nil`."
+    :initarg :null-object
+    :initform nil)
+   (object-type
+    :documentation "Specifies which Lisp type is used to represent objects.  
It can
+be `hash-table', `alist' (the default) or `plist'."
+    :initarg :object-type
+    :initform 'alist
+    :type symbol))
+  "Media type class that handles the processing of HTTP responses
+in the JSON format.  The HTTP response is processed in a
+non-streaming way.  After the response has been received, the
+body of the plz-response structure is set to the result of parsing
+the HTTP response body with the `json-parse-buffer' function.
+The arguments to the `json-parse-buffer' can be customized by
+making an instance of this class and setting its slots
+accordingly.")
+
+(defun plz-media-type--parse-json-object (media-type)
+  "Parse the JSON object in the current buffer according to MEDIA-TYPE."
+  (with-slots (array-type false-object null-object object-type) media-type
+    (json-parse-buffer :array-type array-type
+                       :false-object false-object
+                       :null-object null-object
+                       :object-type object-type)) )
+
+(cl-defmethod plz-media-type-then
+  ((media-type plz-media-type:application/json) response)
+  "Transform the RESPONSE into a format suitable for MEDIA-TYPE."
+  (setf (plz-response-body response) (plz-media-type--parse-json-object 
media-type))
+  response)
+
+;; Content Type: application/json (array of objects)
+
+(defclass plz-media-type:application/json-array 
(plz-media-type:application/json)
+  ((handler
+    :documentation "Function that will be called for each object in the JSON 
array."
+    :initarg :handler
+    :type (or function symbol)))
+  "Media type class that handles the processing of HTTP responses
+in a JSON format that assumes that the object at the top level is
+an array.  The HTTP response is processed in a streaming way.
+Each object in the top level array will be parsed with the
+`json-parse-buffer' function.  The function in the :handler slot
+will be called each time a new object arrives.  The body slot of
+the plz-response structure passed to the THEN and ELSE callbacks
+will always be set to nil.")
+
+(defun plz-media-type:application/json-array--parse-next (media-type)
+  "Parse a single line of the newline delimited JSON MEDIA-TYPE."
+  (let ((begin (point)))
+    (cond ((looking-at "\\[")
+           (forward-char 1)
+           (cons :array-start (buffer-substring begin (point))))
+          ((looking-at ",")
+           (forward-char 1)
+           (cons :comma (buffer-substring begin (point))))
+          ((looking-at "\n")
+           (forward-char 1)
+           (cons :line-feed (buffer-substring begin (point))))
+          ((looking-at "\r")
+           (forward-char 1)
+           (cons :carriage-return (buffer-substring begin (point))))
+          ((looking-at "\\]")
+           (forward-char 1)
+           (cons :array-end (buffer-substring begin (point))))
+          ((not (eobp))
+           (condition-case nil
+               (cons :array-element (plz-media-type--parse-json-object 
media-type))
+             (json-error))))))
+
+(defun plz-media-type:application/json-array--consume-next (media-type)
+  "Parse a single line of the newline delimited JSON MEDIA-TYPE."
+  (let ((begin (point)))
+    (prog1 (plz-media-type:application/json-array--parse-next media-type)
+      (delete-region begin (point))
+      (setq-local plz-media-type--position (point)))))
+
+(defun plz-media-type:application/json-array--parse-stream (media-type)
+  "Parse all lines of the newline delimited JSON MEDIA-TYPE in the PROCESS 
buffer."
+  (with-slots (handler) media-type
+    (unless plz-media-type--position
+      (setq-local plz-media-type--position (point)))
+    (goto-char plz-media-type--position)
+    (when-let (result (plz-media-type:application/json-array--consume-next 
media-type))
+      (while result
+        (when (and (equal :array-element (car result))
+                   (functionp handler))
+          (funcall handler (cdr result)))
+        (setq result (plz-media-type:application/json-array--consume-next 
media-type))))))
+
+(cl-defmethod plz-media-type-process
+  ((media-type plz-media-type:application/json-array) process chunk)
+  "Process the CHUNK according to MEDIA-TYPE using PROCESS."
+  (ignore media-type)
+  (cl-call-next-method media-type process chunk)
+  (plz-media-type:application/json-array--parse-stream media-type)
+  (set-marker (process-mark process) (point-max)))
+
+(cl-defmethod plz-media-type-then
+  ((media-type plz-media-type:application/json-array) response)
+  "Transform the RESPONSE into a format suitable for MEDIA-TYPE."
+  (ignore media-type)
+  (plz-media-type:application/json-array--parse-stream media-type)
+  (setf (plz-response-body response) nil)
+  response)
+
+;; Content Type: application/x-ndjson
+
+(defclass plz-media-type:application/x-ndjson (plz-media-type:application/json)
+  ((subtype :initform 'x-ndjson)
+   (handler
+    :documentation "Function that will be called for each line that contains a 
JSON object."
+    :initarg :handler
+    :initform nil
+    :type (or function null symbol)))
+  "Media type class that handles the processing of HTTP responses
+in a JSON format that assumes that the object at the top level is
+an array.  The HTTP response is processed in a streaming way.
+Each object in the top level array will be parsed with the
+`json-parse-buffer' function.  The function in the :handler slot
+will be called each time a new object arrives.  The body slot of
+the plz-response structure passed to the THEN and ELSE callbacks
+will always be set to nil.")
+
+(defconst plz-media-type:application/x-ndjson--line-regexp
+  (rx (* not-newline) (or "\r\n" "\n" "\r"))
+  "Regular expression matching a JSON Object line.")
+
+(defun plz-media-type:application/x-ndjson--parse-line (media-type)
+  "Parse a single line of the newline delimited JSON MEDIA-TYPE."
+  (when (looking-at plz-media-type:application/x-ndjson--line-regexp)
+    (prog1 (plz-media-type--parse-json-object media-type)
+      (delete-region (match-beginning 0) (match-end 0)))))
+
+(defun plz-media-type:application/x-ndjson--parse-stream (media-type)
+  "Parse all lines of the newline delimited JSON MEDIA-TYPE in the PROCESS 
buffer."
+  (with-slots (handler) media-type
+    (unless plz-media-type--position
+      (setq-local plz-media-type--position (point)))
+    (goto-char plz-media-type--position)
+    (when-let (object (plz-media-type:application/x-ndjson--parse-line 
media-type))
+      (while object
+        (setq-local plz-media-type--position (point))
+        (when (functionp handler)
+          (funcall handler object))
+        (setq object (plz-media-type:application/x-ndjson--parse-line 
media-type))))))
+
+(cl-defmethod plz-media-type-process
+  ((media-type plz-media-type:application/x-ndjson) process chunk)
+  "Process the CHUNK according to MEDIA-TYPE using PROCESS."
+  (cl-call-next-method media-type process chunk)
+  (plz-media-type:application/x-ndjson--parse-stream media-type))
+
+(cl-defmethod plz-media-type-then
+  ((media-type plz-media-type:application/x-ndjson) response)
+  "Transform the RESPONSE into a format suitable for MEDIA-TYPE."
+  (plz-media-type:application/x-ndjson--parse-stream media-type)
+  (setf (plz-response-body response) nil)
+  response)
+
+;; Content Type: application/xml
+
+(defclass plz-media-type:application/xml 
(plz-media-type:application/octet-stream)
+  ((subtype :initform 'xml))
+  "Media type class that handles the processing of HTTP responses
+in the XML format.  The HTTP response is processed in a
+non-streaming way.  After the response has been received, the
+body of the plz-response structure is set to the result of parsing
+the HTTP response body with the `libxml-parse-html-region'
+function.")
+
+(cl-defmethod plz-media-type-then
+  ((media-type plz-media-type:application/xml) response)
+  "Transform the RESPONSE into a format suitable for MEDIA-TYPE."
+  (with-slots (array-type false-object null-object object-type) media-type
+    (setf (plz-response-body response)
+          (libxml-parse-html-region (point-min) (point-max) nil))
+    response))
+
+;; Content Type: text/html
+
+(defclass plz-media-type:text/html (plz-media-type:application/xml)
+  ((type :initform 'text)
+   (subtype :initform 'xml))
+  "Media type class that handles the processing of HTTP responses
+in the HTML format.  The HTTP response is processed in a
+non-streaming way.  After the response has been received, the
+body of the plz-response structure is set to the result of parsing
+the HTTP response body with the `libxml-parse-html-region'
+function.")
+
+(defvar plz-media-types
+  `((application/json . ,(plz-media-type:application/json))
+    (application/octet-stream . ,(plz-media-type:application/octet-stream))
+    (application/xml . ,(plz-media-type:application/xml))
+    (text/html . ,(plz-media-type:text/html))
+    (t . ,(plz-media-type:application/octet-stream)))
+  "Association list from media type to content type.")
+
+(defun plz-media-type--handle-sync-http-error (error media-types)
+  "Handle the synchronous HTTP ERROR using MEDIA-TYPES."
+  (let* ((msg (cadr error))
+         (plzerror (caddr error)))
+    (signal (car error)
+            (cond
+             ((plz-error-response plzerror)
+              (let ((response (plz-error-response plzerror)))
+                (if-let (media-type (plz-media-type--of-response media-types 
response))
+                    (list msg (with-temp-buffer
+                                (when-let (body (plz-response-body response))
+                                  (insert body)
+                                  (goto-char (point-min)))
+                                (plz-media-type-else media-type plzerror)))
+                  (cdr error))))))))
+
+(defun plz-media-type--handle-sync-error (error media-types)
+  "Handle the synchronous ERROR using MEDIA-TYPES."
+  (cond
+   ((plz-media-type-filter-error-p error)
+    (signal 'plz-media-type-filter-error
+            (list (plz-media-type-filter-error-message error)
+                  (plz-media-type-filter-error-response error)
+                  (plz-media-type-filter-error-cause error))))
+   ((eq 'plz-http-error (car error))
+    (plz-media-type--handle-sync-http-error error media-types))
+   (t (signal (car error) (cdr error)))))
+
+(cl-defun plz-media-type-request
+    (method
+     url
+     &rest rest &key headers body else finally noquery
+     (as 'string)
+     (body-type 'text)
+     (connect-timeout plz-connect-timeout)
+     (decode t decode-s)
+     (then 'sync)
+     (timeout plz-timeout))
+  "Request METHOD from URL with curl.
+Return the curl process object or, for a synchronous request, the
+selected result.
+
+HEADERS may be an alist of extra headers to send with the
+request.
+
+BODY may be a string, a buffer, or a list like `(file FILENAME)'
+to upload a file from disk.
+
+BODY-TYPE may be `text' to send BODY as text, or `binary' to send
+it as binary.
+
+AS selects the kind of result to pass to the callback function
+THEN, or the kind of result to return for synchronous requests.
+It may be:
+
+- `buffer' to pass the response buffer, which will be narrowed to
+  the response body and decoded according to DECODE.
+
+- `binary' to pass the response body as an un-decoded string.
+
+- `string' to pass the response body as a decoded string.
+
+- `response' to pass a `plz-response' structure.
+
+- `file' to pass a temporary filename to which the response body
+  has been saved without decoding.
+
+- `(file FILENAME)' to pass FILENAME after having saved the
+  response body to it without decoding.  FILENAME must be a
+  non-existent file; if it exists, it will not be overwritten,
+  and an error will be signaled.
+
+- `(media-types MEDIA-TYPES)' to handle the processing of the
+  response based on the Content-Type header.  MEDIA-TYPES is an
+  association list from a content type symbol to an instance of a
+  `plz-media-type' class.  The `plz-media-types' variable is
+  bound to an association list and can be used to handle some
+  commonly used formats such as JSON, HTML, XML.  This list can
+  be used as a basis and is meant to be extended by users.  If no
+  media type was found for a content type, it will be handled by
+  the default octet stream media type.  When this option is used,
+  the THEN callback will always receive a plz-response structure as
+  argument, and the ELSE callback always a plz-error structure.  The
+  plz-response structure will always have the status and header
+  slots set.  The body slot depends on the media type
+  implementation.  In the case for JSON, HTML, XML it will
+  contain the decoded response body.  When receiving JSON for
+  example, it will be an Emacs Lisp association list.  For
+  streaming responses like text/event-stream it will be set to
+  nil, and the events of the server sent events specification
+  will be dispatched to the handlers registered with the media
+  type instance.
+
+- A function, which is called in the response buffer with it
+  narrowed to the response body (suitable for, e.g. `json-read').
+
+If DECODE is non-nil, the response body is decoded automatically.
+For binary content, it should be nil.  When AS is `binary',
+DECODE is automatically set to nil.
+
+THEN is a callback function, whose sole argument is selected
+above with AS; if the request fails and no ELSE function is
+given (see below), the argument will be a `plz-error' structure
+describing the error.  Or THEN may be `sync' to make a
+synchronous request, in which case the result is returned
+directly from this function.
+
+ELSE is an optional callback function called when the request
+fails (i.e. if curl fails, or if the HTTP response has a non-2xx
+status code).  It is called with one argument, a `plz-error'
+structure.  If ELSE is nil, a `plz-curl-error' or
+`plz-http-error' is signaled when the request fails, with a
+`plz-error' structure as the error data.  For synchronous
+requests, this argument is ignored.
+
+NOTE: In v0.8 of `plz', only one error will be signaled:
+`plz-error'.  The existing errors, `plz-curl-error' and
+`plz-http-error', inherit from `plz-error' to allow applications
+to update their code while using v0.7 (i.e. any `condition-case'
+forms should now handle only `plz-error', not the other two).
+
+FINALLY is an optional function called without argument after
+THEN or ELSE, as appropriate.  For synchronous requests, this
+argument is ignored.
+
+CONNECT-TIMEOUT and TIMEOUT are a number of seconds that limit
+how long it takes to connect to a host and to receive a response
+from a host, respectively.
+
+NOQUERY is passed to `make-process', which see.
+
+When the HTTP response is streamed, the buffering in the curl
+output stream is turned off and the PROCESS-FILTER may be called
+multiple times, depending on the size of the HTTP body.  It is
+the user's responsibility to understand and process each chunk,
+and to construct the finalized response if necessary.  There are
+no guarantees regarding the chunk, such as being line-based or
+not.
+\(To silence checkdoc, we mention the internal argument REST.)"
+  ;; FIXME(v0.8): Remove the note about error changes from the docstring.
+  ;; FIXME(v0.8): Update error signals in docstring.
+  (declare (indent defun))
+  (if-let (media-types (pcase as
+                         (`(media-types ,media-types)
+                          media-types)))
+      (let ((buffer) (filter-error))
+        (condition-case error
+            (let* ((plz-curl-default-args (cons "--no-buffer" 
plz-curl-default-args))
+                   (result (plz method url
+                             :as 'buffer
+                             :body body
+                             :body-type body-type
+                             :connect-timeout connect-timeout
+                             :decode decode
+                             :else (lambda (error)
+                                     (setq buffer (current-buffer))
+                                     (when (or (functionp else) (symbolp else))
+                                       (funcall else (or filter-error
+                                                         (plz-media-type-else
+                                                          
plz-media-type--current
+                                                          error)))))
+                             :finally (lambda ()
+                                        (unwind-protect
+                                            (when (functionp finally)
+                                              (funcall finally))
+                                          (when (buffer-live-p buffer)
+                                            (kill-buffer buffer))))
+                             :headers headers
+                             :noquery noquery
+                             :process-filter (lambda (process chunk)
+                                               (condition-case cause
+                                                   
(plz-media-type-process-filter process media-types chunk)
+                                                 (error
+                                                  (let ((buffer 
(process-buffer process)))
+                                                    (setq filter-error
+                                                          
(make-plz-media-type-filter-error
+                                                           :cause cause
+                                                           :message (format 
"error in process filter: %S" cause)
+                                                           :response (when 
(buffer-live-p buffer)
+                                                                       
(with-current-buffer buffer
+                                                                         
plz-media-type--response))))
+                                                    (delete-process 
process)))))
+                             :timeout timeout
+                             :then (if (symbolp then)
+                                       then
+                                     (lambda (_)
+                                       (setq buffer (current-buffer))
+                                       (when (or (functionp then) (symbolp 
then))
+                                         (funcall then (plz-media-type-then
+                                                        plz-media-type--current
+                                                        
plz-media-type--response))))))))
+              (cond ((bufferp result)
+                     (unwind-protect
+                         (with-current-buffer result
+                           (plz-media-type-then plz-media-type--current 
plz-media-type--response))
+                       (when (buffer-live-p result)
+                         (kill-buffer result))))
+                    ((processp result)
+                     result)
+                    (t (user-error "Unexpected response: %s" result))))
+          ;; TODO: How to kill the buffer for sync requests that raise an 
error?
+          (plz-error
+           (plz-media-type--handle-sync-error (or filter-error error) 
media-types))))
+    (apply #'plz (append (list method url) rest))))
+
+;;;; Footer
+
+(provide 'plz-media-type)
+
+;;; plz-media-type.el ends here
diff --git a/plz-media-type.info b/plz-media-type.info
new file mode 100644
index 0000000000..696c5a87c7
--- /dev/null
+++ b/plz-media-type.info
@@ -0,0 +1,471 @@
+This is README.info, produced by makeinfo version 6.8 from README.texi.
+
+INFO-DIR-SECTION Emacs
+START-INFO-DIR-ENTRY
+* Plz Event Source: (plz-media-type). A plz.el media type to handle 
Server-Sent Events.
+END-INFO-DIR-ENTRY
+
+
+File: README.info,  Node: Top,  Next: Installation,  Up: (dir)
+
+plz-media-type
+**************
+
+http://elpa.gnu.org/packages/plz-media-type.svg
+(http://elpa.gnu.org/packages/plz-media-type.html)
+https://github.com/r0man/plz-media-type/actions/workflows/test.yml/badge.svg
+(https://github.com/r0man/plz-media-type/actions/workflows/test.yml)
+
+   ‘plz-media-type’ is an Emacs Lisp library that enhances MIME type
+handling for HTTP requests within Emacs.  It leverages the plz.el
+(https://github.com/alphapapa/plz.el) HTTP library for networking calls
+and introduces a mechanism to process responses based on the content
+type header.  This library defines various classes and methods for
+parsing and processing standard MIME types, including JSON, XML, HTML,
+and binary data.  It is used in the LLM (https://github.com/ahyatt/llm)
+library to handle decoding of various streaming and non-streaming media
+type formats.
+
+   👷🏽 NOTE: This is work in progress.  The library is not yet on ELPA.
+
+* Menu:
+
+* Installation::
+* Usage::
+* Credits::
+* License::
+
+— The Detailed Node Listing —
+
+Installation
+
+* GNU ELPA::
+
+Usage
+
+* Quick Start::
+* Media Types::
+* Error Handling::
+
+Media Types
+
+* JSON::
+* Newline Delimited JSON Stream::
+* JSON Array Stream::
+* XML::
+* HTML::
+* Octet Stream::
+
+Credits
+
+* Copyright assignment::
+
+
+
+File: README.info,  Node: Installation,  Next: Usage,  Prev: Top,  Up: Top
+
+1 Installation
+**************
+
+* Menu:
+
+* GNU ELPA::
+
+
+File: README.info,  Node: GNU ELPA,  Up: Installation
+
+1.1 GNU ELPA
+============
+
+‘plz-media-type’ is available in GNU ELPA
+(http://elpa.gnu.org/packages/plz-media-type.html).  It may be installed
+in Emacs using the ‘package-install’ command.
+
+
+File: README.info,  Node: Usage,  Next: Credits,  Prev: Installation,  Up: Top
+
+2 Usage
+*******
+
+The main function, ‘plz-media-type-request’, works similarly to the plz
+(https://github.com/alphapapa/plz.el?tab=readme-ov-file#functions)
+function but with an additional feature.  When the ‘:as’ option is set
+to ‘(media-types MEDIA-TYPES)’, the HTTP response is decoded based on
+the content type header.  The ‘MEDIA-TYPES’ association list defines a
+mapping from content type symbols to instances of media type classes.
+These classes determine how the response is processed.
+
+   When using the media type option:
+
+   • Synchronous requests return a ‘plz-response’ structure or signal an
+     error.
+
+   • Asynchronous requests return a process object and pass a
+     ‘plz-response’ structure to the ‘THEN’ callback and a ‘plz-error’
+     structure to the ‘ELSE’ callback.
+
+* Menu:
+
+* Quick Start::
+* Media Types::
+* Error Handling::
+
+
+File: README.info,  Node: Quick Start,  Next: Media Types,  Up: Usage
+
+2.1 Quick Start
+===============
+
+The ‘plz-media-types’ variable contains a list of pre-configured media
+type mappings.  The following code makes a synchronous ‘GET’ request to
+a URL and returns a ‘plz-response’ structure.  Since the response is
+returned with the content type header set to ‘application/json’, the
+‘plz-media-type:application/json’ class will be used to decode the HTTP
+body.
+
+     (plz-media-type-request
+       'get "https://httpbin.org/json";
+       :as `(media-types ,plz-media-types))
+
+     #s(plz-response 2 200
+                     ((date . "Sun, 24 Mar 2024 10:41:18 GMT")
+                      (content-type . "application/json")
+                      (content-length . "429")
+                      (server . "gunicorn/19.9.0")
+                      (access-control-allow-origin . "*")
+                      (access-control-allow-credentials . "true"))
+                     ((slideshow
+                       (author . "Yours Truly")
+                       (date . "date of publication")
+                       (slides .
+                               [((title . "Wake up to WonderWidgets!")
+                                 (type . "all"))
+                                ((items .
+                                        ["Why <em>WonderWidgets</em> are 
great" "Who <em>buys</em> WonderWidgets"])
+                                 (title . "Overview")
+                                 (type . "all"))])
+                       (title . "Sample Slide Show"))))
+
+
+File: README.info,  Node: Media Types,  Next: Error Handling,  Prev: Quick 
Start,  Up: Usage
+
+2.2 Media Types
+===============
+
+The following table shows the media type classes provided by the
+‘plz-media-type’ library.  The ‘Content Type’ and ‘Default’ columns
+indicate which media type is part of the default ‘plz-media-types’ and
+which content type header values trigger their use.  The ‘Stream’ column
+specifies whether the class consumes data in a streaming or
+non-streaming way.
+
+EIEIO Class                                 Content Type                 
Default   Stream
+--------------------------------------------------------------------------------------------
+‘plz-media-type:application/json-array’     -                            No    
    Yes
+‘plz-media-type:application/json’           ‘application/json’           Yes   
    No
+‘plz-media-type:application/octet-stream’   ‘application/octet-stream’   Yes   
    No
+‘plz-media-type:application/x-ndjson’       -                            No    
    Yes
+‘plz-media-type:application/xml’            ‘application/xml’            Yes   
    No
+‘plz-media-type:text/html’                  ‘text/html’                  Yes   
    No
+
+* Menu:
+
+* JSON::
+* Newline Delimited JSON Stream::
+* JSON Array Stream::
+* XML::
+* HTML::
+* Octet Stream::
+
+
+File: README.info,  Node: JSON,  Next: Newline Delimited JSON Stream,  Up: 
Media Types
+
+2.2.1 JSON
+----------
+
+The ‘plz-media-type:application/json’ media type class handles JSON
+responses.  It parses the response body using ‘json-parse-buffer’ after
+receiving the entire response.
+
+   *Customization:*
+
+   Instances of this class can be customized by setting the following
+slots:
+
+   • ‘:array-type’: Lisp type used for arrays (‘array’ or ‘list’,
+     default ‘array’)
+   • ‘:false-object’: Object representing JSON ‘false’ (default
+     ‘:json-false’)
+   • ‘:null-object’: Object representing JSON ‘null’ (default ‘nil’)
+   • ‘:object-type’: Lisp type used for objects (‘hash-table’, ‘alist’,
+     or ‘plist’, default ‘alist’)
+
+   *Example:*
+
+     (plz-media-type-request
+       'get "https://httpbin.org/json";
+       :as `(media-types
+             ((application/json
+               . ,(plz-media-type:application/json :array-type 'list)))))
+
+     #s(plz-response 2 200
+                     ((date . "Sun, 24 Mar 2024 10:05:19 GMT")
+                      (content-type . "application/json")
+                      (content-length . "429")
+                      (server . "gunicorn/19.9.0")
+                      (access-control-allow-origin . "*")
+                      (access-control-allow-credentials . "true"))
+                     ((slideshow
+                       (author . "Yours Truly")
+                       (date . "date of publication")
+                       (slides
+                        ((title . "Wake up to WonderWidgets!")
+                         (type . "all"))
+                        ((items "Why <em>WonderWidgets</em> are great" "Who 
<em>buys</em> WonderWidgets")
+                         (title . "Overview")
+                         (type . "all")))
+                       (title . "Sample Slide Show"))))
+
+
+File: README.info,  Node: Newline Delimited JSON Stream,  Next: JSON Array 
Stream,  Prev: JSON,  Up: Media Types
+
+2.2.2 Newline Delimited JSON Stream
+-----------------------------------
+
+The ‘plz-media-type:application/x-ndjson’ media type class handles
+newline-delimited JSON responses in a streaming fashion.  It parses each
+line using ‘json-parse-buffer’ and calls the ‘:handler’ function for
+each decoded object.  The body slot of the ‘plz-response’ structure will
+always be ‘nil’.
+
+   *Customization:*
+
+   • ‘:handler’: Function called for each JSON object.
+
+   *Example:*
+
+     (plz-media-type-request
+       'get "https://httpbin.org/stream/5";
+       :as `(media-types
+             ((application/json
+               . ,(plz-media-type:application/x-ndjson
+                   :handler (lambda (object)
+                              (message "%s" object)))))))
+
+     #s(plz-response 2 200
+                     ((date . "Sun, 24 Mar 2024 10:06:51 GMT")
+                      (content-type . "application/json")
+                      (server . "gunicorn/19.9.0")
+                      (access-control-allow-origin . "*")
+                      (access-control-allow-credentials . "true"))
+                     nil)
+
+
+File: README.info,  Node: JSON Array Stream,  Next: XML,  Prev: Newline 
Delimited JSON Stream,  Up: Media Types
+
+2.2.3 JSON Array Stream
+-----------------------
+
+The ‘plz-media-type:application/json-array’ media type class handles
+JSON responses where the top-level object is an array.  It parses each
+object in the array using ‘json-parse-buffer’ and calls the ‘:handler’
+function for each decoded object.
+
+   *Customization:*
+
+   • ‘:handler’: Function called for each JSON object.
+
+   *Example:*
+
+     (plz-media-type-request
+       'get "https://localhost/json-array";
+       :as `(media-types
+             ((application/json
+               . ,(plz-media-type:application/json-array
+                   :handler (lambda (object)
+                              (message "%s" object)))))))
+
+
+File: README.info,  Node: XML,  Next: HTML,  Prev: JSON Array Stream,  Up: 
Media Types
+
+2.2.4 XML
+---------
+
+The ‘plz-media-type:application/xml’ media type class handles XML
+responses.  It parses the response body using ‘libxml-parse-html-region’
+after receiving the entire response.
+
+   *Customization:* None
+
+   *Example:*
+
+     (plz-media-type-request
+       'get "https://httpbin.org/xml";
+       :as `(media-types ((application/xml . 
,(plz-media-type:application/xml)))))
+
+     #s(plz-response 2 200
+                     ((date . "Sun, 24 Mar 2024 10:17:57 GMT")
+                      (content-type . "application/xml")
+                      (content-length . "522")
+                      (server . "gunicorn/19.9.0")
+                      (access-control-allow-origin . "*")
+                      (access-control-allow-credentials . "true"))
+                     (top nil
+                          (comment nil "  A SAMPLE set of slides  ")
+                          (html nil
+                                (body nil
+                                      (slideshow
+                                       ((title . "Sample Slide Show")
+                                        (date . "Date of publication")
+                                        (author . "Yours Truly"))
+                                       (comment nil " TITLE SLIDE ")
+                                       (slide
+                                        ((type . "all"))
+                                        (title nil "Wake up to 
WonderWidgets!"))
+                                       (comment nil " OVERVIEW ")
+                                       (slide
+                                        ((type . "all"))
+                                        (title nil "Overview")
+                                        (item nil "Why "
+                                              (em nil "WonderWidgets")
+                                              " are great")
+                                        (item nil)
+                                        (item nil "Who "
+                                              (em nil "buys")
+                                              " WonderWidgets")))))))
+
+
+File: README.info,  Node: HTML,  Next: Octet Stream,  Prev: XML,  Up: Media 
Types
+
+2.2.5 HTML
+----------
+
+The ‘plz-media-type:text/html’ media type class handles HTML responses.
+It parses the response body using ‘libxml-parse-html-region’ after
+receiving the entire response.
+
+   *Customization:* None
+
+   *Example:*
+
+     (plz-media-type-request
+       'get "https://httpbin.org/html";
+       :as `(media-types ((text/html . ,(plz-media-type:application/xml)))))
+
+     #s(plz-response 2 200
+                     ((date . "Sun, 24 Mar 2024 10:18:40 GMT")
+                      (content-type . "text/html; charset=utf-8")
+                      (content-length . "3741")
+                      (server . "gunicorn/19.9.0")
+                      (access-control-allow-origin . "*")
+                      (access-control-allow-credentials . "true"))
+                     (html nil
+                           (head nil)
+                           (body nil "\n      "
+                                 (h1 nil "Herman Melville - Moby-Dick")
+                                 "\n\n      "
+                                 (div nil "\n        "
+                                      (p nil "\n          Availing himself of 
the mild, summer-cool weather that now reigned in these latitudes, and in 
preparation for the peculiarly active pursuits shortly to be anticipated, 
Perth, the begrimed, blistered old blacksmith, had not removed his portable 
forge to the hold again, after concluding his contributory work for Ahab's leg, 
but still retained it on deck, fast lashed to ringbolts by the foremast; being 
now almost incessantly invoked  [...]
+                                      "\n      ")
+                                 "\n  ")))
+
+
+File: README.info,  Node: Octet Stream,  Prev: HTML,  Up: Media Types
+
+2.2.6 Octet Stream
+------------------
+
+The ‘plz-media-type:application/octet-stream’ media type class handles
+any other response and is used as the default media type hanlder.  It
+does not parse the response body in any way.
+
+     (plz-media-type-request
+       'get "https://httpbin.org/json";
+       :as `(media-types ((t . ,(plz-media-type:application/octet-stream)))))
+
+     #s(plz-response 2 200
+                     ((date . "Sun, 24 Mar 2024 10:28:40 GMT")
+                      (content-type . "application/json")
+                      (content-length . "429")
+                      (server . "gunicorn/19.9.0")
+                      (access-control-allow-origin . "*")
+                      (access-control-allow-credentials . "true"))
+                     "{\n  \"slideshow\": {\n    \"author\": \"Yours Truly\", 
\n    \"date\": \"date of publication\", \n    \"slides\": [\n      {\n        
\"title\": \"Wake up to WonderWidgets!\", \n        \"type\": \"all\"\n      }, 
\n      {\n        \"items\": [\n          \"Why <em>WonderWidgets</em> are 
great\", \n          \"Who <em>buys</em> WonderWidgets\"\n        ], \n        
\"title\": \"Overview\", \n        \"type\": \"all\"\n      }\n    ], \n    
\"title\": \"Sample Slid [...]
+
+
+File: README.info,  Node: Error Handling,  Prev: Media Types,  Up: Usage
+
+2.3 Error Handling
+==================
+
+This library uses a process filter to handle streaming HTTP responses
+retrieved with curl.  Media types that stream data typically trigger
+callbacks that execute user-defined code.  If an error occurs within
+this code, the process will be terminated.  Synchronous requests will
+signal a ‘plz-media-type-filter-error’ with the error message, HTTP
+response, and cause included as error data.  Asynchronous requests will
+receive a ‘plz-media-type-filter-error’ structure in the ‘ELSE’
+callback.  This structure, derived from ‘plz-error’, contains an
+additional ‘cause’ slot.
+
+
+File: README.info,  Node: Credits,  Next: License,  Prev: Usage,  Up: Top
+
+3 Credits
+*********
+
+   • Thanks to ahyatt (https://github.com/ahyatt) and alphapapa
+     (https://github.com/alphapapa) for their help and advice.
+
+* Menu:
+
+* Copyright assignment::
+
+
+File: README.info,  Node: Copyright assignment,  Up: Credits
+
+3.1 Copyright assignment
+========================
+
+This package is part of GNU Emacs (https://www.gnu.org/software/emacs/),
+being distributed in GNU ELPA (https://elpa.gnu.org/).  Contributions to
+this project must follow GNU guidelines, which means that, as with other
+parts of Emacs, patches of more than a few lines must be accompanied by
+having assigned copyright for the contribution to the FSF.  Contributors
+who wish to do so may contact emacs-devel@gnu.org <emacs-devel@gnu.org>
+to request the assignment form.
+
+
+File: README.info,  Node: License,  Prev: Credits,  Up: Top
+
+4 License
+*********
+
+GPLv3
+
+
+
+Tag Table:
+Node: Top225
+Node: Installation1555
+Node: GNU ELPA1687
+Node: Usage1941
+Node: Quick Start2915
+Node: Media Types4493
+Node: JSON5850
+Node: Newline Delimited JSON Stream7765
+Node: JSON Array Stream9011
+Node: XML9821
+Node: HTML12026
+Node: Octet Stream16903
+Node: Error Handling18238
+Node: Credits18946
+Node: Copyright assignment19209
+Node: License19793
+
+End Tag Table
+
+
+Local Variables:
+coding: utf-8
+End:
diff --git a/tests/plz-media-type-test.el b/tests/plz-media-type-test.el
new file mode 100644
index 0000000000..e96c5b612b
--- /dev/null
+++ b/tests/plz-media-type-test.el
@@ -0,0 +1,165 @@
+;;; plz-media-type-test.el --- Test helpers for plz media type -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2019-2023  Free Software Foundation, Inc.
+
+;; Author: r0man <roman@burningswell.com>
+;; Maintainer: r0man <roman@burningswell.com>
+
+;; This file is part of GNU Emacs.
+
+;;; License:
+
+;; This program 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, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Test helpers for plz media type.
+
+;;; Code:
+
+;;;; Requirements
+
+(require 'ert)
+(require 'json)
+(require 'let-alist)
+(require 'map)
+
+(require 'plz)
+
+;;;; Variables
+
+(defvar plz-media-type-test-uri-prefix
+  "http://localhost";
+  "URI prefix for HTTP requests, without trailing slash.
+If running httpbin locally, set to \"http://localhost\".";)
+
+;;;; Customization
+
+
+;;;; Commands
+
+
+;;;; Macros
+
+(cl-defun plz-media-type-test-wait (process &optional (seconds 0.1) (times 
100))
+  "Wait for SECONDS seconds TIMES times for PROCESS to finish."
+  (when process
+    ;; Sometimes it seems that the process is killed, the THEN
+    ;; function called by its sentinel, and its buffer killed, all
+    ;; before this function gets called with the process argument;
+    ;; when that happens, tests that use this can fail.  Testing
+    ;; whether PROCESS is non-nil seems to fix it, but it's possible
+    ;; that something funny is going on...
+    (cl-loop for i upto times ;; 10 seconds
+             while (equal 'run (process-status process))
+             do (sleep-for seconds))))
+
+(cl-defmacro plz-deftest (name () &body docstring-keys-and-body)
+  "Like `ert-deftest', but defines tests for both HTTP/1.1 and HTTP/2.
+Also defines local function `url' which returns its argument
+appended to `plz-media-type-test-uri-prefix' (and any instance of
+\"URI-PREFIX\" in URL-PART is replaced with `plz-media-type-test-uri-prefix'
+in URL-encoded form)."
+  (declare (debug (&define [&name "test@" symbolp]
+                          sexp [&optional stringp]
+                          [&rest keywordp sexp] def-body))
+           (doc-string 3)
+           (indent 2))
+  `(progn
+     ,@(cl-loop for http-version in '("1.1" "2")
+                collect (let ((name (intern (format "%s-http%s" name 
http-version))))
+                          `(ert-deftest ,name ()
+                             (let ((plz-curl-default-args
+                                    ',(append plz-curl-default-args (list 
(format "--http%s" http-version)))))
+                               (cl-labels ((url (part)
+                                             (setf part 
(replace-regexp-in-string
+                                                         "URI-PREFIX" 
(url-hexify-string plz-media-type-test-uri-prefix)
+                                                         part t t))
+                                             (concat 
plz-media-type-test-uri-prefix part)))
+                                 ,@docstring-keys-and-body)))))))
+
+(defun plz-media-type-test-make-mock-program (response-file &optional 
mock-file)
+  "Make a shell script that emit a curl response.
+
+RESPONSE-FILE is the file to read the response from.
+
+MOCK-FILE is the file to write the mock program to.  If nil, a
+temporary filename is used."
+  (let ((mock-file (or mock-file (make-temp-file "plz-media-type-test-mock"))))
+    (with-temp-buffer
+      (insert "#!/usr/bin/env bash")
+      (newline)
+      (insert "cat " (expand-file-name response-file) " | pv --quiet 
--rate-limit 10000")
+      (newline)
+      (make-directory (file-name-directory mock-file) t)
+      (write-region (point-min) (point-max) mock-file)
+      (chmod mock-file #o755)
+      mock-file)))
+
+(defun plz-media-type-test-save-mock-response (buffer filename)
+  "Write the plz HTTP response in BUFFER to FILENAME."
+  (let ((filename (expand-file-name filename)))
+    (with-current-buffer buffer
+      (widen)
+      (make-directory (file-name-directory filename) t)
+      (write-region (point-min) (point-max) filename)
+      filename)))
+
+(defmacro plz-media-type-test-with-mock-response (filename &rest body)
+  "Evaluate BODY with a mocked HTTP response from FILENAME."
+  (declare (indent 1) (debug (body)))
+  `(let ((plz-curl-program (plz-media-type-test-make-mock-program ,filename)))
+     ,@body))
+
+(defun plz-media-type-test-response (example)
+  "Return the HTTP test response filename for EXAMPLE."
+  (if-let (file (locate-dominating-file "." ".git"))
+      (let ((filename (expand-file-name (concat file "tests/response/" 
example))))
+        (if (file-exists-p filename)
+            filename
+          (error "No such HTTP response file: %s" filename)))
+    (error "Can't locate dominating plz.el file")))
+
+(defun plz-media-type-test-openai-extract-content (events)
+  "Extract the content of the OpenAI EVENTS."
+  (thread-last
+    (reverse events)
+    (seq-map (lambda (event)
+               (with-slots (data) event
+                 (unless (equal "[DONE]" data)
+                   (when-let ((data (json-parse-string data))
+                              (choice (seq-first (map-elt data "choices")))
+                              (delta (map-elt choice "delta"))
+                              (content (map-elt delta "content")))
+                     content)))))
+    (seq-remove #'null)
+    (string-join)))
+
+(defun plz-media-type-test-vertex-extract-content (objects)
+  "Extract the content of the Vertext OBJECTS."
+  (thread-last
+    objects
+    (seq-map (lambda (object)
+               (seq-mapcat (lambda (candidate)
+                             (alist-get 'parts (cdar candidate)))
+                           (alist-get 'candidates object))))
+    (seq-map (lambda (part)
+               (alist-get 'text (car part))))
+    (reverse)))
+
+;;;; Footer
+
+(provide 'plz-media-type-test)
+
+;;; plz-media-type-test.el ends here
diff --git a/tests/response/application/json/vertex-hello.txt 
b/tests/response/application/json/vertex-hello.txt
new file mode 100644
index 0000000000..8dff93cb64
--- /dev/null
+++ b/tests/response/application/json/vertex-hello.txt
@@ -0,0 +1,110 @@
+HTTP/2 200 
+content-type: application/json; charset=UTF-8
+vary: Origin
+vary: X-Origin
+vary: Referer
+content-encoding: gzip
+date: Fri, 15 Mar 2024 10:56:22 GMT
+server: scaffolding on HTTPServer2
+cache-control: private
+x-xss-protection: 0
+x-frame-options: SAMEORIGIN
+x-content-type-options: nosniff
+alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
+
+[{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": "Hi there!"
+          }
+        ]
+      },
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.022846196,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.03825006
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.058131594,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.044431433
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.060863446,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.034553625
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.11736965,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.10017223
+        }
+      ]
+    }
+  ]
+}
+,
+{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": " How can I assist you today?"
+          }
+        ]
+      },
+      "finishReason": "STOP",
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.030157408,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.04023794
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.08181271,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.025613913
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.047958102,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.015130728
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.17582092,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.0416178
+        }
+      ]
+    }
+  ],
+  "usageMetadata": {
+    "promptTokenCount": 1,
+    "candidatesTokenCount": 10,
+    "totalTokenCount": 11
+  }
+}
+]
\ No newline at end of file
diff --git a/tests/response/application/json/vertex-poem.txt 
b/tests/response/application/json/vertex-poem.txt
new file mode 100644
index 0000000000..fb545ab800
--- /dev/null
+++ b/tests/response/application/json/vertex-poem.txt
@@ -0,0 +1,335 @@
+HTTP/2 200 
+content-type: application/json; charset=UTF-8
+vary: Origin
+vary: X-Origin
+vary: Referer
+content-encoding: gzip
+date: Wed, 20 Mar 2024 08:11:00 GMT
+server: scaffolding on HTTPServer2
+cache-control: private
+x-xss-protection: 0
+x-frame-options: SAMEORIGIN
+x-content-type-options: nosniff
+alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
+
+[{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": "**Ode to Emacs, Master of Code**\n\nIn the realm of text, 
where chaos reigns,\nEmacs descends, a force"
+          }
+        ]
+      },
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.08064661,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.07682221
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.17078441,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.14414884
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.22661245,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.085403666
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.09568695,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.056444023
+        }
+      ]
+    }
+  ]
+}
+,
+{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": " that sustains.\nWith its 🧙 wizardry and 🗝️ secret 
powers,\nIt"
+          }
+        ]
+      },
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.055617608,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.044348583
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.1322902,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.111821815
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.107063465,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.03138043
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.11496335,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.039937314
+        }
+      ]
+    }
+  ]
+}
+,
+{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": " wrangles words, bringing order to hours.\n\nIts 🐈 
cat-like reflexes, lightning-fast,\nEdit and search with unmatched 
contrast.\nFrom 📜 scrolls to 💻 terminals so bright,\nEmacs illuminates the"
+          }
+        ]
+      },
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.063831605,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.052521676
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.062331032,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.113776386
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.11338311,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.04288224
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.12453206,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.042802148
+        }
+      ]
+    }
+  ]
+}
+,
+{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": " code with its light.\n\nIts 💻 extensions, a boundless 
expanse,\nTailor thy editor to thy heart's dance.\nFrom 🐍 Python to 💻 
TypeScript's sway,\nEmacs orchestrates, paving the way.\n\nWith its "
+          }
+        ]
+      },
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.059210256,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.051941562
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.039787807,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.10951516
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.10631887,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.05300978
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.101767845,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.0434469
+        }
+      ]
+    }
+  ]
+}
+,
+{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": "⌨️ keyboard shortcuts, a symphony of ease,\nThou navigate 
through code with utmost breeze.\nNo 🖱️ mouse required, thy fingers glide,\nAs 
thou command this editor with pride.\n\nIts 💻 terminal prowess, a window to 
grace,\nRun code, debug, and explore with space.\nFrom 🛠️ git"
+          }
+        ]
+      },
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.060863446,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.056652427
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.03155902,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.11636176
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.09704755,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.058024753
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.09203286,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.047249716
+        }
+      ]
+    }
+  ]
+}
+,
+{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": " commits to 🌐 network streams,\nEmacs empowers, 
fulfilling thy dreams.\n\nSo raise a 💻 keyboard, let fingers soar,\nWith Emacs 
as thy guide, knowledge to explore.\nThrough syntax jungles and coding 
maze,\nEmacs shines brightly, illuminating the ways.\n\nMay thy code be clean, 
thy projects refined,\nAs Emacs guides thee, leaving chaos behind.\nIn this 
digital realm, where creativity blooms,\nEmacs,"
+          }
+        ]
+      },
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.050988145,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.06119922
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.03138043,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.08756384
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.08137363,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.055515114
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.09041373,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.05340333
+        }
+      ]
+    }
+  ]
+}
+,
+{
+  "candidates": [
+    {
+      "content": {
+        "role": "model",
+        "parts": [
+          {
+            "text": " the sorcerer, dispels all dooms."
+          }
+        ]
+      },
+      "finishReason": "STOP",
+      "safetyRatings": [
+        {
+          "category": "HARM_CATEGORY_HATE_SPEECH",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.05781161,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.066934206
+        },
+        {
+          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.034293946,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.091220066
+        },
+        {
+          "category": "HARM_CATEGORY_HARASSMENT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.08647765,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.060197048
+        },
+        {
+          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
+          "probability": "NEGLIGIBLE",
+          "probabilityScore": 0.09384396,
+          "severity": "HARM_SEVERITY_NEGLIGIBLE",
+          "severityScore": 0.05340333
+        }
+      ]
+    }
+  ],
+  "usageMetadata": {
+    "promptTokenCount": 10,
+    "candidatesTokenCount": 320,
+    "totalTokenCount": 330
+  }
+}
+]
\ No newline at end of file
diff --git a/tests/response/application/json/vertext-unauthenticated.txt 
b/tests/response/application/json/vertext-unauthenticated.txt
new file mode 100644
index 0000000000..bcd53e3916
--- /dev/null
+++ b/tests/response/application/json/vertext-unauthenticated.txt
@@ -0,0 +1,31 @@
+HTTP/2 401 
+content-type: application/json; charset=UTF-8
+vary: Origin
+vary: X-Origin
+vary: Referer
+content-encoding: gzip
+date: Fri, 15 Mar 2024 10:56:22 GMT
+server: scaffolding on HTTPServer2
+cache-control: private
+x-xss-protection: 0
+x-frame-options: SAMEORIGIN
+x-content-type-options: nosniff
+alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
+
+[{
+  "error": {
+    "code": 401,
+    "message": "Request had invalid authentication credentials. Expected OAuth 
2 access token, login cookie or other valid authentication credential. See 
https://developers.google.com/identity/sign-in/web/devconsole-project.";,
+    "status": "UNAUTHENTICATED",
+    "details": [
+      {
+        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
+        "reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED",
+        "metadata": {
+          "service": "aiplatform.googleapis.com",
+          "method": 
"google.cloud.aiplatform.v1.PredictionService.StreamGenerateContent"
+        }
+      }
+    ]
+  }
+}]
\ No newline at end of file
diff --git a/tests/response/application/x-ndjson/ollama-hello.txt 
b/tests/response/application/x-ndjson/ollama-hello.txt
new file mode 100644
index 0000000000..1205412b81
--- /dev/null
+++ b/tests/response/application/x-ndjson/ollama-hello.txt
@@ -0,0 +1,32 @@
+HTTP/1.1 200 OK
+Content-Type: application/x-ndjson
+Date: Tue, 12 Mar 2024 12:05:13 GMT
+Transfer-Encoding: chunked
+
+{"model":"llama2","created_at":"2024-03-12T12:05:13.747334659Z","response":"Hello","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:13.814191426Z","response":" 
there","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:13.880926587Z","response":"!","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:13.947866055Z","response":" 
It","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.015054376Z","response":"'","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.082471215Z","response":"s","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.148577108Z","response":" 
nice","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.214802148Z","response":" 
to","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.281459481Z","response":" 
meet","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.350610212Z","response":" 
you","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.419490326Z","response":".","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.486487527Z","response":" 
Is","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.553190097Z","response":" 
there","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.623595043Z","response":" 
something","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.694458171Z","response":" 
I","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.76547139Z","response":" 
can","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.833659175Z","response":" 
help","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.903078162Z","response":" 
you","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:14.97368534Z","response":" 
with","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:15.046102396Z","response":" 
or","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:15.117115422Z","response":" 
would","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:15.18784764Z","response":" 
you","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:15.259555212Z","response":" 
like","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:15.328392358Z","response":" 
to","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:15.398189056Z","response":" 
chat","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:15.467785437Z","response":"?","done":false}
+{"model":"llama2","created_at":"2024-03-12T12:05:15.535938819Z","response":"","done":true,"context":[518,25580,29962,3532,14816,29903,29958,5299,829,14816,29903,6778,13,13,10994,518,29914,25580,29962,13,10994,727,29991,739,29915,29879,7575,304,5870,366,29889,1317,727,1554,306,508,1371,366,411,470,723,366,763,304,13563,29973],"total_duration":3569916695,"load_duration":782537698,"prompt_eval_count":21,"prompt_eval_duration":998427000,"eval_count":27,"eval_duration":1788606000}
diff --git a/tests/response/text/event-stream/openai-emoji.txt 
b/tests/response/text/event-stream/openai-emoji.txt
new file mode 100644
index 0000000000..36fbb031bf
--- /dev/null
+++ b/tests/response/text/event-stream/openai-emoji.txt
@@ -0,0 +1,30 @@
+HTTP/2 200 
+date: Mon, 18 Mar 2024 09:21:55 GMT
+content-type: text/event-stream
+access-control-allow-origin: *
+cache-control: no-cache, must-revalidate
+openai-model: gpt-3.5-turbo-0125
+openai-organization: user-fw69wrkwmbvzme6szvt8tcol
+openai-processing-ms: 324
+openai-version: 2020-10-01
+strict-transport-security: max-age=15724800; includeSubDomains
+x-ratelimit-limit-requests: 10000
+x-ratelimit-limit-tokens: 60000
+x-ratelimit-remaining-requests: 9999
+x-ratelimit-remaining-tokens: 59971
+x-ratelimit-reset-requests: 8.64s
+x-ratelimit-reset-tokens: 29ms
+x-request-id: req_354442e58bd8858eb36ec66252b064bc
+cf-cache-status: DYNAMIC
+server: cloudflare
+cf-ray: 866427bfef893bbf-WAW
+alt-svc: h3=":443"; ma=86400
+
+data: 
{"id":"chatcmpl-943TnFu5Ta6soqBxGjdFglP8og3L0","object":"chat.completion.chunk","created":1710753715,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943TnFu5Ta6soqBxGjdFglP8og3L0","object":"chat.completion.chunk","created":1710753715,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"🙂"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943TnFu5Ta6soqBxGjdFglP8og3L0","object":"chat.completion.chunk","created":1710753715,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}
+
+data: [DONE]
+
diff --git a/tests/response/text/event-stream/openai-hello.txt 
b/tests/response/text/event-stream/openai-hello.txt
new file mode 100644
index 0000000000..bf11d635e7
--- /dev/null
+++ b/tests/response/text/event-stream/openai-hello.txt
@@ -0,0 +1,46 @@
+HTTP/2 200 
+date: Mon, 18 Mar 2024 09:46:36 GMT
+content-type: text/event-stream
+access-control-allow-origin: *
+cache-control: no-cache, must-revalidate
+openai-model: gpt-3.5-turbo-0125
+openai-organization: user-fw69wrkwmbvzme6szvt8tcol
+openai-processing-ms: 251
+openai-version: 2020-10-01
+strict-transport-security: max-age=15724800; includeSubDomains
+x-ratelimit-limit-requests: 10000
+x-ratelimit-limit-tokens: 60000
+x-ratelimit-remaining-requests: 9999
+x-ratelimit-remaining-tokens: 59975
+x-ratelimit-reset-requests: 8.64s
+x-ratelimit-reset-tokens: 25ms
+x-request-id: req_aa8aa09f84cb55c9ac5b5a7f80bd8b44
+cf-cache-status: DYNAMIC
+server: cloudflare
+cf-ray: 86644be7998534e0-WAW
+alt-svc: h3=":443"; ma=86400
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"!"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"
 How"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"
 can"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"
 I"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"
 assist"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"
 you"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"
 today"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{"content":"?"},"logprobs":null,"finish_reason":null}]}
+
+data: 
{"id":"chatcmpl-943rgCSYEAaL283mHJodpzvDJjGT9","object":"chat.completion.chunk","created":1710755196,"model":"gpt-3.5-turbo-0125","system_fingerprint":"fp_4f2ebda25a","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}
+
+data: [DONE]
+
diff --git a/tests/test-plz-media-type.el b/tests/test-plz-media-type.el
new file mode 100644
index 0000000000..fb24a28f42
--- /dev/null
+++ b/tests/test-plz-media-type.el
@@ -0,0 +1,366 @@
+;;; test-plz-media-type.el --- Plz media type tests -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2019-2023  Free Software Foundation, Inc.
+
+;; Author: r0man <roman@burningswell.com>
+;; Maintainer: r0man <roman@burningswell.com>
+
+;; This file is part of GNU Emacs.
+
+;;; License:
+
+;; This program 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, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Plz media type tests
+
+;;; Code:
+
+(require 'ert)
+(require 'plz-media-type)
+(require 'plz-media-type-test)
+
+(plz-deftest test-plz-media-type:application/json:async ()
+  (let* ((response)
+         (process (plz-media-type-request 'get (url "/json")
+                    :as `(media-types ,plz-media-types)
+                    :then (lambda (object)
+                            (setf response object)))))
+    (plz-media-type-test-wait process)
+    (should (plz-response-p response))
+    (should (equal 200 (plz-response-status response)))
+    (let-alist (plz-response-body response)
+      (should (equal "Sample Slide Show" .slideshow.title)))))
+
+(plz-deftest test-plz-media-type:application/json:sync ()
+  (let ((response (plz-media-type-request 'get (url "/json")
+                    :as `(media-types ,plz-media-types))))
+    (should (plz-response-p response))
+    (should (equal 200 (plz-response-status response)))
+    (let-alist (plz-response-body response)
+      (should (equal "Sample Slide Show" .slideshow.title)))))
+
+(ert-deftest test-plz-media-type:application/json:sync-error ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/json/vertext-unauthenticated.txt")
+    (let* ((result (condition-case error
+                       (plz-media-type-request 'get "MOCK-URL"
+                         :as `(media-types ((application/json . 
,(plz-media-type:application/json)))))
+                     (plz-error error))))
+      (should (equal 'plz-http-error (car result)))
+      (should (equal "HTTP error" (cadr result)))
+      (let ((error (caddr result)))
+        (should (plz-error-p error))
+        (let ((response (plz-error-response error)))
+          (should (plz-response-p response))
+          (should (equal 401 (plz-response-status response)))
+          (should (equal '(code . 401) (cadar (elt (plz-response-body 
response) 0)))))))))
+
+(plz-deftest test-plz-media-type:text/html:async ()
+  (let* ((response)
+         (process (plz-media-type-request 'get (url "/html")
+                    :as `(media-types ,plz-media-types)
+                    :then (lambda (object)
+                            (setf response object)))))
+    (plz-media-type-test-wait process)
+    (should (plz-response-p response))
+    (should (equal 200 (plz-response-status response)))
+    (should (equal 'html (car (plz-response-body response))))))
+
+(plz-deftest test-plz-media-type:text/html:sync ()
+  (let ((response (plz-media-type-request 'get (url "/html")
+                    :as `(media-types ,plz-media-types))))
+    (should (plz-response-p response))
+    (should (equal 200 (plz-response-status response)))
+    (should (equal 'html (car (plz-response-body response))))))
+
+(plz-deftest test-plz-media-type:application/xml:async ()
+  (let* ((response)
+         (process (plz-media-type-request 'get (url "/xml")
+                    :as `(media-types ,plz-media-types)
+                    :then (lambda (object)
+                            (setf response object)))))
+    (plz-media-type-test-wait process)
+    (should (plz-response-p response))
+    (should (equal 200 (plz-response-status response)))
+    (should (equal 'top (car (plz-response-body response))))))
+
+(plz-deftest test-plz-media-type:application/xml:sync ()
+  (let ((response (plz-media-type-request 'get (url "/xml")
+                    :as `(media-types ,plz-media-types))))
+    (should (plz-response-p response))
+    (should (equal 200 (plz-response-status response)))
+    (should (equal 'top (car (plz-response-body response))))))
+
+(ert-deftest test-plz-media-type-parse ()
+  (should (null (plz-media-type-parse nil)))
+  (should (null (plz-media-type-parse "")))
+  (should (equal (plz-media-type :type 'text :subtype 'html)
+                 (plz-media-type-parse "text/html")))
+  (should (equal (plz-media-type
+                  :type 'text
+                  :subtype 'html
+                  :parameters '(("charset" . "UTF-8")))
+                 (plz-media-type-parse "text/html;charset=UTF-8")))
+  (should (equal (plz-media-type
+                  :type 'text
+                  :subtype 'html
+                  :parameters '(("charset" . "UTF-8")
+                                ("boundary" . "AaB03x\"")))
+                 (plz-media-type-parse "text/html; charset=UTF-8; 
boundary=\"AaB03x\""))))
+
+(ert-deftest test-plz-media-type-charset ()
+  (let ((media-type (plz-media-type-parse "text/html; charset=UTF-8")))
+    (should (equal "UTF-8" (plz-media-type-charset media-type)))))
+
+(ert-deftest test-plz-media-type-coding-system ()
+  (let ((media-type (plz-media-type-parse "text/html")))
+    (should (equal 'utf-8 (plz-media-type-coding-system media-type))))
+  (let ((media-type (plz-media-type-parse "text/html; charset=UTF-8")))
+    (should (equal 'utf-8 (plz-media-type-coding-system media-type)))))
+
+(ert-deftest test-plz-media-type-symbol ()
+  (let ((media-type (plz-media-type-parse "text/html")))
+    (should (equal 'text/html (plz-media-type-symbol media-type)))))
+
+(ert-deftest test-plz-media-type-process-filter-error-sync ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/x-ndjson/ollama-hello.txt")
+    (let ((result (condition-case error
+                      (plz-media-type-request 'get "MOCK-URL"
+                        :as `(media-types ((application/x-ndjson
+                                            . 
,(plz-media-type:application/x-ndjson
+                                                :handler (lambda (_) (signal 
'error "boom")))))))
+                    (plz-error error))))
+      (should (equal 'plz-media-type-filter-error (elt result 0)))
+      (should (equal "error in process filter: (error . \"boom\")" (elt result 
1)))
+      (let ((response (elt result 2)))
+        (should (plz-response-p response))
+        (should (equal 200 (plz-response-status response)))
+        (should (null (plz-response-body response))))
+      (should (equal '(error . "boom") (elt result 3))))))
+
+(ert-deftest test-plz-media-type-process-filter-error-async ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/x-ndjson/ollama-hello.txt")
+    (let* ((else) (finally) (then)
+           (process (plz-media-type-request 'get "MOCK-URL"
+                      :as `(media-types ((application/x-ndjson
+                                          . 
,(plz-media-type:application/x-ndjson
+                                              :handler (lambda (_) (signal 
'error "boom"))))))
+                      :else (lambda (object) (push object else))
+                      :finally (lambda () (push t finally))
+                      :then (lambda (object) (push object then)))))
+      (plz-media-type-test-wait process)
+      (should (equal '(t) finally))
+      (should (equal 0 (length then)))
+      (should (equal 1 (length else)))
+      (seq-doseq (error else)
+        (should (plz-error-p error))
+        (should (plz-media-type-filter-error-p error))
+        (should (equal "error in process filter: (error . \"boom\")" 
(plz-error-message error)))
+        (should (equal '(error . "boom") (plz-media-type-filter-error-cause 
error)))
+        (let ((response (plz-error-response error)))
+          (should (plz-response-p response))
+          (should (equal 200 (plz-response-status response)))
+          (should (null (plz-response-body response))))))))
+
+(ert-deftest test-plz-media-type:application/octet-stream:stream ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"text/event-stream/openai-hello.txt")
+    (let* ((else) (finally) (then)
+           (process (plz-media-type-request 'post 
"https://api.openai.com/v1/chat/completions";
+                      :as `(media-types `((t . 
,(plz-media-type:application/octet-stream))))
+                      :else (lambda (object) (push object else))
+                      :finally (lambda () (push t finally))
+                      :then (lambda (object) (push object then)))))
+      (plz-media-type-test-wait process)
+      (should (null else))
+      (should (equal '(t) finally))
+      (should (equal 1 (length then)))
+      (seq-doseq (response then)
+        (should (plz-response-p response))
+        (should (equal 200 (plz-response-status response)))
+        (should (string-match "[DONE]" (plz-response-body response)))))))
+
+(ert-deftest test-plz-media-type:application/x-ndjson ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/x-ndjson/ollama-hello.txt")
+    (let* ((else) (finally) (then) (objects)
+           (process (plz-media-type-request 'get "MOCK-URL"
+                      :as `(media-types ((application/x-ndjson
+                                          . 
,(plz-media-type:application/x-ndjson
+                                              :handler (lambda (object)
+                                                         (push object 
objects))))))
+                      :else (lambda (object) (push object else))
+                      :finally (lambda () (push t finally))
+                      :then (lambda (object) (push object then)))))
+      (plz-media-type-test-wait process)
+      (should (null else))
+      (should (equal '(t) finally))
+      (should (equal 1 (length then)))
+      (seq-doseq (response then)
+        (should (plz-response-p response))
+        (should (equal 200 (plz-response-status response)))
+        (should (null (plz-response-body response))))
+      (should (equal 27 (length objects)))
+      (should (equal '((model . "llama2")
+                       (created_at . "2024-03-12T12:05:13.747334659Z")
+                       (response . "Hello")
+                       (done . :json-false))
+                     (seq-elt objects 26)))
+      ;; TODO: Fix parsing of last line :/
+      (should (equal '((model . "llama2")
+                       (created_at . "2024-03-12T12:05:15.467785437Z")
+                       (response . "?")
+                       (done . :json-false))
+                     (seq-elt objects 1))))))
+
+(ert-deftest test-plz-media-type:application/json-array:async ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/json/vertex-hello.txt")
+    (let* ((else) (finally) (then) (objects)
+           (process (plz-media-type-request 'get "MOCK-URL"
+                      :as `(media-types ((application/json
+                                          . 
,(plz-media-type:application/json-array
+                                              :handler (lambda (object)
+                                                         (push object 
objects))))))
+                      :else (lambda (object) (push object else))
+                      :finally (lambda () (push t finally))
+                      :then (lambda (object) (push object then)))))
+      (plz-media-type-test-wait process)
+      (should (null else))
+      (should (equal '(t) finally))
+      (should (equal 1 (length then)))
+      (seq-doseq (response then)
+        (should (plz-response-p response))
+        (should (equal 200 (plz-response-status response)))
+        (should (null (plz-response-body response))))
+      (should (equal 2 (length objects)))
+      (should (equal '("Hi there!" " How can I assist you today?")
+                     (plz-media-type-test-vertex-extract-content objects))))))
+
+(ert-deftest test-plz-media-type:application/json-array:async-poem ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/json/vertex-poem.txt")
+    (let* ((else) (finally) (then) (objects)
+           (process (plz-media-type-request 'get "MOCK-URL"
+                      :as `(media-types ((application/json
+                                          . 
,(plz-media-type:application/json-array
+                                              :handler (lambda (object)
+                                                         (push object 
objects))))))
+                      :else (lambda (object) (push object else))
+                      :finally (lambda () (push t finally))
+                      :then (lambda (object) (push object then)))))
+      (plz-media-type-test-wait process)
+      (should (null else))
+      (should (equal '(t) finally))
+      (should (equal 1 (length then)))
+      (seq-doseq (response then)
+        (should (plz-response-p response))
+        (should (equal 200 (plz-response-status response)))
+        (should (null (plz-response-body response))))
+      (should (equal 7 (length objects)))
+      (let ((parts (plz-media-type-test-vertex-extract-content objects)))
+        (should (string-match "**Ode to Emacs, Master of Code" (cl-first 
parts)))
+        (should (equal '(" the sorcerer, dispels all dooms.") (last 
parts)))))))
+
+(ert-deftest test-plz-media-type:application/json-array:sync ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/json/vertex-hello.txt")
+    (let* ((objects)
+           (response (plz-media-type-request 'get "MOCK-URL"
+                       :as `(media-types ((application/json
+                                           . 
,(plz-media-type:application/json-array
+                                               :handler (lambda (object)
+                                                          (push object 
objects)))))))))
+      (should (plz-response-p response))
+      (should (equal 200 (plz-response-status response)))
+      (should (null (plz-response-body response)))
+      (should (equal 2 (length objects)))
+      (should (equal '("Hi there!" " How can I assist you today?")
+                     (plz-media-type-test-vertex-extract-content objects))))))
+
+(ert-deftest test-plz-media-type:application/json-array:async-error ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/json/vertext-unauthenticated.txt")
+    (let* ((else) (finally) (then) (objects)
+           (process (plz-media-type-request 'get "MOCK-URL"
+                      :as `(media-types ((application/json
+                                          . 
,(plz-media-type:application/json-array
+                                              :handler (lambda (object)
+                                                         (push object 
objects))))))
+                      :else (lambda (object) (push object else))
+                      :finally (lambda () (push t finally))
+                      :then (lambda (object) (push object then)))))
+      (plz-media-type-test-wait process)
+      (should (equal '(t) finally))
+      (should (null then))
+      (should (equal 1 (length else)))
+      (seq-doseq (error else)
+        (should (plz-error-p error))
+        (let ((response (plz-error-response error)))
+          (should (plz-response-p response))
+          (should (equal 401 (plz-response-status response)))
+          (should (null (plz-response-body response)))))
+      (should (equal 1 (length objects)))
+      (should (equal '(code . 401) (cadaar objects))))))
+
+(ert-deftest test-plz-media-type:application/json-array:sync-error ()
+  (plz-media-type-test-with-mock-response (plz-media-type-test-response 
"application/json/vertext-unauthenticated.txt")
+    (let* ((objects)
+           (result (condition-case error
+                       (plz-media-type-request 'get "MOCK-URL"
+                         :as `(media-types ((application/json
+                                             . 
,(plz-media-type:application/json-array
+                                                 :handler (lambda (object)
+                                                            (push object 
objects)))))))
+                     (plz-error error))))
+      (should (equal 'plz-http-error (car result)))
+      (should (equal "HTTP error" (cadr result)))
+      (let ((error (caddr result)))
+        (should (plz-error-p error))
+        (let ((response (plz-error-response error)))
+          (should (plz-response-p response))
+          (should (equal 401 (plz-response-status response)))
+          (should (null (plz-response-body response)))))
+      (should (equal 1 (length objects)))
+      (should (equal '(code . 401) (cadaar objects))))))
+
+(plz-deftest plz-media-type-request-timeout-sync ()
+  (pcase-let* ((start-time (current-time))
+               (`(,_signal . (,_message ,(cl-struct plz-error (curl-error 
`(,code . ,message)))))
+               (should-error (plz-media-type-request 'get (url "/delay/5")
+                               :as `(media-types ,plz-media-types)
+                                :then 'sync
+                                :timeout 1)
+                             :type 'plz-error))
+               (end-time (current-time)))
+    (should (eq 28 code))
+    (should (equal "Operation timeout." message))
+    (should (< (time-to-seconds (time-subtract end-time start-time)) 1.1))))
+
+(plz-deftest plz-media-type-request-timeout-async ()
+  (let* ((start-time (current-time))
+         (end-time)
+         (plz-error)
+         (process (plz-media-type-request 'get (url "/delay/5")
+                    :as `(media-types ,plz-media-types)
+                    :timeout 1
+                    :then #'ignore
+                    :else (lambda (e)
+                            (setf end-time (current-time)
+                                  plz-error e)))))
+    (plz-media-type-test-wait process)
+    (should (eq 28 (car (plz-error-curl-error plz-error))))
+    (should (equal "Operation timeout." (cdr (plz-error-curl-error 
plz-error))))
+    (should (< (time-to-seconds (time-subtract end-time start-time)) 1.1))))
+
+;;;; Footer
+
+(provide 'test-plz-media-type)
+
+;;; test-plz-media-type.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]