Conversation
…ples Agent-Logs-Url: https://github.com/zotonic/cowmachine/sessions/fc255aa1-5e23-40df-a585-fbd4e25584c1 Co-authored-by: mworrell <38268+mworrell@users.noreply.github.com>
…ow diagram, fix examples Agent-Logs-Url: https://github.com/zotonic/cowmachine/sessions/fc255aa1-5e23-40df-a585-fbd4e25584c1 Co-authored-by: mworrell <38268+mworrell@users.noreply.github.com>
|
@copilot Check the tests - some are failing. |
Agent-Logs-Url: https://github.com/zotonic/cowmachine/sessions/a65afe50-8a2f-467a-b821-af7a64079cda Co-authored-by: mworrell <38268+mworrell@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR strengthens Cowmachine’s correctness and usability by adding end-to-end coverage of the HTTP decision flow, documenting how Cowmachine diverges from Webmachine, correcting the decision-flow diagram, and making the shipped examples consistently use Cowmachine middleware.
Changes:
- Added an EUnit-based e2e test module that boots Cowboy listeners and exercises many decision-flow branches via HTTP requests.
- Added/updated documentation: a Cowmachine-specific decision-flow
.dotdiagram and a Webmachine→Cowmachine callback-differences reference. - Updated multiple examples to consistently run through
#{middlewares => [controller, cowmachine]}and removed legacy/random Cowboy-direct fallback paths; fixed a controller example callback.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/cowmachine_e2e_tests.erl | New e2e test module covering many decision-flow branches via real HTTP requests. |
| rebar3.crashdump | Adds a crash artifact file (should not be committed). |
| docs/http-headers-status-cowmachine.dot | Adds corrected Cowmachine-specific HTTP decision-flow diagram. |
| docs/differences-webmachine-cowmachine.md | Adds reference doc enumerating callback and behavior differences vs Webmachine. |
| examples/upload/src/main.erl | Removes random switching; always uses Cowmachine middleware chain. |
| examples/eventsource/src/main.erl | Removes random switching; always uses Cowmachine middleware chain. |
| examples/cookie/src/main.erl | Removes random switching; always uses Cowmachine middleware chain. |
| examples/rest_basic_auth/apps/main/src/main_app.erl | Simplifies startup to always use Cowmachine middleware chain. |
| examples/hello_world_ssl/apps/main/src/main_app.erl | Simplifies TLS startup; always uses Cowmachine middleware chain. |
| examples/hello_world_rest/apps/main/src/main_app.erl | Fixes startup (incl. prior compile issue) and always uses Cowmachine middleware chain. |
| examples/hello_world_chunked/apps/main/src/main_app.erl | Simplifies startup; always uses Cowmachine middleware chain (controller2). |
| examples/echo_post/apps/main/src/main_app.erl | Simplifies startup; always uses Cowmachine middleware chain. |
| examples/echo_get/apps/main/src/main_app.erl | Simplifies startup; always uses Cowmachine middleware chain. |
| examples/compress_response/apps/main/src/main_app.erl | Simplifies startup; always uses Cowmachine middleware chain. |
| examples/controller_functions/apps/main/src/controller.erl | Removes unused Webmachine callback and fixes finish_request/1 return value. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… preserve www-authenticate header Agent-Logs-Url: https://github.com/zotonic/cowmachine/sessions/708ab264-012b-4ca9-b558-44bb0d692c0f Co-authored-by: mworrell <38268+mworrell@users.noreply.github.com>
Fixed in 4cb6ad7. Both |
Cowmachine lacked end-to-end tests, had no documentation of how it diverged from webmachine, carried a flow diagram with known errors, and had examples that randomly fell back to old Cowboy-direct handlers at runtime.
End-to-end tests (
test/cowmachine_e2e_tests.erl)22 EUnit tests exercising the full HTTP decision flow. The module doubles as a Cowboy middleware and a cowmachine controller; per-test behaviour is driven by
application:set_env. Tests are ordered top-to-bottom following the decision diagram:Coverage: 200, HEAD, 503, 414, 405+Allow, 400, 401 (plain + binary challenge), 403, 415, 413, OPTIONS+custom headers, content-type negotiation (match and 406), 404, 410, 301+Location, 307+Location, ETag header, Last-Modified header, If-None-Match→304, If-None-Match:*→304, If-Modified-Since→304, DELETE→204, DELETE→202 (async), POST→200 echo.
Webmachine diff (
docs/differences-webmachine-cowmachine.md)Full reference of every callback difference:
Fun(ReqData, State) → {R, RD, S}becameFun(Context) → {R, Context}process/4:delete_resource,process_post, named per-content-type handler atoms incontent_types_provided/content_types_acceptedencodings_provided→content_encodings_providedprocess/4,transfer_encodings_provided/1,upgrades_provided/1,execute/2content_types_provided,allowed_methods(atoms → binaries),charsets_provided(no conversion fun),is_authorized(falsenow has explicit handling)v3b6_upgradenode;v3h7semantics differ;v3m20/v3n11/v3o18dispatch toprocess/4Corrected flow diagram (
docs/http-headers-status-cowmachine.dot)Fixes in the existing
http-headers-status.dotthat reflected webmachine, not cowmachine:v3b6_upgradeforbidden?andvalid_content_headers?v3m5edgesPOST→410, else→v3n5(reversed)POST→v3n5, else→410v3n5edgesallow_missing_post=true→410(reversed)allow_missing_post=true→v3n11v3m20delete_resourceprocess(DELETE)v3h7If-Match: *→ 412Example fixes
main_app.erl/main.erl): removedrand:uniformswitching between oldmainpageCowboy handler and cowmachine; always use#{middlewares => [controller, cowmachine]}hello_world_rest/main_app.erl: fixed compile error (double binding ofProtocolOpts)controller_functions/controller.erl: removeddelete_resource/1(webmachine leftover, never called by cowmachine); fixedfinish_request/1returning{undefined, Context}→{true, Context}Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
8.8.8.8REDACTED, pid is -1(packet block)repo.hex.pm/usr/lib/erlang/erts-13.2.2.5/bin/inet_gethost 4(dns block)s3.amazonaws.com/usr/bin/curl curl -fsSL REDACTED -o /usr/local/bin/rebar3 sg-1ubuntu4.6_amd64.deb -libwxgtk3.2-1t64_3.2.4+dfsg-4build1_amd64.deb /usr/local/sbin/iptables main/src/controldpkg-deb main/src/mainpag--control /controller.erl iptables algo�� n_0.21.4-1build3_all.deb ubuntu4.6_all.deb /snap/bin/git ngs/ubuntu-archisystemctl nflict 168.63.129.16 git(dns block)If you need me to access, download, or install something from one of these locations, you can either:
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.