requesthash

package
v0.0.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 3 Imported by: 0

README

Request Hash Middleware

What it does

Computes a request body hash and stores/exposes it for idempotency, audit, signature validation, and duplicate detection.

How to implement

package main

import (
	"github.com/oarkflow/fh"
	"github.com/oarkflow/fh/mw/requesthash"
)

func main() {
	app := fh.New()
	app.Use(requesthash.New(requesthash.Config{}))

	app.Get("/", func(c fh.Ctx) error {
		return c.Status(fh.StatusOK).SendString("ok")
	})
}

Impact

Hashing reads the body and adds CPU proportional to payload size. It can improve dedupe and forensic traceability.

Ordering guidance

Run after body limit and before idempotency/reliability/handlers that need the hash.

Production considerations

Avoid hashing very large streaming bodies unless explicitly supported. Use bounded memory and restore the body for downstream handlers.

Documentation

Index

Constants

View Source
const (
	DefaultHeader = "X-Request-Body-SHA256"
	DefaultLocal  = "request_body_sha256"
)

Variables

This section is empty.

Functions

func New

func New(cfg Config) fh.HandlerFunc

Types

type Config

type Config struct {
	Header    string
	LocalKey  string
	SkipEmpty bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL