Пример #1
0
func (a *HttpLoadbalancer) ProcessRequest(req context.ContextSpec) (*http.Response, error) {
	// None of the modules in the pipeline has intercepted the request, so lets hit the endpoint now!
	// TODO: - Transport should be configurable via options
	//       - HTTP Header to be added: `X-Forwarded-Host`

	// Note that we rewrite request each time we proxy it to the
	// endpoint, so that each try gets a fresh start
	req.SetHttpRequest(copyRequest(req.GetHttpRequest(), req.GetBody(), a.url))

	return http.DefaultTransport.RoundTrip(req.GetHttpRequest())
}
Пример #2
0
func (ba *BasicAuth) ProcessRequest(c context.ContextSpec) (*http.Response, error) {
	authHeaderValue := c.GetHttpRequest().Header.Get("Authorization")
	if authHeaderValue == "" {
		logutils.FileLogger.Error("Attempted access with malformed header, no auth header found. Path: %s, Origin: %s", c.GetHttpRequest().URL, c.GetHttpRequest().Referer())
		return nil, errors.FromStatus(http.StatusUnauthorized) // 401
	}
	// Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
	parts := strings.Fields(authHeaderValue)
	if len(parts) != 2 {
		logutils.FileLogger.Error("Attempted access with malformed header, header not in basic auth format.")
		return nil, errors.FromStatus(http.StatusBadRequest) //400
	}

	// Decode the username:password string
	authvaluesStr, err := base64.StdEncoding.DecodeString(parts[1])
	if err != nil {
		logutils.FileLogger.Error("Base64 Decoding failed of basic auth data: %s", err)
		return nil, errors.FromStatus(http.StatusBadRequest) //400
	}

	authValues := strings.Split(string(authvaluesStr), ":")
	if len(authValues) != 2 {
		// Header malformed
		logutils.FileLogger.Error("Attempted access with malformed header, values not in basic auth format.")
		return nil, errors.FromStatus(http.StatusBadRequest) //400
	}

	// CHANGELOG.md - check session and identity for valid key

	// Ensure that username and password match up
	if ba.username != authValues[0] || ba.password != authValues[1] {
		logutils.FileLogger.Error("User not authorized")
		return nil, errors.FromStatus(http.StatusForbidden) //403
	}

	return nil, nil // all good
}
Пример #3
0
func (r *Rewrite) ProcessRequest(c context.ContextSpec) (*http.Response, error) {
	//fmt.Printf("[mod_rewrite] Old URL.String() is: %s \n", c.GetHttpRequest().URL.String())
	//c.GetHttpRequest().URL.Path = c.Eval(r.path)
	//fmt.Printf("[mod_rewrite] New URL.String() is: %s \n", c.GetHttpRequest().URL.String())
	operation := r.path[0]
	newPath := FuncMapOps[operation](c.GetHttpRequest().URL.Path, r.path[1])
	fmt.Printf("[mod-rewrite] Old Path was: %s. New Path is: %s ...\n", c.GetHttpRequest().URL.Path, newPath)
	c.GetHttpRequest().URL.Path = newPath
	return nil, nil
}