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

Adjusting the max POST body size #228

Open
namooh opened this issue Sep 11, 2015 · 6 comments
Open

Adjusting the max POST body size #228

namooh opened this issue Sep 11, 2015 · 6 comments

Comments

@namooh
Copy link

namooh commented Sep 11, 2015

I would like to adjust the POST max body size for my server, as 200KB default is pretty low for my use case. I have found the solution to modify the jetty server: https://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size

The solution is basically to set the system property org.eclipse.jetty.server.Request.maxFormContentSize. This can be done in leiningen easily, but is not very production friendly.

Is there anyway to set this property in Ring? It would be great if run-jetty function accepts the argument above.

@weavejester
Copy link
Member

You might be able to set this via .setAttribute on the server instance. So something like:

(run-jetty
 handler
 {:port 3000
  :configurator #(.setAttribute % "org.eclipse.jetty.server.Request.maxFormContentSize" -1)})

Let me know if that works.

@namooh
Copy link
Author

namooh commented Sep 11, 2015

@weavejester Thanks. I tried this but it did not affect the behavior of the server. I think the maxFormContentSize is first set from ContextHandler and falls back to the server attribute if there is no context.

From Jetty 7.6 Java Docs

The form content that a request can process is limited to protect from Denial of Service attacks. The size in bytes is limited by ContextHandler.getMaxFormContentSize() or if there is no context then the "org.eclipse.jetty.server.Request.maxFormContentSize" Server attribute. The number of parameters keys is limited by ContextHandler.getMaxFormKeys() or if there is no context then the "org.eclipse.jetty.server.Request.maxFormKeys" Server attribute.

Do you know if Ring uses a Context handler by default, and if so where to get it?

@weavejester
Copy link
Member

Unfortunately I don't know. Jetty is labyrinthine in its class structure, and none of it is documented beyond a minimal set of Javadocs. I tried to figure out where the ContextHandler is introduced, but I think it'll require a significant investment of time going through the source code.

Also, the Jetty version is 9, so the Jetty 7.6 docs you have might be outdated.

@weavejester
Copy link
Member

Perhaps the best option is simply to use another adapter, like Ring-Undertow or Http-Kit. It's a bit of a cop-out, but it might save you time in the long run.

@namooh
Copy link
Author

namooh commented Sep 11, 2015

@weavejester Thank you. I was lost in Jetty Docs and source code as well. I am thinking to change the adaptor to http-kit as it allows to explicitly set max-body-size.

@jszakmeister
Copy link

@namooh How do you know this is the right approach? What did you see that led you to this being the knob that needed to be adjusted? I ask because from my reading of the Jetty docs and examples, I don't think Jetty is introducing a ContextHandler itself. It sounds like the approach is to set a ContextHandler as the handler for the server instance. Perhaps something like this:

(let [server (create-server (dissoc options :configurator))
      proxyf (if (:async? options) async-proxy-handler proxy-handler)
      context-handler (ContextHandler. (proxyf handler))]
  (when-let [max-form-content-size (:max-form-content-size options)]
    (.maxFormContentSize context-handler max-form-content-size))
  (.setHandler server context-handler)
  (when-let [configurator (:configurator options)]
    (configurator server))
  (try
    (.start server)
    (when (:join? options true)
      (.join server))
    server
    (catch Exception ex
      (.stop server)
      (throw ex))))

Note: the above is completely untested, but seems to be what is suggested by the Jetty docs (though we may have to set a prefix too). This is what I'm basing this on: https://www.eclipse.org/jetty/documentation/9.3.x/embedding-jetty.html#_embedding_contexts

But, I'm not convinced that it's a ContextHandler problem. Perhaps in this case, it's really some other size that's not adjusted properly for your situation.

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

No branches or pull requests

3 participants