Ashwani
Ashwani

Reputation: 545

Curl post returning bad request in HaProxy http-request redirect configuration

Here im trying to rewrite the URL in HaProxy, the get method is working as expected but I'm facing issue with the POST method; Elaborating the issue below

What im trying to do:

Whenever someone request for http://preprod.mydomain.com/app_a/* it should go to >> http://preprod.mydomain.com/something/app_a/*(It's Working as expected with GET method)

My HaProxy configuration:

acl mydomain_domain hdr(host) -i preprod.mydomain.com
acl app_a_redirection path_beg  -i /app_a

http-request set-header X-Location-Path %[capture.req.uri] if app_a_redirection mydomain_domain
http-request replace-header X-Location-Path [^/]+/(.*) \1 if app_a_redirection mydomain_domain
http-request redirect location http://preprod.mydomain.com/something/app_a/%[hdr(X-Location-Path)] code 307 if app_a_redirection mydomain_domain

Adding Error details while POST:

    Request URL:    
    curl --location --request POST 'https://preprod.mydomain.com/app_a/something-1/something-2' \
        --header 'Content-Type: application/json' \
        --data-raw '{
            "user_id": "xxxxxxxxxxxx",
            "app_id": "xxxxxxxxxxxx",
            "app_version": "1.0.0",
            "client_session_id": "xxxxxxxxxxxx",
            "xpath": "xxxxxxxxxxxx",
            "device_id": "xxxxxxxxxxxx",
            "events": "xxxxxxxxxxxx"
        }'
Error: {"timestamp":"2020-08-18T06:57:16.037+0000","status":400,"error":"Bad Request","message":"Required request body is missing: public com.mydomain.something.response.UploadedEventResponse com.mydomain.something.controllers.MobileAppController.postAppEvents(com.mydomain.something.core.models.request.EventsDTO) throws java.lang.Exception","path":"/something/app_a/something-1/something-2"}

Upvotes: 0

Views: 490

Answers (1)

Aleksandar
Aleksandar

Reputation: 2672

POST and redirect does not work as you expect. See Post/Redirect/Get for the flow.

Looks like you want to set the path instead of a redirect.

Try this, untested

http-request set-path http://preprod.mydomain.com/something/app_a/%[hdr(X-Location-Path)] if app_a_redirection mydomain_domain

Doc link: http-request set-path

Upvotes: 1

Related Questions