Compare commits
3 Commits
v2024.3.28
...
v2024.3.29
Author | SHA1 | Date | |
---|---|---|---|
ad907576dc | |||
3a894972f1 | |||
274bef13d8 |
@ -25,7 +25,6 @@ Où:
|
||||
- droit en lecture sur l'ensemble des entités (proxy, layer);
|
||||
- droit en lecture ET en écriture sur l'ensemble des entités.
|
||||
|
||||
|
||||
## Points d'entrée
|
||||
|
||||
### `POST /api/v1/proxies`
|
||||
@ -34,7 +33,7 @@ Créer un nouveau proxy
|
||||
|
||||
#### Exemple de corps de requête
|
||||
|
||||
```json5
|
||||
```json
|
||||
{
|
||||
"name": "myproxy", // OBLIGATOIRE - Nom du proxy
|
||||
"to": "https://www.cadoles.com", // OBLIGATOIRE - Site distant ciblé par le proxy
|
||||
@ -44,7 +43,7 @@ Créer un nouveau proxy
|
||||
|
||||
#### Exemple de résultat
|
||||
|
||||
```json5
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"proxy": {
|
||||
@ -74,7 +73,7 @@ Récupérer les informations complètes sur un proxy
|
||||
|
||||
#### Exemple de résultat
|
||||
|
||||
```json5
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"proxy": {
|
||||
@ -100,18 +99,18 @@ Modifier un proxy
|
||||
|
||||
#### Exemple de corps de requête
|
||||
|
||||
```json5
|
||||
```json
|
||||
{
|
||||
"to": "https://www.cadoles.com", // OPTIONNEL - Site distant ciblé par le proxy
|
||||
"from": ["mylocalproxydomain:*"], // OPTIONNEL - Liste de patrons de filtrage associés au proxy
|
||||
"weight": 100, // OPTIONNEL - Poids à associer au proxy
|
||||
"enabled": true, // OPTIONNEL - Activer/désactiver le proxy
|
||||
"enabled": true // OPTIONNEL - Activer/désactiver le proxy
|
||||
}
|
||||
```
|
||||
|
||||
#### Exemple de résultat
|
||||
|
||||
```json5
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"proxy": {
|
||||
@ -141,14 +140,14 @@ Lister les proxies existants
|
||||
|
||||
#### Exemple de résultat
|
||||
|
||||
```json5
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"proxies": [
|
||||
{
|
||||
"name": "myproxy",
|
||||
"weight": 0,
|
||||
"enabled": false,
|
||||
"enabled": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -169,7 +168,7 @@ Supprimer le proxy
|
||||
|
||||
#### Exemple de résultat
|
||||
|
||||
```json5
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"proxyName": "myproxy"
|
||||
|
@ -3,7 +3,6 @@ package director
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
|
||||
"forge.cadoles.com/Cadoles/go-proxy"
|
||||
@ -28,15 +27,27 @@ func (d *Director) rewriteRequest(r *http.Request) (*http.Request, error) {
|
||||
return r, errors.WithStack(err)
|
||||
}
|
||||
|
||||
url := getRequestURL(r)
|
||||
ctx = logger.With(r.Context(), logger.F("url", url.String()))
|
||||
|
||||
var match *store.Proxy
|
||||
|
||||
MAIN:
|
||||
for _, p := range proxies {
|
||||
for _, from := range p.From {
|
||||
if matches := wildcard.Match(r.Host, from); !matches {
|
||||
logger.Debug(
|
||||
ctx, "matching request with proxy's from",
|
||||
logger.F("from", from),
|
||||
)
|
||||
if matches := wildcard.Match(url.String(), from); !matches {
|
||||
continue
|
||||
}
|
||||
|
||||
logger.Debug(
|
||||
ctx, "proxy's from matched",
|
||||
logger.F("from", from),
|
||||
)
|
||||
|
||||
match = p
|
||||
break MAIN
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package director
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"forge.cadoles.com/Cadoles/go-proxy"
|
||||
"forge.cadoles.com/Cadoles/go-proxy/util"
|
||||
@ -16,3 +17,19 @@ func createMiddlewareChain(handler http.Handler, middlewares []proxy.Middleware)
|
||||
|
||||
return handler
|
||||
}
|
||||
|
||||
func getRequestURL(r *http.Request) *url.URL {
|
||||
scheme := "http"
|
||||
if r.URL.Scheme != "" {
|
||||
scheme = r.URL.Scheme
|
||||
}
|
||||
|
||||
url := url.URL{
|
||||
Host: r.Host,
|
||||
Scheme: scheme,
|
||||
Path: r.URL.Path,
|
||||
RawQuery: r.URL.RawQuery,
|
||||
}
|
||||
|
||||
return &url
|
||||
}
|
||||
|
Reference in New Issue
Block a user