Funzioni dello schema
Funzioni dello schemaHTTP Request via Schema

HTTP Request via Schema

Included in the “Power Extensions” bundle

Aggiunta di campi allo schema GraphQL per recuperare i dati della richiesta HTTP corrente.

Elenco dei campi

I seguenti campi vengono aggiunti allo schema:

_httpRequestBody

Corpo della richiesta HTTP.

_httpRequestClientHost

Host del client.

_httpRequestClientIP

Recupera l'indirizzo IP del client. Se il server non è configurato correttamente (vedi sotto), la risposta è null.

Configurazione

L'indirizzo IP del client viene recuperato dalla variabile globale $_SERVER, normalmente dalla proprietà 'REMOTE_ADDR'. Tuttavia, piattaforme diverse possono richiedere l'uso di un nome di proprietà differente per recuperare questa informazione.

Ad esempio:

  • Cloudflare potrebbe usare 'HTTP_CF_CONNECTING_IP'
  • AWS potrebbe usare 'HTTP_X_FORWARDED_FOR'

Il nome della proprietà da usare può essere configurato nella scheda "Plugin Configuration > Server IP Configuration" della pagina delle Impostazioni:

Configurare il nome della proprietà $_SERVER per recuperare l'IP del client
Configurare il nome della proprietà $_SERVER per recuperare l'IP del client

_httpRequestCookie

Valore del cookie della richiesta.

_httpRequestCookies

Cookie della richiesta.

_httpRequestDomain

Dominio dell'URL richiesto.

_httpRequestFullURL

URL richiesto (inclusi i parametri di query).

_httpRequestHasCookie

La richiesta contiene un determinato cookie?

_httpRequestHasHeader

La richiesta contiene un determinato header?

_httpRequestHasParam

La richiesta contiene un determinato parametro?

_httpRequestHeader

Valore di un header della richiesta.

_httpRequestHeaders

Header della richiesta.

_httpRequestHost

Host dell'URL richiesto.

_httpRequestMethod

Metodo della richiesta.

_httpRequestParams

Oggetto JSON con tutti i parametri (passati via POST o GET).

I valori dei parametri possono essere:

  • Stringhe: ?param=value
  • Array: ?someArray[]=1&someArray[]=2
  • Array di array: ?someMatrix[0][0]=3&someMatrix[0][1]=4&someMatrix[1][0]=5&someMatrix[1][1]=6
  • Array associativi (cioè oggetti): ?someAssocArray["admins"]=20&someAssocArray["authors"]=30
  • Array associativo di array: ?someAssocMatrix["admins"][0]=7&someAssocMatrix["admins"][1]=8&someAssocMatrix["authors"][0]=9&someAssocMatrix["authors"][1]=10
  • Altre combinazioni

Per ottenere il valore del parametro, possiamo usare i campi _httpRequestStringParam e _httpRequestStringListParam per i primi due casi rispettivamente, ma non esistono campi per gli altri casi.

Per questi, usa il campo _httpRequestParams per ottenere l'oggetto JSON, quindi recupera il valore corrispondente al suo interno.

_httpRequestProtocol

Protocollo della richiesta.

_httpRequestQuery

Stringa dei parametri di query.

_httpRequestReferer

Referer della richiesta.

_httpRequestRequestTime

Timestamp dell'inizio della richiesta.

_httpRequestScheme

Schema dell'URL richiesto.

_httpRequestServerIP

Indirizzo IP del server.

_httpRequestStringListParam

Valore di un parametro (passato via POST o GET) del tipo ?param[]=value1&param[]=value2.

_httpRequestStringParam

Valore di un parametro (passato via POST o GET) del tipo ?param=value.

_httpRequestURL

URL richiesto (senza parametri di query).

_httpRequestURLPath

Percorso assoluto (che inizia con "/") dell'URL richiesto.

_httpRequestUserAgent

User agent.

Esempi

Questa query:

