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

vimagination.zapto.org/httpfile

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vimagination.zapto.org/httpfile

Go Modules
Version
v1.1.3
Version published
Created
Source

httpfile

CI Go Reference Go Report Card

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

Package httpfile provides an easy way to create HTTP handlers that respond with static data, possibly gzip compressed if requested by the client.

Highlights

  • Create an updatable http.Handler from static data.
  • Sends either gzip-compressed or uncompressed data based on Accept-Encoding header.

Usage

package main

import (
	_ "embed"
	"fmt"
	"net/http"
	"net/http/httptest"

	"vimagination.zapto.org/httpfile"
)

func main() {
	handler := httpfile.NewWithData("file.json", []byte(`{"hello", "world!"}`))

	w := httptest.NewRecorder()
	r, _ := http.NewRequest(http.MethodGet, "/", nil)
	r.Header.Set("Accept-encoding", "identity")

	handler.ServeHTTP(w, r)

	fmt.Println(w.Body)

	handler.ReadFrom(bytes.NewBuffer([]byte(`{"foo": "bar"}`)))

	r.Header.Set("Accept-encoding", "identity")

	w = httptest.NewRecorder()

	handler.ServeHTTP(w, r)

	fmt.Println(w.Body)

	// Output:
	// {"hello", "world!"}
	// {"foo": "bar"}
}
}

Documentation

Full API docs can be found at:

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

FAQs

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