-
Notifications
You must be signed in to change notification settings - Fork 33
Fix Rack 3.2 compatibility #180
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
Conversation
|
Looks like this may be difficult to do compatibly from Rack 2 through 3.2 🙁 |
You can always check the rack version and add a small compatibility layer. |
6702a97 to
b678ae9
Compare
Done 👍 I think this should be good now |
lib/pitchfork.rb
Outdated
| rescue LoadError | ||
| warn 'rack not available, functionality reduced' | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pitchfork has a runtime dependency on rack. So this shouldn't be needed.
lib/pitchfork.rb
Outdated
| singleton_class.attr_accessor :path_info_requires_leading_slash | ||
| self.path_info_requires_leading_slash = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just make this a constant.
Rack is a dependency in the gemspec
b678ae9 to
e0e1f3d
Compare
byroot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/pitchfork/http_parser.rb
Outdated
| e['pitchfork.socket'] = socket | ||
| e['rack.hijack'] = self | ||
|
|
||
| if Pitchfork::PATH_INFO_REQUIRES_LEADING_SLASH && e['PATH_INFO'] == '*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if Pitchfork::PATH_INFO_REQUIRES_LEADING_SLASH && e['PATH_INFO'] == '*' | |
| if PATH_INFO_REQUIRES_LEADING_SLASH && e['PATH_INFO'] == '*' |
nitpick
One of the changes in Rack 3.2 was a fix to ensure at least one of
PATH_INFO or SCRIPT_NAME are non-empty. This causes a Rack::Lint error
in Pitchfork for `OPTIONS *` requests because Pitchfork has a `nil`
`PATH_INFO` for these.
This commit fixes the issue by setting `PATH_INFO` to `*`. It also undoes
some of the previous changes from the [commit][1] to support Rack 3.1
because they appear to have no effect.
The undone change is the moving of `PATH_INFO = "*"` and `REQUEST_PATH =
"*"` to the `fragment` action. From what I can tell, this part of the
state machine is not involved with the request uri, and so this if
statement is not evaluated in `OPTIONS *` requests:
```
Request_Line = ( Method " " Request_URI ("#" Fragment){0,1} " " HTTP_Version CRLF ) ;
```
Then, the actual fix is manually setting the `PATH_INFO` to `*` when
that's the given `REQUEST_URI`. Normally, `PATH_INFO` is handled in the
`request_uri` action, but that action is only run for URIs starting with
`/` (and explicitly excludes `*`).
[1]: 65725c5
e0e1f3d to
9e5308e
Compare
One of the changes in Rack 3.2 was a fix to ensure at least one of PATH_INFO or SCRIPT_NAME are non-empty. This causes a Rack::Lint error in Pitchfork for
OPTIONS *requests because Pitchfork has anilPATH_INFOfor these.This commit fixes the issue by setting
PATH_INFOto*. It also undoes some of the previous changes from the commit to support Rack 3.1 because they appear to have no effect.The undone change is the moving of
PATH_INFO = "*"andREQUEST_PATH = "*"to thefragmentaction. From what I can tell, this part of the state machine is not involved with the request uri, and so this if statement is not evaluated inOPTIONS *requests:Then, the actual fix is manually setting the
PATH_INFOto*when that's the givenREQUEST_URI. Normally,PATH_INFOis handled in therequest_uriaction, but that action is only run for URIs starting with/(and explicitly excludes*).