Merge branch 'master' into gb-streaming
This commit is contained in:
commit
85cf8d1c60
12 changed files with 212 additions and 74 deletions
153
.travis.yml
153
.travis.yml
|
@ -1,32 +1,131 @@
|
||||||
sudo: false
|
# This Travis job script has been generated by a script via
|
||||||
dist: trusty
|
#
|
||||||
|
# make_travis_yml_2.hs '-f' '-o' '.travis.yml' 'cabal.project'
|
||||||
|
#
|
||||||
|
# For more information, see https://github.com/hvr/multi-ghc-travis
|
||||||
|
#
|
||||||
language: c
|
language: c
|
||||||
|
sudo: false
|
||||||
|
|
||||||
env:
|
git:
|
||||||
- STACK_YAML=stack-ghc-7.8.4.yaml
|
submodules: false # whether to recursively clone submodules
|
||||||
- STACK_YAML=stack-ghc-7.10.3.yaml
|
|
||||||
- STACK_YAML=stack.yaml
|
|
||||||
- STACK_YAML=stack-ghc-8.2.1.yaml
|
|
||||||
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- libgmp-dev
|
|
||||||
|
|
||||||
install:
|
|
||||||
- mkdir -p ~/.local/bin
|
|
||||||
- export PATH=$HOME/.local/bin:$PATH
|
|
||||||
- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
|
|
||||||
- stack --version
|
|
||||||
- stack setup --no-terminal
|
|
||||||
- (cd $HOME/.local/bin && wget https://zalora-public.s3.amazonaws.com/tinc && chmod +x tinc)
|
|
||||||
|
|
||||||
script:
|
|
||||||
- if [ "$STACK_YAML" = "stack-ghc-8.2.1.yaml" ]; then HOMEMODULES="--ghc-options=-Wno-missing-home-modules"; fi
|
|
||||||
- if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then ./scripts/ci-cron.sh ; else stack test $HOMEMODULES --ghc-options=-Werror --no-terminal ; fi
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- $HOME/.tinc/cache
|
- $HOME/.cabal/packages
|
||||||
- $HOME/.stack
|
- $HOME/.cabal/store
|
||||||
|
|
||||||
|
before_cache:
|
||||||
|
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
|
||||||
|
# remove files that are regenerated by 'cabal update'
|
||||||
|
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*
|
||||||
|
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json
|
||||||
|
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache
|
||||||
|
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar
|
||||||
|
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- compiler: "ghc-7.8.4"
|
||||||
|
# env: TEST=--disable-tests BENCH=--disable-benchmarks
|
||||||
|
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.8.4], sources: [hvr-ghc]}}
|
||||||
|
- compiler: "ghc-7.10.3"
|
||||||
|
# env: TEST=--disable-tests BENCH=--disable-benchmarks
|
||||||
|
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-7.10.3], sources: [hvr-ghc]}}
|
||||||
|
- compiler: "ghc-8.0.2"
|
||||||
|
# env: TEST=--disable-tests BENCH=--disable-benchmarks
|
||||||
|
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}
|
||||||
|
- compiler: "ghc-8.2.1"
|
||||||
|
# env: TEST=--disable-tests BENCH=--disable-benchmarks
|
||||||
|
addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.1], sources: [hvr-ghc]}}
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- HC=${CC}
|
||||||
|
- HCPKG=${HC/ghc/ghc-pkg}
|
||||||
|
- unset CC
|
||||||
|
- PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$PATH
|
||||||
|
|
||||||
|
install:
|
||||||
|
- cabal --version
|
||||||
|
- echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"
|
||||||
|
- BENCH=${BENCH---enable-benchmarks}
|
||||||
|
- TEST=${TEST---enable-tests}
|
||||||
|
- HADDOCK=${HADDOCK-true}
|
||||||
|
- INSTALLED=${INSTALLED-true}
|
||||||
|
- travis_retry cabal update -v
|
||||||
|
- sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
|
||||||
|
- rm -fv cabal.project.local
|
||||||
|
- if [ -f "servant/configure.ac" ]; then
|
||||||
|
(cd "servant"; autoreconf -i);
|
||||||
|
fi
|
||||||
|
- if [ -f "servant-client/configure.ac" ]; then
|
||||||
|
(cd "servant-client"; autoreconf -i);
|
||||||
|
fi
|
||||||
|
- if [ -f "servant-client-core/configure.ac" ]; then
|
||||||
|
(cd "servant-client-core"; autoreconf -i);
|
||||||
|
fi
|
||||||
|
- if [ -f "servant-docs/configure.ac" ]; then
|
||||||
|
(cd "servant-docs"; autoreconf -i);
|
||||||
|
fi
|
||||||
|
- if [ -f "servant-foreign/configure.ac" ]; then
|
||||||
|
(cd "servant-foreign"; autoreconf -i);
|
||||||
|
fi
|
||||||
|
- if [ -f "servant-server/configure.ac" ]; then
|
||||||
|
(cd "servant-server"; autoreconf -i);
|
||||||
|
fi
|
||||||
|
- if [ -f "doc/tutorial/configure.ac" ]; then
|
||||||
|
(cd "doc/tutorial"; autoreconf -i);
|
||||||
|
fi
|
||||||
|
- rm -f cabal.project.freeze
|
||||||
|
- cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 servant-server servant-client
|
||||||
|
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2 servant-server servant-client
|
||||||
|
- rm -rf "servant"/.ghc.environment.* "servant-client"/.ghc.environment.* "servant-client-core"/.ghc.environment.* "servant-docs"/.ghc.environment.* "servant-foreign"/.ghc.environment.* "servant-server"/.ghc.environment.* "doc/tutorial"/.ghc.environment.* "servant"/dist "servant-client"/dist "servant-client-core"/dist "servant-docs"/dist "servant-foreign"/dist "servant-server"/dist "doc/tutorial"/dist
|
||||||
|
- DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)
|
||||||
|
|
||||||
|
# Here starts the actual work to be performed for the package under test;
|
||||||
|
# any command which exits with a non-zero exit code causes the build to fail.
|
||||||
|
script:
|
||||||
|
# test that source-distributions can be generated
|
||||||
|
- echo Packaging... && echo -en 'travis_fold:start:sdist\\r'
|
||||||
|
- (cd "servant"; cabal sdist)
|
||||||
|
- (cd "servant-client"; cabal sdist)
|
||||||
|
- (cd "servant-client-core"; cabal sdist)
|
||||||
|
- (cd "servant-docs"; cabal sdist)
|
||||||
|
- (cd "servant-foreign"; cabal sdist)
|
||||||
|
- (cd "servant-server"; cabal sdist)
|
||||||
|
- (cd "doc/tutorial"; cabal sdist)
|
||||||
|
- echo -en 'travis_fold:end:sdist\\r'
|
||||||
|
- echo Unpacking... && echo -en 'travis_fold:start:unpack\\r'
|
||||||
|
- mv "servant"/dist/servant-*.tar.gz "servant-client"/dist/servant-client-*.tar.gz "servant-client-core"/dist/servant-client-core-*.tar.gz "servant-docs"/dist/servant-docs-*.tar.gz "servant-foreign"/dist/servant-foreign-*.tar.gz "servant-server"/dist/servant-server-*.tar.gz "doc/tutorial"/dist/tutorial-*.tar.gz ${DISTDIR}/
|
||||||
|
- cd ${DISTDIR}
|
||||||
|
- find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;
|
||||||
|
- "printf 'packages: servant-*/*.cabal servant-client-*/*.cabal servant-client-core-*/*.cabal servant-docs-*/*.cabal servant-foreign-*/*.cabal servant-server-*/*.cabal tutorial-*/*.cabal\n' > cabal.project"
|
||||||
|
- echo -en 'travis_fold:end:unpack\\r'
|
||||||
|
- echo Building... && echo -en 'travis_fold:start:build\\r'
|
||||||
|
# this builds all libraries and executables (without tests/benchmarks)
|
||||||
|
- cabal new-build -w ${HC} --disable-tests --disable-benchmarks all
|
||||||
|
- echo -en 'travis_fold:end:build\\r'
|
||||||
|
|
||||||
|
- echo Building with installed constraints for package in global-db... && echo -en 'travis_fold:start:build-installed\\r'
|
||||||
|
# Build with installed constraints for packages in global-db
|
||||||
|
- if $INSTALLED; then
|
||||||
|
echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks $(${HCPKG} list --global --simple-output --names-only | sed 's/\([a-zA-Z0-9-]\{1,\}\) */--constraint="\1 installed" /g') all | sh;
|
||||||
|
else echo "Not building with installed constraints"; fi
|
||||||
|
- echo -en 'travis_fold:end:build-installed\\r'
|
||||||
|
|
||||||
|
- echo Building with tests and benchmarks... && echo -en 'travis_fold:start:build-everything\\r'
|
||||||
|
# build & run tests, build benchmarks
|
||||||
|
- cabal new-build -w ${HC} ${TEST} ${BENCH} all
|
||||||
|
- echo -en 'travis_fold:end:build-everything\\r'
|
||||||
|
- echo Testing... && echo -en 'travis_fold:start:test\\r'
|
||||||
|
- if [ "x$TEST" = "x--enable-tests" ]; then cabal new-test -w ${HC} ${TEST} all; fi
|
||||||
|
- echo -en 'travis_fold:end:test\\r'
|
||||||
|
|
||||||
|
- echo Haddock... && echo -en 'travis_fold:start:haddock\\r'
|
||||||
|
# haddock
|
||||||
|
- rm -rf ./dist-newstyle
|
||||||
|
- if $HADDOCK; then cabal new-haddock -w ${HC} --disable-tests --disable-benchmarks all; else echo "Skipping haddock generation";fi
|
||||||
|
|
||||||
|
- echo -en 'travis_fold:end:haddock\\r'
|
||||||
|
# REGENDATA ["-f","-o",".travis.yml","cabal.project"]
|
||||||
|
# EOF
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
packages:
|
packages: servant/
|
||||||
servant/
|
|
||||||
servant-client/
|
servant-client/
|
||||||
servant-client-core/
|
servant-client-core/
|
||||||
servant-docs/
|
servant-docs/
|
||||||
|
|
|
@ -8,6 +8,14 @@ author: Servant Contributors
|
||||||
maintainer: haskell-servant-maintainers@googlegroups.com
|
maintainer: haskell-servant-maintainers@googlegroups.com
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
cabal-version: >=1.10
|
cabal-version: >=1.10
|
||||||
|
tested-with:
|
||||||
|
GHC==7.8.4
|
||||||
|
GHC==7.10.3
|
||||||
|
GHC==8.0.2
|
||||||
|
GHC==8.2.1
|
||||||
|
extra-source-files:
|
||||||
|
static/index.html
|
||||||
|
static/ui.js
|
||||||
|
|
||||||
library
|
library
|
||||||
exposed-modules: ApiType
|
exposed-modules: ApiType
|
||||||
|
@ -38,7 +46,8 @@ library
|
||||||
, string-conversions
|
, string-conversions
|
||||||
, bytestring
|
, bytestring
|
||||||
, attoparsec
|
, attoparsec
|
||||||
, mtl
|
, mtl >=2.1 && <2.3
|
||||||
|
, mtl-compat
|
||||||
, random
|
, random
|
||||||
, js-jquery
|
, js-jquery
|
||||||
, wai
|
, wai
|
||||||
|
@ -57,6 +66,8 @@ test-suite spec
|
||||||
hs-source-dirs: test
|
hs-source-dirs: test
|
||||||
main-is: Spec.hs
|
main-is: Spec.hs
|
||||||
other-modules: JavascriptSpec
|
other-modules: JavascriptSpec
|
||||||
|
build-tool-depends:
|
||||||
|
hspec-discover:hspec-discover
|
||||||
build-depends: base == 4.*
|
build-depends: base == 4.*
|
||||||
, tutorial
|
, tutorial
|
||||||
, hspec
|
, hspec
|
||||||
|
|
|
@ -18,6 +18,12 @@ extra-source-files:
|
||||||
include/*.h
|
include/*.h
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
README.md
|
README.md
|
||||||
|
tested-with:
|
||||||
|
GHC==7.8.4
|
||||||
|
GHC==7.10.3
|
||||||
|
GHC==8.0.2
|
||||||
|
GHC==8.2.1
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
location: http://github.com/haskell-servant/servant.git
|
location: http://github.com/haskell-servant/servant.git
|
||||||
|
@ -43,7 +49,7 @@ library
|
||||||
, generics-sop >= 0.1.0.0 && < 0.4
|
, generics-sop >= 0.1.0.0 && < 0.4
|
||||||
, http-api-data >= 0.3.6 && < 0.4
|
, http-api-data >= 0.3.6 && < 0.4
|
||||||
, http-media >= 0.6.2 && < 0.8
|
, http-media >= 0.6.2 && < 0.8
|
||||||
, http-types >= 0.8.6 && < 0.10
|
, http-types >= 0.8.6 && < 0.11
|
||||||
, mtl >= 2.1 && < 2.3
|
, mtl >= 2.1 && < 2.3
|
||||||
, network-uri >= 2.6 && < 2.7
|
, network-uri >= 2.6 && < 2.7
|
||||||
, safe >= 0.3.9 && < 0.4
|
, safe >= 0.3.9 && < 0.4
|
||||||
|
@ -70,5 +76,7 @@ test-suite spec
|
||||||
, servant-client-core
|
, servant-client-core
|
||||||
, hspec == 2.*
|
, hspec == 2.*
|
||||||
, QuickCheck >= 2.7 && < 2.11
|
, QuickCheck >= 2.7 && < 2.11
|
||||||
|
build-tool-depends:
|
||||||
|
hspec-discover:hspec-discover
|
||||||
other-modules:
|
other-modules:
|
||||||
Servant.Client.Core.Internal.BaseUrlSpec
|
Servant.Client.Core.Internal.BaseUrlSpec
|
||||||
|
|
|
@ -16,7 +16,11 @@ copyright: 2014-2016 Zalora South East Asia Pte Ltd, 2016-2017 Servant
|
||||||
category: Servant, Web
|
category: Servant, Web
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
cabal-version: >=1.10
|
cabal-version: >=1.10
|
||||||
tested-with: GHC >= 7.8
|
tested-with:
|
||||||
|
GHC==7.8.4
|
||||||
|
GHC==7.10.3
|
||||||
|
GHC==8.0.2
|
||||||
|
GHC==8.2.1
|
||||||
homepage: http://haskell-servant.readthedocs.org/
|
homepage: http://haskell-servant.readthedocs.org/
|
||||||
Bug-reports: http://github.com/haskell-servant/servant/issues
|
Bug-reports: http://github.com/haskell-servant/servant/issues
|
||||||
extra-source-files:
|
extra-source-files:
|
||||||
|
@ -41,7 +45,7 @@ library
|
||||||
, http-client >= 0.4.30 && < 0.6
|
, http-client >= 0.4.30 && < 0.6
|
||||||
, http-client-tls >= 0.2.2 && < 0.4
|
, http-client-tls >= 0.2.2 && < 0.4
|
||||||
, http-media >= 0.6.2 && < 0.8
|
, http-media >= 0.6.2 && < 0.8
|
||||||
, http-types >= 0.8.6 && < 0.10
|
, http-types >= 0.8.6 && < 0.11
|
||||||
, exceptions >= 0.8 && < 0.9
|
, exceptions >= 0.8 && < 0.9
|
||||||
, monad-control >= 1.0.0.4 && < 1.1
|
, monad-control >= 1.0.0.4 && < 1.1
|
||||||
, mtl >= 2.1 && < 2.3
|
, mtl >= 2.1 && < 2.3
|
||||||
|
@ -64,6 +68,8 @@ test-suite spec
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
hs-source-dirs: test
|
hs-source-dirs: test
|
||||||
main-is: Spec.hs
|
main-is: Spec.hs
|
||||||
|
build-tool-depends:
|
||||||
|
hspec-discover:hspec-discover
|
||||||
other-modules:
|
other-modules:
|
||||||
Servant.ClientSpec
|
Servant.ClientSpec
|
||||||
Servant.StreamSpec
|
Servant.StreamSpec
|
||||||
|
|
|
@ -15,7 +15,11 @@ copyright: 2014-2016 Zalora South East Asia Pte Ltd, Servant Contribut
|
||||||
category: Servant, Web
|
category: Servant, Web
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
cabal-version: >=1.10
|
cabal-version: >=1.10
|
||||||
tested-with: GHC >= 7.8
|
tested-with:
|
||||||
|
GHC==7.8.4
|
||||||
|
GHC==7.10.3
|
||||||
|
GHC==8.0.2
|
||||||
|
GHC==8.2.1
|
||||||
homepage: http://haskell-servant.readthedocs.org/
|
homepage: http://haskell-servant.readthedocs.org/
|
||||||
Bug-reports: http://github.com/haskell-servant/servant/issues
|
Bug-reports: http://github.com/haskell-servant/servant/issues
|
||||||
extra-source-files:
|
extra-source-files:
|
||||||
|
@ -75,6 +79,8 @@ test-suite spec
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
main-is: Spec.hs
|
main-is: Spec.hs
|
||||||
other-modules: Servant.DocsSpec
|
other-modules: Servant.DocsSpec
|
||||||
|
build-tool-depends:
|
||||||
|
hspec-discover:hspec-discover
|
||||||
hs-source-dirs: test
|
hs-source-dirs: test
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
build-depends:
|
build-depends:
|
||||||
|
|
|
@ -22,6 +22,12 @@ extra-source-files:
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
README.md
|
README.md
|
||||||
bug-reports: http://github.com/haskell-servant/servant/issues
|
bug-reports: http://github.com/haskell-servant/servant/issues
|
||||||
|
tested-with:
|
||||||
|
GHC==7.8.4
|
||||||
|
GHC==7.10.3
|
||||||
|
GHC==8.0.2
|
||||||
|
GHC==8.2.1
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
location: http://github.com/haskell-servant/servant.git
|
location: http://github.com/haskell-servant/servant.git
|
||||||
|
@ -65,6 +71,8 @@ test-suite spec
|
||||||
include-dirs: include
|
include-dirs: include
|
||||||
main-is: Spec.hs
|
main-is: Spec.hs
|
||||||
other-modules: Servant.ForeignSpec
|
other-modules: Servant.ForeignSpec
|
||||||
|
build-tool-depends:
|
||||||
|
hspec-discover:hspec-discover
|
||||||
build-depends: base
|
build-depends: base
|
||||||
, hspec >= 2.1.8
|
, hspec >= 2.1.8
|
||||||
, servant
|
, servant
|
||||||
|
|
|
@ -21,7 +21,11 @@ copyright: 2014-2016 Zalora South East Asia Pte Ltd, Servant Contribut
|
||||||
category: Servant, Web
|
category: Servant, Web
|
||||||
build-type: Custom
|
build-type: Custom
|
||||||
cabal-version: >=1.10
|
cabal-version: >=1.10
|
||||||
tested-with: GHC >= 7.8
|
tested-with:
|
||||||
|
GHC==7.8.4
|
||||||
|
GHC==7.10.3
|
||||||
|
GHC==8.0.2
|
||||||
|
GHC==8.2.1
|
||||||
extra-source-files:
|
extra-source-files:
|
||||||
include/*.h
|
include/*.h
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
|
@ -60,7 +64,6 @@ library
|
||||||
, containers >= 0.5 && < 0.6
|
, containers >= 0.5 && < 0.6
|
||||||
, exceptions >= 0.8 && < 0.9
|
, exceptions >= 0.8 && < 0.9
|
||||||
, http-api-data >= 0.3 && < 0.4
|
, http-api-data >= 0.3 && < 0.4
|
||||||
, http-media >= 0.4 && < 0.8
|
|
||||||
, http-types >= 0.8 && < 0.10
|
, http-types >= 0.8 && < 0.10
|
||||||
, network-uri >= 2.6 && < 2.7
|
, network-uri >= 2.6 && < 2.7
|
||||||
, monad-control >= 1.0.0.4 && < 1.1
|
, monad-control >= 1.0.0.4 && < 1.1
|
||||||
|
@ -121,6 +124,8 @@ test-suite spec
|
||||||
Servant.Server.UsingContextSpec.TestCombinators
|
Servant.Server.UsingContextSpec.TestCombinators
|
||||||
Servant.ServerSpec
|
Servant.ServerSpec
|
||||||
Servant.Utils.StaticFilesSpec
|
Servant.Utils.StaticFilesSpec
|
||||||
|
build-tool-depends:
|
||||||
|
hspec-discover:hspec-discover
|
||||||
build-depends:
|
build-depends:
|
||||||
base == 4.*
|
base == 4.*
|
||||||
, base-compat
|
, base-compat
|
||||||
|
|
|
@ -46,7 +46,7 @@ import GHC.TypeLits (KnownNat, KnownSymbol, natVal,
|
||||||
import Network.HTTP.Types hiding (Header, ResponseHeaders)
|
import Network.HTTP.Types hiding (Header, ResponseHeaders)
|
||||||
import qualified Network.HTTP.Media as NHM
|
import qualified Network.HTTP.Media as NHM
|
||||||
import Network.Socket (SockAddr)
|
import Network.Socket (SockAddr)
|
||||||
import Network.Wai (Application, Request, Response,
|
import Network.Wai (Application, Request,
|
||||||
httpVersion, isSecure,
|
httpVersion, isSecure,
|
||||||
lazyRequestBody,
|
lazyRequestBody,
|
||||||
rawQueryString, remoteHost,
|
rawQueryString, remoteHost,
|
||||||
|
@ -208,16 +208,6 @@ allowedMethodHead method request = method == methodGet && requestMethod request
|
||||||
allowedMethod :: Method -> Request -> Bool
|
allowedMethod :: Method -> Request -> Bool
|
||||||
allowedMethod method request = allowedMethodHead method request || requestMethod request == method
|
allowedMethod method request = allowedMethodHead method request || requestMethod request == method
|
||||||
|
|
||||||
processMethodRouter :: Maybe (BL.ByteString, BL.ByteString) -> Status -> Method
|
|
||||||
-> Maybe [(HeaderName, B.ByteString)]
|
|
||||||
-> Request -> RouteResult Response
|
|
||||||
processMethodRouter handleA status method headers request = case handleA of
|
|
||||||
Nothing -> FailFatal err406 -- this should not happen (checked before), so we make it fatal if it does
|
|
||||||
Just (contentT, body) -> Route $ responseLBS status hdrs bdy
|
|
||||||
where
|
|
||||||
bdy = if allowedMethodHead method request then "" else body
|
|
||||||
hdrs = (hContentType, cs contentT) : (fromMaybe [] headers)
|
|
||||||
|
|
||||||
methodCheck :: Method -> Request -> DelayedIO ()
|
methodCheck :: Method -> Request -> DelayedIO ()
|
||||||
methodCheck method request
|
methodCheck method request
|
||||||
| allowedMethod method request = return ()
|
| allowedMethod method request = return ()
|
||||||
|
@ -236,33 +226,23 @@ acceptCheck proxy accH
|
||||||
| otherwise = delayedFail err406
|
| otherwise = delayedFail err406
|
||||||
|
|
||||||
methodRouter :: (AllCTRender ctypes a)
|
methodRouter :: (AllCTRender ctypes a)
|
||||||
=> Method -> Proxy ctypes -> Status
|
=> (b -> ([(HeaderName, B.ByteString)], a))
|
||||||
-> Delayed env (Handler a)
|
-> Method -> Proxy ctypes -> Status
|
||||||
|
-> Delayed env (Handler b)
|
||||||
-> Router env
|
-> Router env
|
||||||
methodRouter method proxy status action = leafRouter route'
|
methodRouter splitHeaders method proxy status action = leafRouter route'
|
||||||
where
|
where
|
||||||
route' env request respond =
|
route' env request respond =
|
||||||
let accH = fromMaybe ct_wildcard $ lookup hAccept $ requestHeaders request
|
let accH = fromMaybe ct_wildcard $ lookup hAccept $ requestHeaders request
|
||||||
in runAction (action `addMethodCheck` methodCheck method request
|
in runAction (action `addMethodCheck` methodCheck method request
|
||||||
`addAcceptCheck` acceptCheck proxy accH
|
`addAcceptCheck` acceptCheck proxy accH
|
||||||
) env request respond $ \ output -> do
|
) env request respond $ \ output -> do
|
||||||
let handleA = handleAcceptH proxy (AcceptHeader accH) output
|
let (headers, b) = splitHeaders output
|
||||||
processMethodRouter handleA status method Nothing request
|
case handleAcceptH proxy (AcceptHeader accH) b of
|
||||||
|
Nothing -> FailFatal err406 -- this should not happen (checked before), so we make it fatal if it does
|
||||||
methodRouterHeaders :: (GetHeaders (Headers h v), AllCTRender ctypes v)
|
Just (contentT, body) ->
|
||||||
=> Method -> Proxy ctypes -> Status
|
let bdy = if allowedMethodHead method request then "" else body
|
||||||
-> Delayed env (Handler (Headers h v))
|
in Route $ responseLBS status ((hContentType, cs contentT) : headers) bdy
|
||||||
-> Router env
|
|
||||||
methodRouterHeaders method proxy status action = leafRouter route'
|
|
||||||
where
|
|
||||||
route' env request respond =
|
|
||||||
let accH = fromMaybe ct_wildcard $ lookup hAccept $ requestHeaders request
|
|
||||||
in runAction (action `addMethodCheck` methodCheck method request
|
|
||||||
`addAcceptCheck` acceptCheck proxy accH
|
|
||||||
) env request respond $ \ output -> do
|
|
||||||
let headers = getHeaders output
|
|
||||||
handleA = handleAcceptH proxy (AcceptHeader accH) (getResponse output)
|
|
||||||
processMethodRouter handleA status method (Just headers) request
|
|
||||||
|
|
||||||
instance OVERLAPPABLE_
|
instance OVERLAPPABLE_
|
||||||
( AllCTRender ctypes a, ReflectMethod method, KnownNat status
|
( AllCTRender ctypes a, ReflectMethod method, KnownNat status
|
||||||
|
@ -271,7 +251,7 @@ instance OVERLAPPABLE_
|
||||||
type ServerT (Verb method status ctypes a) m = m a
|
type ServerT (Verb method status ctypes a) m = m a
|
||||||
hoistServerWithContext _ _ nt s = nt s
|
hoistServerWithContext _ _ nt s = nt s
|
||||||
|
|
||||||
route Proxy _ = methodRouter method (Proxy :: Proxy ctypes) status
|
route Proxy _ = methodRouter ([],) method (Proxy :: Proxy ctypes) status
|
||||||
where method = reflectMethod (Proxy :: Proxy method)
|
where method = reflectMethod (Proxy :: Proxy method)
|
||||||
status = toEnum . fromInteger $ natVal (Proxy :: Proxy status)
|
status = toEnum . fromInteger $ natVal (Proxy :: Proxy status)
|
||||||
|
|
||||||
|
@ -283,7 +263,7 @@ instance OVERLAPPING_
|
||||||
type ServerT (Verb method status ctypes (Headers h a)) m = m (Headers h a)
|
type ServerT (Verb method status ctypes (Headers h a)) m = m (Headers h a)
|
||||||
hoistServerWithContext _ _ nt s = nt s
|
hoistServerWithContext _ _ nt s = nt s
|
||||||
|
|
||||||
route Proxy _ = methodRouterHeaders method (Proxy :: Proxy ctypes) status
|
route Proxy _ = methodRouter (\x -> (getHeaders x, getResponse x)) method (Proxy :: Proxy ctypes) status
|
||||||
where method = reflectMethod (Proxy :: Proxy method)
|
where method = reflectMethod (Proxy :: Proxy method)
|
||||||
status = toEnum . fromInteger $ natVal (Proxy :: Proxy status)
|
status = toEnum . fromInteger $ natVal (Proxy :: Proxy status)
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,11 @@ import Network.HTTP.Types (Status (..), hAccept, hContentType,
|
||||||
methodDelete, methodGet,
|
methodDelete, methodGet,
|
||||||
methodHead, methodPatch,
|
methodHead, methodPatch,
|
||||||
methodPost, methodPut, ok200,
|
methodPost, methodPut, ok200,
|
||||||
|
#if MIN_VERSION_http_types(0,10,0)
|
||||||
|
imATeapot418,
|
||||||
|
#else
|
||||||
imATeaPot418,
|
imATeaPot418,
|
||||||
|
#endif
|
||||||
parseQuery)
|
parseQuery)
|
||||||
import Network.Wai (Application, Request, requestHeaders, pathInfo,
|
import Network.Wai (Application, Request, requestHeaders, pathInfo,
|
||||||
queryString, rawQueryString,
|
queryString, rawQueryString,
|
||||||
|
@ -70,6 +74,11 @@ import Servant.Server.Experimental.Auth
|
||||||
import Servant.Server.Internal.Context
|
import Servant.Server.Internal.Context
|
||||||
(NamedContext(..))
|
(NamedContext(..))
|
||||||
|
|
||||||
|
#if !MIN_VERSION_http_types(0,10,0)
|
||||||
|
imATeapot418 :: Status
|
||||||
|
imATeapot418 = imATeaPot418
|
||||||
|
#endif
|
||||||
|
|
||||||
-- * comprehensive api test
|
-- * comprehensive api test
|
||||||
|
|
||||||
-- This declaration simply checks that all instances are in place.
|
-- This declaration simply checks that all instances are in place.
|
||||||
|
@ -662,7 +671,7 @@ basicAuthApi = Proxy
|
||||||
basicAuthServer :: Server BasicAuthAPI
|
basicAuthServer :: Server BasicAuthAPI
|
||||||
basicAuthServer =
|
basicAuthServer =
|
||||||
const (return jerry) :<|>
|
const (return jerry) :<|>
|
||||||
(Tagged $ \ _ respond -> respond $ responseLBS imATeaPot418 [] "")
|
(Tagged $ \ _ respond -> respond $ responseLBS imATeapot418 [] "")
|
||||||
|
|
||||||
basicAuthContext :: Context '[ BasicAuthCheck () ]
|
basicAuthContext :: Context '[ BasicAuthCheck () ]
|
||||||
basicAuthContext =
|
basicAuthContext =
|
||||||
|
@ -707,7 +716,7 @@ genAuthApi = Proxy
|
||||||
|
|
||||||
genAuthServer :: Server GenAuthAPI
|
genAuthServer :: Server GenAuthAPI
|
||||||
genAuthServer = const (return tweety)
|
genAuthServer = const (return tweety)
|
||||||
:<|> (Tagged $ \ _ respond -> respond $ responseLBS imATeaPot418 [] "")
|
:<|> (Tagged $ \ _ respond -> respond $ responseLBS imATeapot418 [] "")
|
||||||
|
|
||||||
type instance AuthServerData (AuthProtect "auth") = ()
|
type instance AuthServerData (AuthProtect "auth") = ()
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,11 @@ copyright: 2014-2016 Zalora South East Asia Pte Ltd, Servant Contribut
|
||||||
category: Servant, Web
|
category: Servant, Web
|
||||||
build-type: Custom
|
build-type: Custom
|
||||||
cabal-version: >=1.10
|
cabal-version: >=1.10
|
||||||
tested-with: GHC >= 7.8
|
tested-with:
|
||||||
|
GHC==7.8.4
|
||||||
|
GHC==7.10.3
|
||||||
|
GHC==8.0.2
|
||||||
|
GHC==8.2.1
|
||||||
extra-source-files:
|
extra-source-files:
|
||||||
include/*.h
|
include/*.h
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
|
@ -67,7 +71,7 @@ library
|
||||||
, case-insensitive >= 1.2 && < 1.3
|
, case-insensitive >= 1.2 && < 1.3
|
||||||
, http-api-data >= 0.3 && < 0.4
|
, http-api-data >= 0.3 && < 0.4
|
||||||
, http-media >= 0.4 && < 0.8
|
, http-media >= 0.4 && < 0.8
|
||||||
, http-types >= 0.8 && < 0.10
|
, http-types >= 0.8 && < 0.11
|
||||||
, natural-transformation >= 0.4 && < 0.5
|
, natural-transformation >= 0.4 && < 0.5
|
||||||
, mtl >= 2.0 && < 2.3
|
, mtl >= 2.0 && < 2.3
|
||||||
, mmorph >= 1 && < 1.2
|
, mmorph >= 1 && < 1.2
|
||||||
|
@ -119,6 +123,8 @@ test-suite spec
|
||||||
Servant.API.ResponseHeadersSpec
|
Servant.API.ResponseHeadersSpec
|
||||||
Servant.Utils.LinksSpec
|
Servant.Utils.LinksSpec
|
||||||
Servant.Utils.EnterSpec
|
Servant.Utils.EnterSpec
|
||||||
|
build-tool-depends:
|
||||||
|
hspec-discover:hspec-discover
|
||||||
build-depends:
|
build-depends:
|
||||||
base == 4.*
|
base == 4.*
|
||||||
, base-compat
|
, base-compat
|
||||||
|
|
|
@ -10,7 +10,8 @@ packages:
|
||||||
extra-deps:
|
extra-deps:
|
||||||
- aeson-1.2.0.0
|
- aeson-1.2.0.0
|
||||||
- attoparsec-iso8601-1.0.0.0
|
- attoparsec-iso8601-1.0.0.0
|
||||||
- http-media-0.7.0
|
|
||||||
- cabal-doctest-1.0.2
|
- cabal-doctest-1.0.2
|
||||||
- http-api-data-0.3.7
|
- http-api-data-0.3.7
|
||||||
|
- http-media-0.7.0
|
||||||
|
- http-types-0.10
|
||||||
- servant-js-0.9.3
|
- servant-js-0.9.3
|
||||||
|
|
Loading…
Reference in a new issue