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

Process hangs if request follows a redirection (node.js) #64

Open
ozanmakes opened this issue Feb 22, 2016 · 5 comments
Open

Process hangs if request follows a redirection (node.js) #64

ozanmakes opened this issue Feb 22, 2016 · 5 comments

Comments

@ozanmakes
Copy link

Seems to be caused by the underlying lib xhr2.

main =
  launchAff $
  do res <- get "http://news.ycombinator.com"
     liftEff $ log res.response

This waits about 45 seconds after printing. Getting https://news.ycombinator.com works fine.

I already reported it to upstream but wanted to give you a heads up.

@jdegoes
Copy link
Contributor

jdegoes commented Feb 25, 2016

@osener Thanks for reporting!

@artemyarulin
Copy link

xhr2 doesn't look very active. I guess the most popular Node lib is https://github.com/request/request, what do you think - how difficult would be a transition to that?

@garyb
Copy link
Member

garyb commented Jul 5, 2016

Well, it has a completely different interface so it's not ideal - reimplementing the interface on top of it probably wouldn't be that hard, but it would mean that the library would include a load of unnecessary code when used in the browser - currently there's only this.

@chexxor
Copy link
Contributor

chexxor commented Jan 12, 2018

I think this is an issue with Affjax, not the xhr2 module.

I executed this script on Node and in browser (without require statement), and both seemed to follow the redirect from "http://news.ycombinator.com" to "https://news.ycombinator.com".

var XMLHttpRequest = require("xhr2");
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", function () { console.log(this); });
oReq.open("GET", "http://news.ycombinator.com");
oReq.send();

But running purs repl with this performs poorly, as described by OP:

import Prelude
import Control.Monad.Eff
import Unsafe.Coerce 
import Control.Monad.Eff.Exception
import Control.Monad.Eff.Console
import Control.Monad.Eff.Class
import Control.Monad.Aff
import Network.HTTP.Affjax
void $ launchAff $ (get "http://news.ycombinator.com" :: Affjax _ String) >>= \res -> liftEff $ log $ show res.status <> " " <> show res.headers <> " " <> show res.response

I was using the previous Aff implementation, btw, v3.

@MonoidMusician
Copy link

MonoidMusician commented Jun 29, 2019

Update: this issue still seems to exist. Here's the updated code for the REPL:

import Prelude
import Effect
import Effect.Aff
import Effect.Class
import Data.Bifunctor (lmap)
import Affjax
import Affjax.ResponseFormat 
launchAff_ $ get string "http://news.ycombinator.com" >>= \res -> liftEffect $ log $ show res.status <> " " <> show res.headers <> " " <> show (lmap printResponseFormatError res.body)

And here's code for Milkis if anyone is curious:

import Prelude
import Effect.Aff
import Milkis as M
import Milkis.Impl.Node (nodeFetch)
import Effect.Class.Console (log, logShow)
fetch = M.fetch nodeFetch
launchAff_ $ fetch (M.URL "http://news.ycombinator.com") M.defaultFetchOptions >>= M.text >>= log

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

No branches or pull requests

6 participants