query {
  _httpRequestHeaders
  existingHeader: _httpRequestHeader(name: "Accept")
  caseInsensitiveExistingHeader: _httpRequestHeader(name: "accept")
  nonExistingHeader: _httpRequestHeader(name: "Non-existing")
  existingHasHeader: _httpRequestHasHeader(name: "Accept")
  caseInsensitiveExistingHasHeader: _httpRequestHasHeader(name: "accept")
  nonExistingHasHeader: _httpRequestHasHeader(name: "Non-existing")
  _httpRequestBody
  _httpRequestMethod
  _httpRequestDomain
  _httpRequestScheme
  _httpRequestHost
  _httpRequestURL
  _httpRequestFullURL
  _httpRequestURLPath
  _httpRequestQuery
  _httpRequestParams
  existingParam: _httpRequestStringParam(name: "page")
  caseInsensitiveExistingParam: _httpRequestStringParam(name: "PAge")
  existingArrayParam: _httpRequestStringListParam(name: "someArray")
  nonExistingParam: _httpRequestStringParam(name: "also-non-existing")
  nonExistingListParam: _httpRequestStringListParam(name: "also-non-existing")
  existingHasParam: _httpRequestHasParam(name: "page")
  caseInsensitiveExistingHasParam: _httpRequestHasParam(name: "PAge")
  nonExistingHasParam: _httpRequestHasParam(name: "also-non-existing")
  existingCookie: _httpRequestCookie(name: "wordpress_test_cookie")
  caseInsentiveExistingCookie: _httpRequestCookie(name: "Wordpress_Test_Cookie")
  nonExistingCookie: _httpRequestCookie(name: "not_existing")
  existingHasCookie: _httpRequestHasCookie(name: "wordpress_test_cookie")
  caseInsentiveExistingHasCookie: _httpRequestHasCookie(name: "Wordpress_Test_Cookie")
  nonExistingHasCookie: _httpRequestHasCookie(name: "not_existing")
  _httpRequestProtocol
  _httpRequestReferer
  _httpRequestServerIP
  _httpRequestClientIP
  _httpRequestClientHost
  _httpRequestUserAgent
  _httpRequestCookies
  _httpRequestRequestTime
}

...produce:

