Open conan opened 6 years ago
I think at least :query-string
should be s/nillable
. Both Immutant and Aleph use custom Map implementations with predefined keys but the implementations read the values directly from underlaying implementations, which can return nil
.
If the Jetty adapter is doing the wrong thing it should be fixed.
I'm not sure whether the best thing to do is to make the keys nillable. I currently lean toward not, as that gives more relevance to contains?
, e.g. (contains? request :query-string)
. I'm also reluctant to treat nil
and a missing key as being the same, if Clojure spec itself treats them differently.
If Immutant and Aleph use a custom map implementation, I don't see any reason why they also can't dictate a key as being missing.
Both Aleph & Immutant use zero-copy requests where the shape of the request needs to be defined forehand and the values are lazily fetched on-demand from the underlaying impementation (Netty or Undertow). This is a big win in performance, but can't strip away keys (in a performant way).
If get
is calculated on the fly, then contains?
can be as well. The only performance hit would be in keys
, but arguably it would return better information as a result.
In terms of pros and cons, here's how I see it:
contains?
and keys
become much less useful:headers
), more things would become nillable as wellI'm not quite sure what the best option is. My inclination is that allowing nils would make life a little easier for adapter writers, but might make the job of end developers a little more complex. My current inclination is to side with the latter, but I'm open to convincing.
I don't have a strong argument either way. My feeling from an idiomatic perspective is that nil
should not be allowed, but my feeling from a pragmatic perspective is that this issue can be fixed more easily if they are. Though my inner aesthete complains, I think I'd also side with the latter because I haven't been able to find any complaints about the current behaviour that allows nil
s, and I'd rather the issue was fixed than not. Not very helpful, sorry.
I've tried using both jetty and httpkit, in both cases my request maps contain
nil
values for the optional keys:body
and:query-string
; this is not compliant with the:ring/request
spec. Is it possible to remove the keys from the request map instead of setting them tonil
in order to remain spec compliant?