Fork me on GitHub
#pedestal
<
2016-10-03
>
ul14:10:43

hi there! i'm trying to make simple proxy endpoint in my service, and write it like this

(defn image-proxy [request]
  (-> request
      (get-in [:params :url])
      (client/get)
      (deref)
      (select-keys [:status :headers :body])
      (update :headers #(encore/map-keys name %))))

(def routes #{["/proxy" :get [`proxy]]})
But when I visit http://localhost:8080/proxy?url=http://google.com I get an error: `

mtnygard14:10:23

Hi @ul. I can help

mtnygard14:10:28

The error didn’t come through though.

ul14:10:43

one second, will put it into gist, too big to flood the chat

mtnygard14:10:10

That is a sizeable error all right.

ul14:10:11

Essentially it is Caused by: org.xnio.channels.FixedLengthOverflowException: null

ul14:10:33

Would you mind explaining me? I'm lost honestly speaking

ul14:10:45

I plan to use this proxy endpoint to convey images to my app's canvas. To allow canvas to be snapshotted they must come from my domain, thus need for proxy

mtnygard14:10:49

I’m looking at the stack trace, and I notice Undertow in the mix.

mtnygard14:10:07

Could you try the same thing with Jetty as the container? Just to see if it’s specific to Undertow

ul14:10:13

yes, i use io.pedestal/pedestal.immutant

ul14:10:21

just a sec

mtnygard14:10:32

OK, that helps a lot.

mtnygard14:10:58

I think the issue is that when you do (select-keys) from the Google response, you’re picking up the Content-Length header. But the body is somehow now exactly the same length.

mtnygard14:10:08

That’s what those errors each indicate in their own special way.

mtnygard14:10:22

Just that Content-Length doesn’t match the number of bytes sent

ul14:10:35

Aha! Not obvious... Thank you very much! I think I can just drop that header?

mtnygard14:10:50

I think so. The server should fill it in for you

mtnygard14:10:19

I’d be concerned about some of the other headers that Google offers… like the privacy policy. IDK if it’s legit to just pass that along.

mtnygard14:10:24

But it should work for your images.

ul14:10:00

perhaps the best would be to define whitelist of headers safe to pass, like content-type

ul14:10:13

thank you very much!

mtnygard14:10:14

That makes sense

mtnygard15:10:27

New doc published. Covers error handling and the pattern-matching error-dispatch macro.

mtnygard15:10:53

As always, I welcome bug reports and pull requests.

grzm15:10:00

that looks really useful. Thanks, mtnygard!