HTTP 303 Oracle ORDS

Sep 10 2020

Devo reindirizzare l'utente a un altro endpoint dopo aver effettuato un POST, ma l'altro endpoint accetta solo richieste GET.

Come dice wiki il codice HTTP 303 dovrebbe dire al client di inviare una richiesta a un'altra posizione e cambiare il metodo in GET:

Se un server risponde a una richiesta POST o altra richiesta non idempotente con una risposta 303 Vedi Altro e un valore per l'intestazione della posizione, il client dovrebbe ottenere la risorsa menzionata nell'intestazione della posizione utilizzando il metodo GET ( origine ).

Ma dopo la risposta il client reindirizza utilizzando nuovamente il POST. Ho testato l'endpoint con Insomnia ed ecco l'output della timeline:

* Preparing request to http://******:8080/ords/demo/llmob.test_post_david
* Current time is 2020-09-10T07:21:09.418Z
* Using libcurl/7.69.1 OpenSSL/1.1.1e zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libssh2/1.9.0 nghttp2/1.29.0
* Using default HTTP version
* Disable timeout
* Enable automatic URL encoding
* Enable SSL validation
* Enable cookie sending with jar of 5 cookies
* Connection 21 seems to be dead!
* Closing connection 21
* Hostname ****** was found in DNS cache
*   Trying 192.168.254.135:8080...
* Connected to ****** (192.168.254.135) port 8080 (#22)

> POST /ords/demo/llmob.test_post_david HTTP/1.1
> Host: ******:8080
> User-Agent: insomnia/2020.3.3
> Access-Control-Allow-Origin: *
> Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> Accept: */*
> Content-Length: 433

| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="ShoppingCartID"
| 78


* We are completely uploaded and fine
* Mark bundle as not supporting multiuse

< HTTP/1.1 303 
< Location: http://******:8080/ords/devapex/sbas/r/self-check-out159/odobreno
< Transfer-Encoding: chunked
< Date: Thu, 10 Sep 2020 07:21:10 GMT


* Ignoring the response-body
* Received 5 B chunk
* Connection #22 to host ****** left intact
* Issue another request to this URL: 'http://******:8080/ords/devapex/sbas/r/self-check-out159/odobreno'
* Disables POST, goes with GET
* Found bundle for host ******: 0x1497368c8870 [serially]
* Can not multiplex, even if we wanted to!
* Re-using existing connection! (#22) with host ******
* Connected to ****** (192.168.254.135) port 8080 (#22)

> POST /ords/devapex/sbas/r/self-check-out159/odobreno HTTP/1.1
> Host: ******:8080
> User-Agent: insomnia/2020.3.3
> Access-Control-Allow-Origin: *
> Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> Accept: */*
> Content-Length: 433

| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="ShoppingCartID"
| 78

* We are completely uploaded and fine
* Mark bundle as not supporting multiuse

< HTTP/1.1 405 
< Allow: GET
< Content-Type: text/html
< Content-Length: 15798
< Date: Thu, 10 Sep 2020 07:21:10 GMT


* Received 7.9 KB chunk
* Received 7.5 KB chunk
* Connection #22 to host ****** left intact

La prima risposta viene generata con il OWA_UTILpacchetto come segue:

 owa_util.status_line(
                         nstatus=> 303, bclose_header=> false
                         );
                         
   owa_util.redirect_url(
             curl         => 'http://******:8080/ords/devapex/sbas/r/self-check-out159/odobreno',
            bclose_header  =>TRUE
            );

ORDS versione 18.4.

Aggiornare

Quando la stessa richiesta viene emessa dal browser, il codice di risposta è 403 (errore di seguito) e il reindirizzamento non avviene mai.

La richiesta non può essere elaborata perché questa risorsa non supporta le richieste di condivisione Cross Origin o la richiesta Origin non è autorizzata ad accedere a questa risorsa. Se ords viene inviato tramite proxy inverso, assicurati che il server front-end stia propagando il nome host, per mod_proxy assicurati che ProxyPreserveHost sia impostato su On

Risposte

EJEgyed Sep 22 2020 at 20:59

Se l'endpoint a cui stai tentando di inoltrare l'utente si trova nello stesso host / modulo, puoi utilizzare il :FORWARD_LOCATIONparametro bind implicito introdotto in ORDS 18.3.

In caso contrario, invece di utilizzare OWA_UTILper impostare la nuova posizione a cui deve essere reindirizzato l'utente, prova a utilizzare le intestazioni di risposta ORDS. Ho un esempio di come farlo qui .