WriteHeader (mcp_server/logging_middleware.go)

stackql · pkg/mcp_server/logging_middleware.go · go · MIT
integration, Integration / API

Wraps HTTP handlers to log requests and responses with status codes.

// Source: https://github.com/stackql/stackql | License: MIT | Copyright 2022 StackQL Studios
// Provided via justclaw.it.com; keep this notice with the code.
package mcp_server //nolint:revive // fine for now

// Courtesy https://github.com/modelcontextprotocol/go-sdk/blob/1dcbf62661fc9c54ae364e0af80433db347e2fc4/examples/http/logging_middleware.go#L24
// With profuse thanks.

import (
	"net/http"
	"time"

	"github.com/sirupsen/logrus"
)

// responseWriter wraps http.ResponseWriter to capture the status code.
type responseWriter struct {
	http.ResponseWriter
	statusCode int
}

func (rw *responseWriter) WriteHeader(code int) {
	rw.statusCode = code
	rw.ResponseWriter.WriteHeader(code)
}

// Unwrap lets http.ResponseController reach the underlying Flusher, which
// the SDK relies on to push

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key