# Haskell HTTP(S) libraries don't work well

**URL:** <https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087>\
**Category:** Uncategorized\
**Created:** [November 11, 2023, 9:15am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087 "2023-11-11T09:15:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liamzy](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@Liamzy](https://discourse.haskell.org/u/Liamzy)\
**Post date:** [November 11, 2023, 9:15am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/1 "2023-11-11T09:15:05Z")

</div>

I’d consider it a big flaw in base that we don’t have “approved” HTTP libraries, but getting simple HTTP into base is a political quagmire.

But what’s worse is that the Haskell HTTP libraries aren’t at a sufficient level of maturity for someone to even push to add HTTP into base; for instance, Network.HTTP.Conduit will crap out if I have Linux shell variables pointing my HTTP proxy to socks.

From what I’ve seen of the group working on Cabal, the labor and organization seems to be at least adequate, and good things will come within the span of a year.

But that still leaves us with the library ecosystem at large, and the question is, “Can we do better?”

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [November 11, 2023, 9:28am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/2 "2023-11-11T09:28:49Z")

</div>

> [@Liamzy](#):
>
> I’d consider it a big flaw in base that we don’t have “approved” HTTP libraries, but getting simple HTTP into base is a political quagmire.

I’m not sure why that would need to be in base, especially given how you noticed that the maturity is sub-par.

On the other hand, core libraries are a bit of a fuzzy term and there’s not a very clear guideline on what’s supposed to be a core library and how to become one. The CLC readme has some words on that [here](https://github.com/haskell/core-libraries-committee#core-libraries).

My opinion is that it could be up to a separate project to define a set of battle tested libraries, document maintenance status and so on. That is mostly documentation work. No need to push this into base and burn CLC out.

---

<div class="post-metadata">

**Author:** ![Nycticorax](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/nycticorax/32/834_2.png) [@Nycticorax](https://discourse.haskell.org/u/Nycticorax)\
**Post date:** [November 11, 2023, 9:38am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/3 "2023-11-11T09:38:50Z")

</div>

If the issue is of the high-effort/high impact type, perhaps the Haskell Foundation could put a bounty on it? If we have such things?

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [November 11, 2023, 9:45am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/4 "2023-11-11T09:45:02Z")

</div>

The main issue here is TLS.

haskell-tls is questionable: there’s no audit, we don’t have sufficient research that explores how vulnerable haskell GC/RTS is to side channel attacks, how memory secure, how it plays with laziness, etc. etc.

If you use HsOpenSSL instead, you’ll get into trouble distributing your binary, if you link dynamically. If you link statically, you’ll have a security hazard.

The solution is bindings (HsOpenSSL or botan or whatever), but the shipping/distribution issue will remain: dynamic linking causes portability issues, static linking causes security issues. That’s why shelling out to curl is the most portable and easiest solution, in fact.

---

<div class="post-metadata">

**Author:** ![Liamzy](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@Liamzy](https://discourse.haskell.org/u/Liamzy)\
**Post date:** [November 11, 2023, 9:49am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/5 "2023-11-11T09:49:53Z")

</div>

The reason I think it’d be nice to have in `base` would be so that a fast call to `ghci` would be able to get a hold of network access, instead of playing Russian Roulette with `cabal install --lib` (it’ll blow up in your face sooner or later) or putting up with delayed build times with `cabal repl` / cabal scripts.

The `String` precedent is also very nice as well; people complain about String all the time, wish that we defaulted to `Text`, but `String` implies it’s fine to have a suboptimal code in `base` and have people be expected to use other things instead for serious work.

Go at least has network libs in standard libraries, and given that Haskell is used a lot for backend, it seems reasonable to not expect learners or trial users to get a library to make HTTP requests.

* * *

That said, I agree that existing network libs are, while very mature, not mature enough, and there’s likely to be serious technological challenges because of the need for secure cryptography.

I guess it’s something the Haskell community doesn’t have the resources to do at this point in time. 🙂

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [November 11, 2023, 9:52am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/6 "2023-11-11T09:52:03Z")

</div>

> [@Liamzy](#):
>
> The reason I think it’d be nice to have in `base` would be so that a fast call to `ghci` would be able to get a hold of network access, instead of playing Russian Roulette with `cabal install --lib` (it’ll blow up in your face sooner or later) or putting up with delayed build times with `cabal repl` / cabal scripts.

That’s an issue to better fix in cabal instead of bloating up base library due to cabal usability issues.

---

<div class="post-metadata">

**Author:** ![atravers](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@atravers](https://discourse.haskell.org/u/atravers)\
**Post date:** [November 11, 2023, 9:54am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/7 "2023-11-11T09:54:02Z")

</div>

…and wasn’t @Ericson2314 contemplating a break-up of `base` after its separation from GHC?

* * *

> [@Liamzy](#):
>
> The `String` precedent is also very nice as well; people complain about String all the time, wish that we defaulted to `Text` […]

…was `Text` available in 2010? (But _that_ topic really should have its own thread.)

---

<div class="post-metadata">

**Author:** ![Liamzy](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@Liamzy](https://discourse.haskell.org/u/Liamzy)\
**Post date:** [November 11, 2023, 10:00am UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/8 "2023-11-11T10:00:02Z")

</div>

It depends, I’m trying to push for `cabal init` to do `-threaded ` by default, but in theory, this is supposed to be GHC’s problem (there’s an open ticket there that’s stalled because the intended contributor had issues working with the testing framework).

I guess the Stack folks have it easy; base + GHC + cabal + GHCup are the core Haskell toolchain and everyone keeps on pushing problems to some other part of the toolchain.

* * *

In any case, I agree with most of what you’ve said.

---

<div class="post-metadata">

**Author:** ![BurningWitness](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/burningwitness/32/3665_2.png) [@BurningWitness](https://discourse.haskell.org/u/BurningWitness)\
**Post date:** [November 11, 2023, 1:00pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/9 "2023-11-11T13:00:11Z")

</div>

> If you link statically, you’ll have a security hazard.

Could you elaborate on this? I don’t think the “outdated C library” argument works because [from my extremely limited experience] network libraries are complex state machines, so a pure Haskell implementation could easily be way less secure.

I also wonder if as a Core Library it could be built into a binary and distributed that way, which would allow backwards-compatible security updates through simple minor version bumps on every version in a several-year time window.

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [November 11, 2023, 1:19pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/10 "2023-11-11T13:19:51Z")

</div>

> [@BurningWitness](#):
>
> Could you elaborate on this?

Instead of having one point of security updates (e.g. linux distributors who very closely monitor CVEs and have tools and communication processes in place since decades) that are shipped easily and quickly, now it’s up to every application developer to monitor CVEs and roll out new binaries in case anything statically linked is busted.

That is _significant_ work. We just started to have Haskell security advisories. We’re not even close to that level of trust from application developers.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [November 11, 2023, 1:22pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/11 "2023-11-11T13:22:13Z")

</div>

Can you also elaborate on the portability issues of dynamic linking e.g. botan? Doesn’t shelling out to `curl` also cause portability issues (it might not be present or it might be slightly different on each platform)? Is there really such a big difference between the two?

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [November 11, 2023, 1:28pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/12 "2023-11-11T13:28:30Z")

</div>

> [@jaror](#):
>
> Can you also elaborate on the portability issues of dynamic linking e.g. botan?

When you link dynamically, you have a couple of options:

- ship bindists for every distro you can imagine (built on said distro)… this is what HLS does to achieve high portability (and we can’t link HLS statically due to certain issues)
- build on the oldest distro you can find (debian oldstable or something): that’s not good for security either, but works well for glibc compatibility
- analyze all the library versions for every distro and build bindists for ABI versions (GHC has a [matrix](https://gitlab.haskell.org/ghc/ghc/-/wikis/platforms/linux) for example)

Either way, it usually increases the complexity of shipping binaries. Depending on how stable the ABI of the library is, old binaries may also stop working (that’s happening with old GHC bindists linked against old ncurses right now).

---

<div class="post-metadata">

**Author:** ![ApothecaLabs](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/apothecalabs/32/3215_2.png) [@ApothecaLabs](https://discourse.haskell.org/u/ApothecaLabs)\
**Post date:** [November 11, 2023, 2:43pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/13 "2023-11-11T14:43:20Z")

</div>

Since botan was mentioned - there is a [full TLS implementation](https://botan.randombit.net/handbook/api_ref/tls.html) in botan, but it is not present in the FFI and it will require some C++ work before I can provide Haskell bindings to it. I am not sure what the timeline for that will be, but I am currently performing work of a similar nature to enable X509 certificate support.

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [November 11, 2023, 2:49pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/14 "2023-11-11T14:49:03Z")

</div>

In the case of botan [there are just two families of versions in common use](https://repology.org/project/botan/information):

- 2.19.3
- 3.X.X

So as long as you support both you should be good for a while (botan respects semver since 2.0.0).

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [November 11, 2023, 3:03pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/15 "2023-11-11T15:03:38Z")

</div>

The default version in fedora is 1.10.17. There’s another package `botan2`, which is version 2.19.1. Fedora has no version 3.

So it already seems quite rapidly evolving. And ABI incompatibility can happen within a major version, see [here](https://github.com/semver/semver/issues/590).

---

<div class="post-metadata">

**Author:** ![atravers](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@atravers](https://discourse.haskell.org/u/atravers)\
**Post date:** [November 11, 2023, 3:10pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/16 "2023-11-11T15:10:30Z")

</div>

> [@hasufell](#):
>
> the shipping/distribution issue […] dynamic linking causes portability issues, static linking causes security issues.

…so either way, you’ll risk being considered a _“novelty”_ :

- use static linking and be practically useless due to the security concerns of developers being _“out-of-date”_ ;

- use dynamic linking and be literally useless for certain combinations of OSs, libraries, _etc_.

Forget `rustup` for the moment, how is _this_ dilemma managed in Rust?

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [November 11, 2023, 3:20pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/17 "2023-11-11T15:20:55Z")

</div>

> [@atravers](#):
>
> how is _this_ dilemma managed in Rust

1. they don’t use a GCed language with laziness
2. they have an [audited](https://github.com/rustls/rustls/blob/master/audit/TLS-01-report.pdf) TLS implementation
3. they have CVEs and security baked into their ecosystem and policies: [Security policy - Rust Programming Language](https://www.rust-lang.org/policies/security)

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [November 11, 2023, 3:33pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/18 "2023-11-11T15:33:34Z")

</div>

> [@hasufell](#):
>
> The default version in fedora is 1.10.17. There’s another package `botan2`, which is version 2.19.1. Fedora has no version 3.

Those have various vulnerabilities ([1.10.17](https://repology.org/project/botan/cves?version=1.10.17) and [2.19.1](https://repology.org/project/botan/cves?version=2.19.1)), it seems wise to not support them. Edit: Also it seems [Fedora 38 and 39 do have 2.19.3](https://packages.fedoraproject.org/pkgs/botan2/botan2/).

> [@hasufell](#):
>
> And ABI incompatibility can happen within a major version, see [here](https://github.com/semver/semver/issues/590).

[Botan ensures ABI stability of the C API:](https://botan.randombit.net/handbook/abi.html)

> If you are concerned about long-term ABI issues, considering using the C API instead; this subset _is_ ABI stable.

But that is troubling if TLS is not part of the C API…

---

<div class="post-metadata">

**Author:** ![ApothecaLabs](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/apothecalabs/32/3215_2.png) [@ApothecaLabs](https://discourse.haskell.org/u/ApothecaLabs)\
**Post date:** [November 11, 2023, 3:43pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/19 "2023-11-11T15:43:55Z")

</div>

> [@jaror](#):
>
> But that is troubling if TLS is not part of the C API…

All the more reason for me to add it then 😁

---

<div class="post-metadata">

**Author:** ![sclv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/sclv/32/71_2.png) [@sclv](https://discourse.haskell.org/u/sclv)\
**Post date:** [November 11, 2023, 5:20pm UTC](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087/20 "2023-11-11T17:20:36Z")

</div>

First, I want to say that even if we had a great http library that everyone agreed was great, I would not want it in base, or even in a core lib shipped with ghc, because experience has taught us that even libraries everyone agrees on are best managed when decoupled, where possible.

Second I am hopeful that botan will provide a good tls api and make a reliable and easy to install cross-platform HTTP(s) library possible.

But finally, I want to point out that for _many_ circumstances, having a good tls implementation and a good http implementation is not nearly enough to have a good http library for all users. Unfortunately, there’s a lot of other “conveniences” that people expect with http clients – that they follow redirects, that they handle different connection disruptions in a recoverable way, and especially that they can probe a bunch of system configuration to try to determine and make use of system proxy settings.

This is one reason why in my experience, the robustness of an http experience _even when linking against libcurl_ is not nearly as nice as shelling out to curl – the executable does a very good job of dealing with all that stuff (as well as auth schemes, etc) in the way closest to what “normal users expect”.

I’d love for us to have a library that worked close to as well – but I just want to caution that the task is way larger than just the basic protocols would suggest.

(Let me add: for writing programs and servers running on systems I personally control, and where I can configure both code and the system itself, then existing libraries are fine, and perhaps preferable to shelling out – but for writing programs that can be distributed widely and be used by many people over many different system configurations, that’s when it turns out to be very painful)

[Next page](https://discourse.haskell.org/t/haskell-http-s-libraries-dont-work-well/8087.md?page=2)
