From fd44cd53734a7b1a18343e11682a548f63ebbc50 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Thu, 18 May 2017 11:05:21 +0200 Subject: Do not follow redirect for HTTP 201 Created because that can send the Location of the new resource --- it_url.class | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'it_url.class') diff --git a/it_url.class b/it_url.class index 4f184ac..2b1ee18 100644 --- a/it_url.class +++ b/it_url.class @@ -129,7 +129,8 @@ function get($p=null, $timeout=5) else $result = $url->request_curl($p); - if ($url->headers['Location'] && preg_match('#^(https?://[^/]*)?(/)?(.*)$#i', $url->headers['Location'], $parts) && ($parts[1] != $url->url)) # Handle redirects (supports relative and global) + # Handle redirects (supports relative and global) but not for HTTP 201 Created because that can send the Location of the new resource + if ($url->headers['Location'] && $url->result != 201 && preg_match('#^(https?://[^/]*)?(/)?(.*)$#i', $url->headers['Location'], $parts) && ($parts[1] != $url->url)) { unset($p['url'], $p['headers']['Host']); $url->it_url($parts[1] ? $parts[1].$parts[2].$parts[3] : $url->protocol.'://'.$url->realhostname.($parts[2] ? $parts[2].$parts[3] : '/'.dirname($url->path).'/'.$parts[3])); -- cgit v1.2.3