Package httprec provides tools for recording and modifying HTTP responses that are useful for creating middleware, for the Go programming language.
Find a file
2025-09-21 06:49:40 -07:00
always.go rename 2025-09-19 18:25:42 -07:00
errors.go errors 2025-09-04 05:50:10 -07:00
go.mod httprec.RecordMediaType 2025-09-20 05:59:01 -07:00
go.sum httprec.RecordMediaType 2025-09-20 05:59:01 -07:00
LICENSE initial commits 2025-09-04 05:49:05 -07:00
never.go rename 2025-09-19 18:25:42 -07:00
README.md docs correction 2025-09-21 06:49:40 -07:00
recordmediatype.go httprec.RecordMediaTypeExceptWhenAccepted httprec.RecordMediaType 2025-09-20 16:22:45 -07:00
recordmediatype_test.go httprec.RecordMediaTypeExceptWhenAccepted httprec.RecordMediaType 2025-09-20 16:22:45 -07:00
recordmediatypeexceptwhenaccepted.go httprec.RecordMediaTypeExceptWhenAccepted httprec.RecordMediaType 2025-09-20 16:22:45 -07:00
recordmediatypeexceptwhenaccepted_test.go httprec.RecordMediaTypeExceptWhenAccepted httprec.RecordMediaType 2025-09-20 16:22:45 -07:00
responsewriter.go httprec.ResponseWriter 2025-09-04 17:14:43 -07:00
responsewritercontroller.go httprec.ResponseWriterController 2025-09-04 05:58:44 -07:00
responsewritercontrollerfunc.go added compile time test 2025-09-04 17:38:12 -07:00
test_test.go httprec.RecordMediaType 2025-09-20 05:59:01 -07:00

go-httprec

Package httprec provides tools for recording and modifying HTTP responses that are useful for creating middleware, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/codeberg.org/reiver/go-httprec

GoDoc

Example

Package httprec provides an http.ResponseWriter that can be usedto record and modify HTTP responses.

Here is an example of it being used:

type MiddleWare struct {
	SubHTTPHandler http.Handler
}

func (recevier MiddleWare) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {

	// ...

	var recordingResponseWriter *httprec.ResponseWriter = httprec.NewResponseWriter(responseWriter, request, controller)

	receiver.SubHandler.ServeHTTP(recordingResponseWriter, request)
	if !recordingResponseWriter.HasRecording() {
		return
	}

	bytes = recordingResponseWriter.Bytes()

	// ...

}

Response Writer Controllers

A response-writer-controller controls whether the httprec.ResponseWriter records or not.

Package httprec comes with some built-in contollers:

  • httprec.AlwaysRecord makes httprec.ResponseWriter to always record
  • httprec.NeverRecord makes httprec.ResponseWriter to never record
  • httprec.RecordMediaType makes httprec.ResponseWriter record only if the response of the sub-http.Handler has a specified media-type in its Content-Type
  • httprec.RecordMediaTypeExceptWhenAccepted makes httprec.ResponseWriter record only if the response of the sub-http.Handler has a specified media-type in its Content-Type and the requests Accept does not have it

Import

To import package httprec use import code like the following:

import "codeberg.org/reiver/go-httprec"

Installation

To install package httprec do the following:

GOPROXY=direct go get codeberg.org/reiver/go-httprec

Author

Package httprec was written by Charles Iliya Krempeaux