Skip to content

Add HTTP Library for WASM Plugins - go-plugin-http #81

@hanxi

Description

@hanxi

Summary

I've implemented an HTTP library for go-plugin that enables WASM plugins to make HTTP requests. Since WASM doesn't support Go's standard net/http package, this library provides HTTP capabilities through host function proxying using the host-function-library pattern.

Repository: https://github.com/hanxi/go-plugin-http

Features

  • Provides net/http-like API for WASM plugins (Get, Post, Head, Do, etc.)
  • Supports custom headers, request body, and timeout
  • Uses the host-function-library pattern (similar to examples/host-function-library)
  • Works with Go 1.24+ and -buildmode=c-shared for WASI reactor

Usage Example

Host Side

import (
    httpexport "github.com/hanxi/go-plugin-http/export"
    httpimpl "github.com/hanxi/go-plugin-http/impl"
)

p, err := proto.NewGreeterPlugin(ctx, proto.WazeroRuntime(func(ctx context.Context) (wazero.Runtime, error) {
    r, err := proto.DefaultWazeroRuntime()(ctx)
    if err != nil {
        return nil, err
    }
    // Inject HTTP Library
    return r, httpexport.Instantiate(ctx, r, httpimpl.HttpLibraryImpl{})
}))

Plugin Side

import http "github.com/hanxi/go-plugin-http/plugin"

resp, err := http.Get("https://example.com/api")
if err != nil {
    return nil, err
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)

Questions

I think this library could be useful for the go-plugin community. I have two questions:

  1. Would you be interested in adding this as an example in examples/?

    • I could submit a PR to add it as examples/http-library or similar
  2. Or would you prefer to add a link to this library in the README?

    • Perhaps in a "Community Libraries" or "Related Projects" section

I'm happy to contribute in whatever way works best for the project. Let me know your thoughts!

Related

  • This library was inspired by the host-function-library example
  • Tested with go-plugin v0.9.0 and wazero v1.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions