Welcome Guest, Not a member yet? Register   Sign In
Segment length in uri problem
#1

Hi
I've defined a new route as

Code:
$routes->get('/opendata/(:segment)', 'Tools::openData/$1');

This Tools/openData controller/fuction receives 1 parameter, which is a base64 encoded string of about (average) 500 characters

I've tried with
Code:
https://myApp.com/opendata/dGhpc2lzanVzdGF0ZXN0dGhpc2lzanVzdGF0ZXN0dGhpc2lzanVzdGF0ZXN0dGhpc2lzanVzdGF0ZXN0dGhpc2lzanVzdGF0ZXN0dGhpc2lzanVzdGF0ZXN0
120 characters approx and everything works fine.

Now, I've tried with a real world example which is about 500 char. long and I get a 404 error

1. Any workaround or config setting to allow this ?

2. Any function that could shorten/compress this string (without database, cookies, etc.) univocally so it can work without modifying anything else?

Thanks a lot
Reply
#2

All work.

Code:
CodeIgniter\HTTP\IncomingRequest {#20 ▼
  #protocolVersion: "1.1"
  #validProtocolVersions: array:4 [▶]
  #body: null
  #headers: array:16 [▶]
  #headerMap: array:16 [▶]
  #method: "GET"
  +uri: CodeIgniter\HTTP\SiteURI {#23 ▶}
  #proxyIPs: null
  #ipAddress: "::1"
  #globals: array:3 [▶]
  #enableCSRF: false
  #path: "opendata/VGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2VUZXN0UGhyYXNlVGVzdFBocmFzZVRlc3RQaHJhc2U= ◀"
  #files: null
  #negotiator: null
  #defaultLocale: "ru"
  #locale: "ru"
  #validLocales: array:2 [▶]
  +config: Config\App {#8 ▶}
  #oldInput: []
  #userAgent: CodeIgniter\HTTP\UserAgent {#25 ▶}
}
Simple CI 4 project for beginners codeigniter-expenses
Reply
#3

What ?
Don't you get 404 when throwing segments of 500 char long?

Ouch .. then how could I debug the 404 error I'm getting? I've enabled debug, debugbar etc. but cannot get anything useful about the 404 it is throwing

Also, the apache server has no extra config or anything weird about it. Same with PHP. Both std installations

Thanks again
Reply
#4

Base64 string can contain "/". If your string contains "/", it is not a single segment.
Try "(:any)". But a controller parameter only gets one segment. You need to use "...$params" to get multiple segments.
Reply
#5

(This post was last modified: 09-07-2023, 10:49 PM by InsiteFX.)

Code:
Maximum URL length for web servers and CDNs
-------------------------------------------
Apache: 8,177 characters.
NGINX: 4,096 characters.
Microsoft IIS: 16,384 characters.
Fastly (CDN): 8,192 characters.
Amazon Cloudfront (CDN): 8,192 characters.
Cloudflare (CDN): 32,768 characters.

Max size of URL parameters in _GET
-----------------------------------
In PHP, the maximum size of the parameters in a GET request is determined by the server's configuration.
The default value is often around 2MB, but it can be increased or decreased depending on the server's settings.
The specific value can be found in the server's php.ini file in the variables post_max_size and upload_max_filesize.
.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(This post was last modified: 09-08-2023, 05:15 AM by kabeza.)

(09-07-2023, 02:53 PM)kenjis Wrote: Base64 string can contain "/". If your string contains "/", it is not a single segment.
Try "(:any)". But a controller parameter only gets one segment. You need to use "...$params" to get multiple segments.

Wow, you're right. That was it. I've found a / in the 500char string
I've found these functions on internet that seems to work and handle the / = chars

Code:
   
function base64UrlEncode(string $data): string
    {
        $base64Url = strtr(base64_encode($data), '+/', '-_');
        return rtrim($base64Url, '=');
    }
   
    function base64UrlDecode(string $base64Url): string
    {
        return base64_decode(strtr($base64Url, '-_', '+/'));
    }

Thanks again

(09-07-2023, 10:43 PM)InsiteFX Wrote:
Code:
Maximum URL length for web servers and CDNs
-------------------------------------------
Apache: 8,177 characters.
NGINX: 4,096 characters.
Microsoft IIS: 16,384 characters.
Fastly (CDN): 8,192 characters.
Amazon Cloudfront (CDN): 8,192 characters.
Cloudflare (CDN): 32,768 characters.

Max size of URL parameters in _GET
-----------------------------------
In PHP, the maximum size of the parameters in a GET request is determined by the server's configuration.
The default value is often around 2MB, but it can be increased or decreased depending on the server's settings.
The specific value can be found in the server's php.ini file in the variables post_max_size and upload_max_filesize.
.

Thanks a lot 4 the useful info
Reply
#7

Try using urlencode.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

(09-08-2023, 09:07 PM)InsiteFX Wrote: Try using urlencode.

added urlencode in the above shared functions and working great!
Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB