Exemplo n.º 1
0
// ModifyResponse runs cresmod.ModifyResponse and checks ctx.Auth.Error for
// application specific auth failure.
//
// If an error is returned from resmod.ModifyResponse it is returned.
func (m *Modifier) ModifyResponse(ctx *martian.Context, res *http.Response) error {
	if m.resmod != nil {
		if err := m.resmod.ModifyResponse(ctx, res); err != nil {
			return err
		}
	}

	if err := ctx.Auth.Error; err != nil {
		ctx.Auth.Reset()
		ctx.SkipRoundTrip = false
		return err
	}

	return nil
}
Exemplo n.º 2
0
// ModifyRequest sets the auth ID in the context from the request iff it has
// not already been set and runs reqmod.ModifyRequest. If the underlying
// modifier has indicated via ctx.Auth.Error that no valid auth credentials
// have been found we set ctx.SkipRoundTrip.
func (m *Modifier) ModifyRequest(ctx *martian.Context, req *http.Request) error {
	ctx.Auth.ID = id(req.Header)

	if m.reqmod == nil {
		return nil
	}

	if err := m.reqmod.ModifyRequest(ctx, req); err != nil {
		return err
	}

	if ctx.Auth.Error != nil {
		ctx.SkipRoundTrip = true
	}

	return nil
}
Exemplo n.º 3
0
// ModifyResponse runs resmod.ModifyResponse and modifies the response to
// include the correct status code and headers if ctx.Auth.Error is present.
//
// If an error is returned from resmod.ModifyResponse it is returned.
func (m *Modifier) ModifyResponse(ctx *martian.Context, res *http.Response) error {
	var err error

	if m.resmod != nil {
		err = m.resmod.ModifyResponse(ctx, res)
	}

	if ctx.Auth.Error != nil {
		// Reset the auth so we don't get stuck in a failed auth loop
		// when dealing with Keep-Alive.
		ctx.Auth.Reset()
		ctx.SkipRoundTrip = false

		res.StatusCode = http.StatusProxyAuthRequired
		res.Header.Set("Proxy-Authenticate", "Basic")
	}

	return err
}
Exemplo n.º 4
0
// ModifyRequest sets the auth ID in the context from the request iff it has
// not already been set and runs reqmod.ModifyRequest. If the underlying
// modifier has indicated via ctx.Auth.Error that no valid auth credentials
// have been found we set ctx.SkipRoundTrip.
func (m *Modifier) ModifyRequest(ctx *martian.Context, req *http.Request) error {
	ip, _, err := net.SplitHostPort(req.RemoteAddr)
	if err != nil {
		ip = req.RemoteAddr
	}

	ctx.Auth.ID = ip

	if m.reqmod == nil {
		return nil
	}

	if err := m.reqmod.ModifyRequest(ctx, req); err != nil {
		return err
	}

	if ctx.Auth.Error != nil {
		ctx.SkipRoundTrip = true
	}

	return nil
}
Exemplo n.º 5
0
// ModifyRequest signals to the proxy to skip the roundtrip.
func (m *Modifier) ModifyRequest(ctx *martian.Context, req *http.Request) error {
	ctx.SkipRoundTrip = true

	return nil
}