c208dffb7b
* v0.8.1 * Add the HTTP version to `Request` The `node-http` `Request` has the HTTP version on it. We can make it available in our `Request` for consumers. We went the naive approach first and typed it as a string. There is some structure to the version, so we could attempt to parse it. It's unclear what we would do if parsing failed though. Maybe we want something like: ```PureScript data Version = Known { major :: Int, minor :: Int } | Unknown String ``` That would allow us to parse the known format, and fallback to accepting anything else. It's definitely something to discuss anyway. * Make HTTP version its own data type There are only a handful of HTTP versions that are commonly used. We can talk about those explicitly and fallback to any arbitrary version. The changes here try to follow the patterns elsewhere in the code base. Hopefully, it's not too far off.
64 lines
2.1 KiB
Haskell
64 lines
2.1 KiB
Haskell
module Test.HTTPure.VersionSpec where
|
|
|
|
import Prelude
|
|
|
|
import Test.Spec as Spec
|
|
|
|
import HTTPure.Version as Version
|
|
|
|
import Test.HTTPure.TestHelpers as TestHelpers
|
|
import Test.HTTPure.TestHelpers ((?=))
|
|
|
|
showSpec :: TestHelpers.Test
|
|
showSpec = Spec.describe "show" do
|
|
Spec.describe "with an HTTP0_9" do
|
|
Spec.it "is 'HTTP0_9'" do
|
|
show Version.HTTP0_9 ?= "HTTP/0.9"
|
|
Spec.describe "with an HTTP1_0" do
|
|
Spec.it "is 'HTTP1_0'" do
|
|
show Version.HTTP1_0 ?= "HTTP/1.0"
|
|
Spec.describe "with an HTTP1_1" do
|
|
Spec.it "is 'HTTP1_1'" do
|
|
show Version.HTTP1_1 ?= "HTTP/1.1"
|
|
Spec.describe "with an HTTP2_0" do
|
|
Spec.it "is 'HTTP2_0'" do
|
|
show Version.HTTP2_0 ?= "HTTP/2.0"
|
|
Spec.describe "with an HTTP3_0" do
|
|
Spec.it "is 'HTTP3_0'" do
|
|
show Version.HTTP3_0 ?= "HTTP/3.0"
|
|
Spec.describe "with an Other" do
|
|
Spec.it "is 'Other'" do
|
|
show (Version.Other "version") ?= "HTTP/version"
|
|
|
|
readSpec :: TestHelpers.Test
|
|
readSpec = Spec.describe "read" do
|
|
Spec.describe "with an 'HTTP0_9' Request" do
|
|
Spec.it "is HTTP0_9" do
|
|
request <- TestHelpers.mockRequest "0.9" "" "" "" []
|
|
Version.read request ?= Version.HTTP0_9
|
|
Spec.describe "with an 'HTTP1_0' Request" do
|
|
Spec.it "is HTTP1_0" do
|
|
request <- TestHelpers.mockRequest "1.0" "" "" "" []
|
|
Version.read request ?= Version.HTTP1_0
|
|
Spec.describe "with an 'HTTP1_1' Request" do
|
|
Spec.it "is HTTP1_1" do
|
|
request <- TestHelpers.mockRequest "1.1" "" "" "" []
|
|
Version.read request ?= Version.HTTP1_1
|
|
Spec.describe "with an 'HTTP2_0' Request" do
|
|
Spec.it "is HTTP2_0" do
|
|
request <- TestHelpers.mockRequest "2.0" "" "" "" []
|
|
Version.read request ?= Version.HTTP2_0
|
|
Spec.describe "with an 'HTTP3_0' Request" do
|
|
Spec.it "is HTTP3_0" do
|
|
request <- TestHelpers.mockRequest "3.0" "" "" "" []
|
|
Version.read request ?= Version.HTTP3_0
|
|
Spec.describe "with an 'Other' Request" do
|
|
Spec.it "is Other" do
|
|
request <- TestHelpers.mockRequest "version" "" "" "" []
|
|
Version.read request ?= Version.Other "version"
|
|
|
|
versionSpec :: TestHelpers.Test
|
|
versionSpec = Spec.describe "Version" do
|
|
showSpec
|
|
readSpec
|