Skip to content

Tags: zigzap/zap

Tags

v0.9.1

__**Bugfix for Middleware.EnpointHandler checkPath logic**__

I introduced a bug by wrongly trying to de-morgan the logic.

Thx @andr3h3nriqu3s11 for submitting issue #136 <#136>

I reverted the commit.

v0.9.0

__**Small API Refactors**__

This is a small update from recent PRs with little breaking changes in
`zap.Mustache` and `zap.Middleware.EndpointHandler`. Thanks for the
great contributions! See the changelog below.

**Also: we now use zig fetch!**

This greatly simplifies the instructions in the README and release
notes.

__**Breaking Changes:**__

Mustache:
- renamed `zap.Mustache.MustacheLoadArgs` to `zap.Mustache.LoadArgs`
- `zap.Mustache.BuildResult` is a public type now

Middleware:
- `zap.Middleware.EndpointHandler` now takes more than one option:

```ts
/// Options used to change the behavior of an `EndpointHandler`
pub const EndpointHandlerOptions = struct {
    /// If `true`, the handler will stop handing requests down the chain if the
    /// endpoint processed the request.
    breakOnFinish: bool = true,

    /// If `true`, the handler will only execute against requests that match
    /// the endpoint's `path` setting.
    checkPath: bool = false,
};
```

I updated the docs and zig-master branch, too.

__**Changelog:**__

Rene Schallner (5):
      Merge pull request #117 from cosmicboots/mustache-build
      doc: getHeader need lowercase keys
      Merge pull request #120 from cosmicboots/endpoint-middleware
      Merge pull request #127 from iacore/patch-1
      docs, announceybot: switch to using zig fetch

Thom Dickson (4):
      include BuildResult in public Mustache API
      rename MustacheLoadArgs to LoadArgs
      Create options for EndpointHandler
      update docs and examples for endpoint middleware

iacore (1):
      update docs for zap.start

v0.8.0

__Update to Zig 0.13__

With the help of our awesome contributers, we have a new release:

- Zap is now officially based on Zig 0.13.0!
- Thx to Lois Pearson, we now have `mimetypeRegister` and `mimetypeClear`
- Thx to geemili, we don't need to link facil.io in our build.zigs anymore
- Thx to Sören Michaels, `methodAsEnum` supports the `HEAD` method.
- ... and more, see the changelog below

**Note:** there now is a `zig-master` branch that gets updated with breaking changes of Zig master on a somewhat regular basis. Please feel free to send PRs.

Many thanks again to everyone who helped out:

Giuseppe Cesarano (1):
      fix: _debug typo in startWithLogging

Joe Koop (1):
      update http.zig to rfc9110 using MDN as a reference

Lord Asdi (1):
      fix: use std.process.getEnvVarOwned instead of std.posix.getenv

Louis Pearson (8):
      fix: last_modifed -> last_modified
      fix: docserver: server wasm with correct mimetype
      feat: Wrap mimetypeRegister and mimetypeClear
      fix: move getHeaderCommon to zap.zig
      feat: add parseAccept
      feat: make example for parseAccept
      fix: simplify accept header api somewhat
      feat: pre-allocate enough space for accept items

Michael Wendt (1):
      feat: remove deprecated path

Rene Schallner (18):
      Update hello_json.zig
      fix docserver invocation from build.zig
      proposed change to parseAccept API
      make zap master build with zig master
      update zig version
      updated zig-master check in CI
      update badge in README
      corrected release templates

Sören Michaels (1):
      feat: add HEAD Method to `methodAsEnum`

geemili (1):
      feat: streamline depending on zap by linking facil.io to module

v0.7.0

__Update to Zig 0.12__

With the help of our awesome contributers, we have a new release:

- zap is now officially based on Zig 0.12.0!
- tests have been updated to use the latest `std.http` client
- @desttinghim added `getHeaderCommon` to `zap.Request`
- @leroycep improved error return traces in `zap.Request.sendError()`
- @dasimmet and @dweiller fixed the use of @fieldParentPtr to the new style
- @xflow-systems improved the write function of websockets

