Skip to content

Commit

Permalink
narrow down gap for canister http_requests between ic-ref(-test) and …
Browse files Browse the repository at this point in the history
…Interface Spec (#100)

Co-authored-by: Martin Raszyk <[email protected]>
  • Loading branch information
mraszyk and mraszyk authored Nov 29, 2022
1 parent 2cd76ef commit 3c2eb69
Show file tree
Hide file tree
Showing 31 changed files with 1,321 additions and 210 deletions.
12 changes: 12 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ source-repository-package
type: git
location: https://github.com/nomeata/haskell-candid
tag: bff9fcf23e6c60bb8cd7c1ac1ae3d39f6fc05ec0

source-repository-package
type: git
location: https://github.com/mraszyk/http-client
tag: 367bca36dfe9142e7bbea922574387497f205823
subdir: http-client

source-repository-package
type: git
location: https://github.com/mraszyk/http-client
tag: 367bca36dfe9142e7bbea922574387497f205823
subdir: http-client-tls
3 changes: 2 additions & 1 deletion cabal.project.freeze

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 25 additions & 9 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,23 @@ in
let
httpbin =
let
python = nixpkgs.python3.withPackages
(ps: [ ps.httpbin ps.gunicorn ps.gevent ]);
in "${python}/bin/gunicorn -b 127.0.0.1:8003 httpbin:app -k gevent";
my-python-package = ps: ps.callPackage ./httpbin.nix {};
python-with-my-packages = nixpkgs.python3.withPackages(ps: with ps; [
(my-python-package ps) ps.gunicorn ps.gevent
]);
openssl = nixpkgs.openssl;
in "${openssl}/bin/openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -nodes -subj '/C=CH/ST=Zurich/L=Zurich/O=DFINITY/CN=127.0.0.1';
echo \"import gunicorn.http.wsgi
from six import wraps
def wrap_default_headers(func):
@wraps(func)
def default_headers(*args, **kwargs):
return [header for header in func(*args, **kwargs) if not header.startswith('Server: ') and not header.startswith('Date: ')]
return default_headers
gunicorn.http.wsgi.Response.default_headers = wrap_default_headers(gunicorn.http.wsgi.Response.default_headers)\" > conf.py;
${python-with-my-packages}/bin/gunicorn -b 127.0.0.1:8003 --limit-request-line 0 --limit-request-field_size 0 --certfile cert.pem --keyfile key.pem httpbin:app -k gevent -c conf.py";
in

rec {
Expand All @@ -170,14 +184,15 @@ rec {
pids="$(jobs -p)"
kill $pids
}
ic-ref --pick-port --write-port-to port &
${httpbin} &
sleep 1
ic-ref --pick-port --write-port-to port --cert-path "cert.pem" &
trap kill_jobs EXIT PIPE
sleep 1
test -e port
mkdir -p $out
${httpbin} &
sleep 1
LANG=C.UTF8 ic-ref-test --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "http://127.0.0.1:8003" --html $out/report.html
LANG=C.UTF8 ic-ref-test --ecid 5v3p4-iyaaa-aaaaa-qaaaa-cai --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "127.0.0.1:8003" --html $out/report.html
pids="$(jobs -p)"
kill -INT $pids
trap - EXIT PIPE
Expand All @@ -195,13 +210,14 @@ rec {
pids="$(jobs -p)"
kill $pids
}
ic-ref --pick-port --write-port-to port &
${httpbin} &
sleep 1
ic-ref --pick-port --write-port-to port --cert-path "cert.pem" &
trap kill_jobs EXIT PIPE
sleep 1
test -e port
${httpbin} &
sleep 1
LANG=C.UTF8 ic-ref-test --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "http://127.0.0.1:8003"
LANG=C.UTF8 ic-ref-test --ecid 5v3p4-iyaaa-aaaaa-qaaaa-cai --endpoint "http://127.0.0.1:$(cat port)/" --httpbin "127.0.0.1:8003"
pids="$(jobs -p)"
kill -INT $pids
trap - EXIT PIPE
Expand Down
78 changes: 78 additions & 0 deletions httpbin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{ lib
, brotlipy
, buildPythonPackage
, decorator
, fetchpatch
, fetchFromGitHub
, flask
, flask-limiter
, itsdangerous
, markupsafe
, raven
, six
, pytestCheckHook
}:

buildPythonPackage rec {
pname = "httpbin";
version = "0.7.0";
format = "setuptools";

src = fetchFromGitHub {
name = "httpbin";
owner = "mraszyk";
repo = "httpbin";
rev = "c6f2830f366635ed0afef1e6f5d5c48428950d36";
sha256 = "sha256-S4dAuV925YM+KLA0u/eoZkICWl5ExvfKD2+34rbpm7Q=";
};

patches = [
(fetchpatch {
# Replaces BaseResponse class with Response class for Werkezug 2.1.0 compatibility
# https://github.com/postmanlabs/httpbin/pull/674
url = "https://github.com/postmanlabs/httpbin/commit/5cc81ce87a3c447a127e4a1a707faf9f3b1c9b6b.patch";
hash = "sha256-SbEWjiqayMFYrbgAPZtSsXqSyCDUz3z127XgcKOcrkE=";
})
];

propagatedBuildInputs = [
brotlipy
flask
flask-limiter
markupsafe
decorator
itsdangerous
raven
six
];

checkInputs = [
pytestCheckHook
];

pytestFlagsArray = [
"test_httpbin.py"
];

disabledTests = [
# Tests seems to be outdated
"test_anything"
"test_get"
"test_redirect_n_equals_to_1"
"test_redirect_n_higher_than_1"
"test_redirect_to_post"
"test_relative_redirect_n_equals_to_1"
"test_relative_redirect_n_higher_than_1"
];

pythonImportsCheck = [
"httpbin"
];

meta = with lib; {
description = "HTTP Request and Response Service";
homepage = "https://github.com/kennethreitz/httpbin";
license = licenses.mit;
maintainers = with maintainers; [ ];
};
}
Loading

0 comments on commit 3c2eb69

Please sign in to comment.