transport

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BearerAuthTransport

type BearerAuthTransport struct {
	Transport http.RoundTripper
	Token     string

	// TokenProvider, when non-nil, supplies the bearer token for each request
	// and takes precedence over Token.
	TokenProvider func() string

	// AllowedHosts, when non-empty, restricts the hosts the Authorization
	// header is attached to. The token is set only when the request host
	// and port exactly match one of these entries (case-insensitive). This
	// scopes the credential to the configured GitHub hosts, so that if a
	// response redirects off them the token is not carried to the redirect
	// target.
	//
	// net/http strips a cross-host Authorization header when it follows a
	// redirect, but only for headers set on the initial request. This
	// transport re-adds the header on every hop, so that protection does not
	// otherwise apply here.
	//
	// When empty, the token is attached to every request, preserving the
	// prior behavior.
	AllowedHosts []string
}

func (*BearerAuthTransport) RoundTrip

func (t *BearerAuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

type ETagTransport added in v1.11.0

type ETagTransport struct {
	Transport http.RoundTripper

	// MaxEntries bounds the number of cached responses. When zero,
	// defaultETagCacheSize is used.
	MaxEntries int

	// MaxEntryBytes bounds the size of a single cached body. Responses larger
	// than this are revalidated but not retained. When zero, defaultMaxEntryBytes
	// is used.
	MaxEntryBytes int

	// MaxTotalBytes bounds the combined size of all cached bodies. When zero,
	// defaultMaxTotalBytes is used.
	MaxTotalBytes int
	// contains filtered or unexported fields
}

ETagTransport is an http.RoundTripper that adds HTTP conditional-request support (ETag / If-None-Match) to GET requests. For each cacheable GET it stores the response ETag and body; on a subsequent identical request it sends If-None-Match and, when the server answers 304 Not Modified, serves the cached body instead of re-downloading it.

Every request is still sent to the server, so responses are always revalidated and never served stale. A 304 Not Modified does not count against the GitHub REST API primary rate limit, so revalidated requests conserve rate-limit budget and bandwidth.

Cached entries are scoped by the request's Authorization header so responses are never shared across tokens. Responses marked non-storable by HTTP cache directives (request or response Cache-Control: no-store, or Vary: *) are never retained. The cache is bounded both by entry count and by a total-byte budget (LRU) and is safe for concurrent use.

This transport is intended for the long-lived local (stdio) server only. The hosted, horizontally-scaled server constructs a fresh REST client per request and does not use it, so an in-process cache adds nothing there.

func (*ETagTransport) RoundTrip added in v1.11.0

func (t *ETagTransport) RoundTrip(req *http.Request) (*http.Response, error)

type GraphQLFeaturesTransport

type GraphQLFeaturesTransport struct {
	// Transport is the underlying HTTP transport. If nil, http.DefaultTransport is used.
	Transport http.RoundTripper
}

GraphQLFeaturesTransport is an http.RoundTripper that adds GraphQL-Features header to requests based on context values. This is required for using non-GA GraphQL API features like the agent assignment API.

This transport is used internally by the MCP server and is also exported for library consumers who need to build their own HTTP clients with GraphQL feature flag support.

Usage:

import "github.com/github/github-mcp-server/pkg/http/transport"

httpClient := &http.Client{
    Transport: &transport.GraphQLFeaturesTransport{
        Transport: http.DefaultTransport,
    },
}
gqlClient := githubv4.NewClient(httpClient)

Then use ghcontext.WithGraphQLFeatures(ctx, "feature_name") when calling GraphQL operations.

func (*GraphQLFeaturesTransport) RoundTrip

func (t *GraphQLFeaturesTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type UserAgentTransport

type UserAgentTransport struct {
	Transport http.RoundTripper
	Agent     string
}

func (*UserAgentTransport) RoundTrip

func (t *UserAgentTransport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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