Users of `sendError()`: the API has changed! The doc comment has been updated. The new way of using it is:

```ts
r.sendError(err, if (@errorReturnTrace()) |t| t.* else null, 505);
```

The new version outputs much nicer error traces.

**Note:** there will likely be a `zig-master` branch in the future that gets updated with breaking changes of Zig master. For sanity reasons, it will not be called `zig-0.13.0` but `zig-master`. I'll update the README accordingly then.

**Note 2:** I merged PRs and fixed the tests while waiting for my plane to board, then finished on the plane. If I might have rushed it and oopsied something up, I'll apologize and follow up with a bugfix release.

One open issue is using openssl on macOS, especially with openssl in custom locations, like homebrew-installed versions. If anyone wants to look into that: PRs are welcome 😊!

Many thanks again to everyone who helped out!

v0.6.0

__Breaking change in zap.Router__

Latest zig master does not allow for multiple copies of the same anonymous type anymore. This broke zap.RequestHandler used by zap.Router.

So I rewrote zap.Router and zap.RequestHandler is gone.

To keep the APIs identical for both zig versions, I applied the rewrite patch also to the zig 0.11.0 (master) branch.

- [simple_router example](https://github.com/zigzap/zap/blob/master/examples/simple_router/simple_router.zig)
- [zap.Router documentation](https://zigzap.org/zap/#zap.router)

From a user perspective not much changed:

- for unbound route handlers, use `zap.Router.handle_route_unbound`.
- use `zap.Router.on_request_handler()` to get the request function to pass to a Listener.

**Note:** the 0.12.0 branch is currently broken with regard to tests due to changes in `std.http`.

__**Changelog**__ in alphabetical order:

GitHub Action (1):
      Update README

Rene Schallner (2):
      trying to add mastercheck badge to README
      re-write of zap.Router, fix #83

v0.5.1

__Request.methodAsEnum() and Windows build error message__

This is a small update of recent PRs. Thanks for the great contributions!

See the changelog below for individual contributions.

- `zap.Request.methodAsEnum()` returns HTTP method as enum or .UNKNOWN
    - the reason the method is not an enum by default is to avoid the
      string comparisons on every request when we might not need them
- build attempts on Windows now produce a meaningful error message
- `zap.Request` now supports `getParamSlice()` and `getParamSlices()`
    which return optional string slices of the raw query string.
    - PRO: no allocation
    - CON: no decoding: "hello+zap" will not be decoded into "hello zap"
    - if you need decoding, you can still use `getParamStr()`.

I updated the docs and zig-0.12.0 branch, too, as with all recent and future releases.

__**Changelog**__ in alphabetical order:

Froxcey (4):
      Use std.http.Method for Request.method
      Use custom method enum
      Provide Windows error message
      Use debug.err and exit 1 for windows fail message

Joe Liotta (1):
      fixed unneeded optional unwrap in hello_json

Rene Schallner (8):
      Update README.md to point out even more prominently the zig master situation
      Merge pull request #72 from Chiissu/master
      Merge pull request #75 from Chiissu/windows-errmsg
      access raw query params w/o allocator, close #40
      cosmetics
      Merge pull request #79 from joeypas/master
      fix workflow to detect failing builds of individual samples
      in http.methodToEnum use std.meta.stringToEnum
      performance: revert r.method enum back to ?[]const u8
          (new http.Method enum is available via r.methodAsEnum())
      use methodAsEnum() in Endpoint, and in json example

v0.5.0

__Introducing: zap.Router__

Thanks to StringNick, we now have `zap.Router` with handler closures support!

See the `simple_router` example. `zap.Router` is missing doc comments, so if anyone wants to step up, please feel free to send a PR against the `zig-0.12.0` my way.

BTW: Documentation (built on zig-0.12.0 branch) is now live at: <https://zigzap.org/zap>

Doc update PRs are welcome. I am especially excited about the _guides_ feature: <https://zigzap.org/zap/#G;>

__**Introduced:**__

- `zap.Router`: the router itself
- `zap.RequestHandler : a nice way to capture "self" pointers of containers of request functions.
- `simple_router`: example demonstrating the above

Thanks again to StringNick!

I updated the zig-0.12.0 branch, too, as with all recent and future releases.

v0.4.0

__Breaking API Cleanup__

**Documentation (built on zig-0.12.0 branch) is now live at: <https://zigzap.org/zap>**

Doc update PRs are welcome. I am especially excited about the _guides_ feature: <https://zigzap.org/zap/#G;>

So, I spent a few days with a first pass of cleaning up Zap's API, informed by using it in production for over half a year now.

**__Refactored:__**

- no more type names starting with `Simple`.
    - zap.SimpleEndpoint -> zap.Endpoint
    - zap.SimpleRequest -> zap.Request
    - zap.SimpleHttpListener -> zap.HttpListener
    - ...
- zap.Endpoint : zap.Endpoint, zap.Endpoint.Authenticating
    - zap.Endpoint.Listener.register() // was: zap.EndpointListener.addEndpoint
- zap.Auth : zap.Auth.Basic, zap.Auth.BearerSingle, ...
- zap.Mustache : stayed the same
- zap.Request : refactored into its own file, along with supporting types and functions (e.g. http params related)
    - added setContentTypeFromFilename thx @hauleth.
- zap.Middleware: no more MixContexts
    - (zig structs are fine)
    - check example
- zap.fio : facilio C FFI stuff does not pollute zap namespace anymore
    - it is still available via `zap.fio`.
- allocators are always first-ish param: either first or after self
- more docstrings

All examples and tests have been updated. Also, check out the documentation (work in progress).

v0.3.0

__-Dopenssl is back && breaking mustache changes__

Thanks to @Vemahk, `-Dopenssl=true` is back! Apparently, while trying to pass user-defined options from a dependent project to zap, I typoed the working solution, and several people pointed out to me that it's as simple as:

```zig
    const zap = b.dependency("zap", .{
        .target = target,
        .optimize = optimize,
        .openssl = false, // set to true to enable TLS support
    });
```

As a result, we re-introduced `-Dopenssl`, use it if present, and fall back to the `ZAP_USE_OPENSSL` env var (set to `true` to enable) if not.

Aaand: thanks to @chooky (BrookJeynes on GH), we have a new, clean, zig-iomatic, documented Mustache API in Zap now:

```zig
    var mustache = try Mustache.fromData("{{some_item}} {{& nested.item }}");
    defer mustache.deinit();

    const b = mustache.build(.{
        .some_item = 42,
        .nested = .{
            .item = 69,
        },
    });
    defer b.deinit();

    if(b.str()) |s| {
        std.debug.print("{s}", .{s});
    };
```

Checkout mustache.zig and the mustache example to learn more.

v0.2.6

__TLS / HTTPS / openssl build change!!!__

Previously, zap required `-Dopenssl=true` to build openssl support. Turns out, for projects using zap, it's insanely hard if not impossible to pass the user provided option `openssl=true` down to the zap dependency.

As a workaround, I changed the build so that it now expects an environment variable `ZAP_USE_OPENSSL` be set to `true`.

So, to build the _https_ example, run:

`ZAP_USE_OPENSSL=true zig build run-https`

*The Example*

Create the certificate and key file:

```console
$ openssl req -x509 -nodes -days 365 -sha256 -newkey rsa:2048 -keyout mykey.pem -out mycert.pem
```

Build / run the example

```console
$ ZAP_USE_OPENSSL=true zig build https
$ ZAP_USE_OPENSSL=true zig build -Dopenssl=true run-https
```

Issue an HTTPS request:

```console
$ curl -v -k https://localhost:4443/build.zig
```

Using openssl in your code is super simple:

```zig
    const tls = zap.fio_tls_new(
        "localhost:4443",
        CERT_FILE,
        KEY_FILE,
        null, // key file is not password-protected
    );
    defer tls.deinit();
```

That `tls` data is then passed to the `SimpleHttpListener`:

```zig
    var listener = zap.SimpleHttpListener.init(.{
        .port = 4443,
        .on_request = on_request_verbose,
        .log = true,
        .max_clients = 100000,
        .tls = tls,   //   <----- h e r e
    });
    try listener.listen();
```