Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

vimagination.zapto.org/httpbuffer

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/httpbuffer

Go Modules
Version
v1.1.4
Version published
Created
Source

httpbuffer

CI Go Reference Go Report Card

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

Package httpbuffer provides a buffer for HTTP requests so that the Content-Length may be set and compression applied for dynamic pages.

Highlights

  • Buffer HTTP responses before sending them to the client.
  • Automatically sets Content-Length header.
  • Supports optional compression which is automatically applied based on Accept-Encoding header.
  • Import vimagination.zapto.org/httpbuffer/{brotli,deflate,gzip} to support compression.

Usage

package main

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

	"vimagination.zapto.org/httpbuffer"
	_ "vimagination.zapto.org/httpbuffer/gzip"
)

func handler(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, "Hello, World!")
}

func main() {
	w := httptest.NewRecorder()
	r, _ := http.NewRequest(http.MethodGet, "/", nil)

	handler(w, r)

	fmt.Println(w.Result().ContentLength)

	w = httptest.NewRecorder()
	buf := httpbuffer.Handler{Handler: http.HandlerFunc(handler)}
	buf.ServeHTTP(w, r)

	fmt.Println(w.Result().ContentLength)
	fmt.Println(w.Body)

	// Output:
	// -1
	// 13
	// Hello, World!
}

Documentation

Full API docs can be found at:

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

FAQs

Package last updated on 08 Nov 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