While using subrequests I ran into the issue that my responses din't contain the correct base url but always referred to localhost.
For example images were listed as http://localhost/sites/default/files/... instead of the correct http://website_base_url/sites/default/files/... This wasn't the case in individual requests but only appeared while using subrequests.
After some experimenting I noticed that besides the X-Consumer-ID (*) it's also needed to include a Host in the request headers. After adding a host in my request headers the correct base url was determined based on my Host parameter.
(*) Besides that the X-Consumer-ID is needed to retrieve the correct image styles while using the consumer_image_styles module.
This isn't a bug or issue but worth mentioning for others running into this in the future.
Comment | File | Size | Author |
---|---|---|---|
#9 | 2938013--fwd-host-header--9.patch | 2.28 KB | e0ipso |
| |||
#6 | 2938013--fwd-host-header--6.patch | 1.82 KB | e0ipso |
| |||
#5 | 2938013--fwd-host-header--5.patch | 1.82 KB | e0ipso |
|
Comments
Comment #2
e0ipsoCan you please post:
localhost
problem along with the response?Thanks for the report!
Comment #3
smanhoff CreditAttribution: smanhoff commentedFirst I used following request to retrieve a node based on url, while using the decoupled router module:
But this only got me the following response:
As you can see it always uses localhost instead of the correct base_url. When using the exact same request without subrequests this doesn't occur. So after some digging I figured out that this could be resolved by applying the Host parameter in my request header:
And now based on the Host parameter the correct base url is used throughout the response:
"body": "{"resolved":"host_url/homepage","entity":{"canonical":"host_url/homepage","type":"node","bundle":"homepage","id":"9","uuid":"4e1f5a9b-5ed6-484f-ac21-583612fa21df"},"jsonapi":{"individual":"host_url/jsonapi/node/homepage/4e1f5a9b-5ed6-484f-ac21-583612fa21df","resourceName":"node--homepage","pathPrefix":"jsonapi"}}"
Comment #4
e0ipsoI think it makes sense to forward the Host header to subrequests.
Comment #5
e0ipso@Sander Hofman can you please see if this patch solves the issue?
Many thanks!
Comment #6
e0ipsoThere was a typo in the patch above. Correcting.
Comment #7
smanhoff CreditAttribution: smanhoff commented@e0ipso
Above patch doesn't seem to resolve the issue.
It seems the if statement never gets executed due to the host (localhost) is always included in the $to headers.
If I always forward the master host to the subrequest it seems to work fine but this may cause some unexpected behavior maybe?
Comment #8
e0ipso:-( you are right, Symfony must be setting that under the hood. We need to check the presence of the header in the blueprint. But in that point it's hard to inject the parent's header.
Comment #9
e0ipso@Sander Hofman can you test this one? I don't have a proper environment currently so I'm shooting in the dark.
Comment #11
ziomizar CreditAttribution: ziomizar at Station commented@e0ipso i tested the patch in #9 and it works for me. Thanks
Without patch i have localhost in the response. After apply the patch applyed i get the correct base url of the site.
Comment #12
ziomizar CreditAttribution: ziomizar at Station commentedComment #14
e0ipsoThanks everyone!