head_to_get

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 5 Imported by: 0

README

HEAD-to-GET Plugin

This plugin converts any HTTP request that has the HEAD verb/method to GET, useful for certain Java or .Net web apps that don't support HEAD but you use an external health check that wants to send HEAD anyways.

Configuration

  1. Enable the plugin in your Traefik configuration:
experimental:
 plugins:
  head_to_get:
   moduleName: github.com/cdwiegand/traefik-head-to-get
   version: v0.2.1
  1. Define the middleware. Note that this plugin does not need any configuration, however, values must be passed in for it to be accepted within Traefik:
http:
 # ...
 middlewares:
  # this name must match the middleware that you attach to routers later
  head-to-get:
    plugin:
      head_to_get:
        removeExposingHeaders: true

Please note that traefik requires at least one configuration variable set, to keep the defaults you can set addCspHeader: true to accomodate this. This is not a requirement of this plugin, but a traefik requirement.

  1. Then add it to your given routers, such as this:
http:
 # ...
 routers:
  example-router:
   rule: host(`demo.localhost`)
   service: service-foo
   entryPoints:
    - web
   # add these 2 lines, use the same name you defined directly under "middlewares":
   middlewares: 
    - head-to-get
   # end add those 2 lines
  1. You are done!

Testing Methods

Testing by using local plugin functionality, assuming the code is checked out to C:\devel\traefik-head-to-get:

docker run --rm -it -p 8888:80 -v C:\devel\traefik-head-to-get\:/srv/plugins-local/src/github.com/cdwiegand/traefik-head-to-get:ro -w /srv traefik:3.0 --entryPoints.web.address=:80 --experimental.localPlugins.head_to_get.modulename=github.com/cdwiegand/traefik-head-to-get --providers.file.filename=/srv/plugins-local/src/github.com/cdwiegand/traefik-head-to-get/testing.traefik.yml --api=true --api.dashboard=true

and go to http://localhost:8888/dashboard/ and inspect the browser's Network tab to see the Server header in the response replaced with "Nope/2.0".

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetToRemoveResponseHeaders

func GetToRemoveResponseHeaders() []string

func New

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New created a new plugin, with a config that's been set (possibly) by the admin

func NewBodyDroppingResponseWriter

func NewBodyDroppingResponseWriter(w http.ResponseWriter) http.ResponseWriter

func TestServeHTTP_Get

func TestServeHTTP_Get(t *testing.T)

func TestServeHTTP_Head

func TestServeHTTP_Head(t *testing.T)

func TestServeHTTP_Post

func TestServeHTTP_Post(t *testing.T)

Types

type BodyDroppingResponseWriter

type BodyDroppingResponseWriter struct {
	http.ResponseWriter
}

func (*BodyDroppingResponseWriter) CloseNotify

func (w *BodyDroppingResponseWriter) CloseNotify() <-chan bool

func (*BodyDroppingResponseWriter) Flush

func (w *BodyDroppingResponseWriter) Flush()

func (*BodyDroppingResponseWriter) Header

func (*BodyDroppingResponseWriter) Unwrap

func (*BodyDroppingResponseWriter) Write

func (w *BodyDroppingResponseWriter) Write(bytes []byte) (int, error)

func (*BodyDroppingResponseWriter) WriteHeader

func (w *BodyDroppingResponseWriter) WriteHeader(statusCode int)

type Config

type Config struct {
	PutOriginalMethodInHeader string
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the DEFAULT plugin configuration - no access to config yet!

type HeadToGetPlugin

type HeadToGetPlugin struct {
	// contains filtered or unexported fields
}

HeadToGetPlugin header

func (*HeadToGetPlugin) ServeHTTP

func (t *HeadToGetPlugin) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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