Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the route extension. #99

Closed
brunonymous opened this issue Feb 11, 2020 · 2 comments
Closed

Disable the route extension. #99

brunonymous opened this issue Feb 11, 2020 · 2 comments

Comments

@brunonymous
Copy link

Hello,

Is it possible to disable the route extension (I use Raisin 0.82)?

The following function does not work:
api_format 'json';

Due to the route extension, URLs path containing the dot character return the HTTP 406 error:

curl -v http://localhost:5000/api/v1/websites/foobar.com
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET /api/v1/websites/foobar.com HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 406 Not Acceptable-
< Transfer-Encoding: chunked
< Date: Tue, 11 Feb 2020 15:19:19 GMT
< Connection: keep-alive
< 
* Connection #0 to host localhost left intact

If the negotiate_format () method detects a point in the URL path, then this is automatically used as a format :

        if (_path_has_extension($req->path)) {
            $self->format_from_extension($req->path);
        }
        elsif (_accept_header_set($req->header('Accept'))) {
            # In case of wildcard matches, we default to first allowed format
            $self->format_from_header($req->header('Accept'), $allowed_formats[0]);
        }
        else {
            $self->default_format;
        }
    };

The code patched as follows works a little better:

        my $format;
        if (_path_has_extension($req->path)) {
            $format = $self->format_from_extension($req->path);
        }
        return $format if defined $format;
        if (_accept_header_set($req->header('Accept'))) {
            # In case of wildcard matches, we default to first allowed format
            $self->format_from_header($req->header('Accept'), $allowed_formats[0]);
        }
        else {
            $self->default_format;
        }
    };

But unfortunately the route param is "foobar" instead of "foobar.com".

What is the best practice for disabling the route extension?

Thank you in advance.

@khrt
Copy link
Owner

khrt commented Feb 11, 2020

This is related to #14

@brunonymous
Copy link
Author

Sorry, i hadn't seen this issue. So the only solution for now is to specify the .json extension at the end of the URL:
curl -v http://localhost:5000/api/v1/websites/foobar.com.json

Until a better solution is found. :-) Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants