playwright
playwright copied to clipboard
[BUG] Requests don't preserve the HTTP method on redirects
Source code
- [x] I provided exact source code that allows reproducing the issue locally.
Server
// server.js
const express = require('express')
const app = express()
app.post('/test', (request, response) => {
if (request.get('host').includes('localhost')) { // or any other condition...
response.redirect('http://127.0.0.1:3000/test')
} else {
response.json({ method: 'post' })
}
})
app.get('/test', (_, response) => {
response.json({ method: 'get' })
})
app.listen(3000, () => {
console.log('Server is listening...')
})
Client
// client.mjs
import { request } from '@playwright/test'
const requestContext = await request.newContext()
const response = await requestContext.post('http://localhost:3000/test')
const json = await response.json()
console.log({ json })
Steps
- Start the demo server
node server.js. - When the server is running, start the client
node client.mjs.
Expected
{ json: { method: 'post' } } should be printed to the console.
Actual
{ json: { method: 'get' } } is being printed to the console.
Comment
This particular case could be handled by the client automatically or an additional option could be added. For example, Postman has Follow original HTTP Method option in settings.
@gskierk APIRequestContext follows the fetch spec, step 12. I'd recommend to pass maxRedirects: 0, and then follow the redirect manually.
@dgozman It sounds reasonable enough to me. Also, I can confirm that handling it manually works without any issues.