{
  "data": {
    "_httpRequestHeaders": {
      "authorization": "",
      "host": "gato-graphql-pro.lndo.site",
      "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/114.0",
      "content-length": "1924",
      "accept": "application/json",
      "accept-encoding": "gzip, deflate, br",
      "accept-language": "en-US,en;q=0.5",
      "content-type": "application/json",
      "cookie": "wordpress_sec_f21902903273c44cc3a47d07e23af599=admin%7C1687924210%7CcMlLArK65w5nACJHlglLMMd52rRVZRmu2LRUJmCi7n1%7Cad6b03a20093f342a4107076432f7857e244174ab4d866c1887417c2e304e3fe; wp-settings-time-1=1686559494; wp-settings-1=libraryContent%3Dbrowse; wordpress_test_cookie=WP%20Cookie%20check; wp_lang=en_US; wordpress_logged_in_f21902903273c44cc3a47d07e23af599=admin%7C1687924210%7CcMlLArK65w5nACJHlglLMMd52rRVZRmu2LRUJmCi7n1%7C0ec85ac4a275aff3c464e139d40061aa0062a4e7376666b99ec8063a6715788a",
      "dnt": "1",
      "origin": "https://gato-graphql-pro.lndo.site",
      "referer": "https://gato-graphql-pro.lndo.site/wp-admin/admin.php?page=gatographql&query=%7B%0A%20%20_httpRequestHeaders%0A%20%20existingHeader%3A%20_httpRequestHeader(name%3A%20%22Accept%22)%0A%20%20caseInsensitiveExistingHeader%3A%20_httpRequestHeader(name%3A%20%22accept%22)%0A%20%20nonExistingHeader%3A%20_httpRequestHeader(name%3A%20%22Non-existing%22)%0A%20%20existingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22Accept%22)%0A%20%20caseInsensitiveExistingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22accept%22)%0A%20%20nonExistingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22Non-existing%22)%0A%20%20_httpRequestBody%0A%20%20_httpRequestMethod%0A%20%20_httpRequestDomain%0A%20%20_httpRequestScheme%0A%20%20_httpRequestHost%0A%20%20_httpRequestURL%0A%20%20_httpRequestFullURL%0A%20%20_httpRequestURLPath%0A%20%20_httpRequestQuery%0A%20%20_httpRequestParams%0A%20%20existingParam%3A%20_httpRequestStringParam(name%3A%20%22page%22)%0A%20%20caseInsensitiveExistingParam%3A%20_httpRequestStringParam(name%3A%20%22PAge%22)%0A%20%20existingArrayParam%3A%20_httpRequestStringListParam(name%3A%20%22someArray%22)%0A%20%20nonExistingParam%3A%20_httpRequestStringParam(name%3A%20%22also-non-existing%22)%0A%20%20nonExistingListParam%3A%20_httpRequestStringListParam(name%3A%20%22also-non-existing%22)%0A%20%20existingHasParam%3A%20_httpRequestHasParam(name%3A%20%22page%22)%0A%20%20caseInsensitiveExistingHasParam%3A%20_httpRequestHasParam(name%3A%20%22PAge%22)%0A%20%20nonExistingHasParam%3A%20_httpRequestHasParam(name%3A%20%22also-non-existing%22)%0A%20%20existingCookie%3A%20_httpRequestCookie(name%3A%20%22wordpress_test_cookie%22)%0A%20%20caseInsentiveExistingCookie%3A%20_httpRequestCookie(name%3A%20%22Wordpress_Test_Cookie%22)%0A%20%20nonExistingCookie%3A%20_httpRequestCookie(name%3A%20%22not_existing%22)%0A%20%20existingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22wordpress_test_cookie%22)%0A%20%20caseInsentiveExistingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22Wordpress_Test_Cookie%22)%0A%20%20nonExistingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22not_existing%22)%0A%20%20_httpRequestProtocol%0A%20%20_httpRequestReferer%0A%20%20_httpRequestServerIP%0A%20%20_httpRequestClientIP%0A%20%20_httpRequestClientHost%0A%20%20_httpRequestUserAgent%0A%0A%20%20_httpRequestCookies%0A%20%20_httpRequestRequestTime%0A%7D&variables=%7B%2B%2B%22postID%22%3A%2B40%2C%2B%2B%22translateToLang%22%3A%2B%22es%22%7D&operationName=SendEmail",
      "sec-fetch-dest": "empty",
      "sec-fetch-mode": "cors",
      "sec-fetch-site": "same-origin",
      "sec-gpc": "1",
      "te": "trailers",
      "x-forwarded-for": "172.19.0.1",
      "x-forwarded-host": "gato-graphql-pro.lndo.site",
      "x-forwarded-port": "443",
      "x-forwarded-proto": "https",
      "x-forwarded-server": "6de0a38d2bbe",
      "x-lando": "on",
      "x-real-ip": "172.19.0.1",
      "x-wp-nonce": "258a8aed3b"
    },
    "existingHeader": "application/json",
    "caseInsensitiveExistingHeader": "application/json",
    "nonExistingHeader": null,
    "existingHasHeader": true,
    "caseInsensitiveExistingHasHeader": true,
    "nonExistingHasHeader": false,
    "_httpRequestBody": "{\"query\":\"{\\n  _httpRequestHeaders\\n  existingHeader: _httpRequestHeader(name: \\\"Accept\\\")\\n  caseInsensitiveExistingHeader: _httpRequestHeader(name: \\\"accept\\\")\\n  nonExistingHeader: _httpRequestHeader(name: \\\"Non-existing\\\")\\n  existingHasHeader: _httpRequestHasHeader(name: \\\"Accept\\\")\\n  caseInsensitiveExistingHasHeader: _httpRequestHasHeader(name: \\\"accept\\\")\\n  nonExistingHasHeader: _httpRequestHasHeader(name: \\\"Non-existing\\\")\\n  _httpRequestBody\\n  _httpRequestMethod\\n  _httpRequestDomain\\n  _httpRequestScheme\\n  _httpRequestHost\\n  _httpRequestURL\\n  _httpRequestFullURL\\n  _httpRequestURLPath\\n  _httpRequestQuery\\n  _httpRequestParams\\n  existingParam: _httpRequestStringParam(name: \\\"page\\\")\\n  caseInsensitiveExistingParam: _httpRequestStringParam(name: \\\"PAge\\\")\\n  existingArrayParam: _httpRequestStringListParam(name: \\\"someArray\\\")\\n  nonExistingParam: _httpRequestStringParam(name: \\\"also-non-existing\\\")\\n  nonExistingListParam: _httpRequestStringListParam(name: \\\"also-non-existing\\\")\\n  existingHasParam: _httpRequestHasParam(name: \\\"page\\\")\\n  caseInsensitiveExistingHasParam: _httpRequestHasParam(name: \\\"PAge\\\")\\n  nonExistingHasParam: _httpRequestHasParam(name: \\\"also-non-existing\\\")\\n  existingCookie: _httpRequestCookie(name: \\\"wordpress_test_cookie\\\")\\n  caseInsentiveExistingCookie: _httpRequestCookie(name: \\\"Wordpress_Test_Cookie\\\")\\n  nonExistingCookie: _httpRequestCookie(name: \\\"not_existing\\\")\\n  existingHasCookie: _httpRequestHasCookie(name: \\\"wordpress_test_cookie\\\")\\n  caseInsentiveExistingHasCookie: _httpRequestHasCookie(name: \\\"Wordpress_Test_Cookie\\\")\\n  nonExistingHasCookie: _httpRequestHasCookie(name: \\\"not_existing\\\")\\n  _httpRequestProtocol\\n  _httpRequestReferer\\n  _httpRequestServerIP\\n  _httpRequestClientIP\\n  _httpRequestClientHost\\n  _httpRequestUserAgent\\n\\n  _httpRequestCookies\\n  _httpRequestRequestTime\\n}\",\"variables\":{\"postID\":40,\"translateToLang\":\"es\"}}",
    "_httpRequestMethod": "POST",
    "_httpRequestDomain": "lndo.site",
    "_httpRequestScheme": "https",
    "_httpRequestHost": "gato-graphql-pro.lndo.site",
    "_httpRequestURL": "https://gato-graphql-pro.lndo.site/wp-admin/edit.php",
    "_httpRequestFullURL": "https://gato-graphql-pro.lndo.site/wp-admin/edit.php?page=gatographql&action=run_query",
    "_httpRequestURLPath": "/wp-admin/edit.php",
    "_httpRequestQuery": "page=gatographql&action=run_query",
    "_httpRequestParams": {
      "page": "gatographql",
      "action": "run_query"
    },
    "existingParam": "gatographql",
    "caseInsensitiveExistingParam": null,
    "existingArrayParam": null,
    "nonExistingParam": null,
    "nonExistingListParam": null,
    "existingHasParam": true,
    "caseInsensitiveExistingHasParam": false,
    "nonExistingHasParam": false,
    "existingCookie": "WP Cookie check",
    "caseInsentiveExistingCookie": null,
    "nonExistingCookie": null,
    "existingHasCookie": true,
    "caseInsentiveExistingHasCookie": false,
    "nonExistingHasCookie": false,
    "_httpRequestProtocol": "HTTP/1.1",
    "_httpRequestReferer": "https://gato-graphql-pro.lndo.site/wp-admin/admin.php?page=gatographql&query=%7B%0A%20%20_httpRequestHeaders%0A%20%20existingHeader%3A%20_httpRequestHeader(name%3A%20%22Accept%22)%0A%20%20caseInsensitiveExistingHeader%3A%20_httpRequestHeader(name%3A%20%22accept%22)%0A%20%20nonExistingHeader%3A%20_httpRequestHeader(name%3A%20%22Non-existing%22)%0A%20%20existingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22Accept%22)%0A%20%20caseInsensitiveExistingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22accept%22)%0A%20%20nonExistingHasHeader%3A%20_httpRequestHasHeader(name%3A%20%22Non-existing%22)%0A%20%20_httpRequestBody%0A%20%20_httpRequestMethod%0A%20%20_httpRequestDomain%0A%20%20_httpRequestScheme%0A%20%20_httpRequestHost%0A%20%20_httpRequestURL%0A%20%20_httpRequestFullURL%0A%20%20_httpRequestURLPath%0A%20%20_httpRequestQuery%0A%20%20_httpRequestParams%0A%20%20existingParam%3A%20_httpRequestStringParam(name%3A%20%22page%22)%0A%20%20caseInsensitiveExistingParam%3A%20_httpRequestStringParam(name%3A%20%22PAge%22)%0A%20%20existingArrayParam%3A%20_httpRequestStringListParam(name%3A%20%22someArray%22)%0A%20%20nonExistingParam%3A%20_httpRequestStringParam(name%3A%20%22also-non-existing%22)%0A%20%20nonExistingListParam%3A%20_httpRequestStringListParam(name%3A%20%22also-non-existing%22)%0A%20%20existingHasParam%3A%20_httpRequestHasParam(name%3A%20%22page%22)%0A%20%20caseInsensitiveExistingHasParam%3A%20_httpRequestHasParam(name%3A%20%22PAge%22)%0A%20%20nonExistingHasParam%3A%20_httpRequestHasParam(name%3A%20%22also-non-existing%22)%0A%20%20existingCookie%3A%20_httpRequestCookie(name%3A%20%22wordpress_test_cookie%22)%0A%20%20caseInsentiveExistingCookie%3A%20_httpRequestCookie(name%3A%20%22Wordpress_Test_Cookie%22)%0A%20%20nonExistingCookie%3A%20_httpRequestCookie(name%3A%20%22not_existing%22)%0A%20%20existingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22wordpress_test_cookie%22)%0A%20%20caseInsentiveExistingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22Wordpress_Test_Cookie%22)%0A%20%20nonExistingHasCookie%3A%20_httpRequestHasCookie(name%3A%20%22not_existing%22)%0A%20%20_httpRequestProtocol%0A%20%20_httpRequestReferer%0A%20%20_httpRequestServerIP%0A%20%20_httpRequestClientIP%0A%20%20_httpRequestClientHost%0A%20%20_httpRequestUserAgent%0A%0A%20%20_httpRequestCookies%0A%20%20_httpRequestRequestTime%0A%7D&variables=%7B%2B%2B%22postID%22%3A%2B40%2C%2B%2B%22translateToLang%22%3A%2B%22es%22%7D&operationName=SendEmail",
    "_httpRequestServerIP": "172.19.0.4",
    "_httpRequestClientIP": "172.19.0.2",
    "_httpRequestClientHost": null,
    "_httpRequestUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/114.0",
    "_httpRequestCookies": {
      "wordpress_sec_f21902903273c44cc3a47d07e23af599": "admin|1687924210|cMlLArK65w5nACJHlglLMMd52rRVZRmu2LRUJmCi7n1|ad6b03a20093f342a4107076432f7857e244174ab4d866c1887417c2e304e3fe",
      "wp-settings-time-1": "1686559494",
      "wp-settings-1": "libraryContent=browse",
      "wordpress_test_cookie": "WP Cookie check",
      "wp_lang": "en_US",
      "wordpress_logged_in_f21902903273c44cc3a47d07e23af599": "admin|1687924210|cMlLArK65w5nACJHlglLMMd52rRVZRmu2LRUJmCi7n1|0ec85ac4a275aff3c464e139d40061aa0062a4e7376666b99ec8063a6715788a"
    },
    "_httpRequestRequestTime": 1687836456
  }
}