Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

vimagination.zapto.org/httpwrap

Package Overview
Dependencies
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/httpwrap

Go Modules
Version
v1.0.2
Version published
Created
Source

httpwrap

CI Go Reference Go Report Card

-- import "vimagination.zapto.org/httpwrap"

Package httpwrap wraps an http.ResponseWriter to override some method(s) while maintaining other possible interface implementations.

Highlights

  • Wrap http.ResponseWriter with custom, select overrides.
  • Preserves many, optional interfaces (http.Flusher, http.Hijacker, http.Pusher, etc.).
  • Auto-generated code to make it easy to add new overridable interfaces.

Usage

package main

import (
	"fmt"
	"io"
	"net/http"
	"net/http/httptest"

	"vimagination.zapto.org/httpwrap"
)

type writeLogger struct {
	http.ResponseWriter
}

func (w writeLogger) Write(p []byte) (int, error) {
	fmt.Println("Writing Bytes:", len(p))

	return w.ResponseWriter.Write(p)
}

func (w writeLogger) WriteString(p string) (int, error) {
	fmt.Println("Writing String:", len(p))

	return io.WriteString(w.ResponseWriter, p)
}

func main() {
	w := httptest.NewRecorder()
	l := writeLogger{w}

	ww := httpwrap.Wrap(w, httpwrap.OverrideWriter(l), httpwrap.OverrideStringWriter(l))

	ww.Write([]byte("Some Data\n"))
	io.WriteString(ww, "Some More Data\n")
	fmt.Println(w.Body)

	// Output:
	// Writing Bytes: 10
	// Writing String: 15
	// Some Data
	// Some More Data
}

Documentation

Full API docs can be found at:

https://pkg.go.dev/vimagination.zapto.org/httpwrap

FAQs

Package last updated on 28 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts