HTTP Request Node Error

Hello.

We have an old web service that shows a web page running on a specific port.

I try with HTTP Request Node to make a simple GET request but it fails with the following error.

{
"status": "rejected",
"reason": {
"message": "Parse Error: Expected HTTP/",
"name": "Error",
"stack": "Error: Parse Error: Expected HTTP/ at Socket.socketOnData (_http_client.js:509:22) at Socket.emit (events.js:315:20) at Socket.EventEmitter.emit (domain.js:467:12) at addChunk (internal/streams/readable.js:309:12) at readableAddChunk (internal/streams/readable.js:284:9) at Socket.Readable.push (internal/streams/readable.js:223:10) at TCP.onStreamRead (internal/stream_base_commons.js:188:23)",
"code": "HPE_INVALID_CONSTANT"
}
} 

If i do a simple curl from the host i am running n8n it gets the webpage html source.

Something with this http node i think it does not support old html headers?

From the browser console the GET request shows

Version: HTTP/1.0

Is this the problem why HTTP node throws an error?

Hey @Mulen,

I would have expected HTTP/1.0 to be ok but that could be the issue, If you run your curl command with the -v option does it show anything odd?

Do you know what web server the old service is running on?

It’s a windows server running IIS. The thing is curl command works just fine. I run it with -v option too

* TCP_NODELAY set
* Connected to <IP> port <PORT> (#0)
> GET / HTTP/1.1
> Host: <IP:PORT>
> User-Agent: curl/7.61.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: 
< Cache-control: no-cache
< Pragma: no-cache
< Expires: -1
< Content-Type: text/html
< Set-Cookie:                                          ; path=/;
< MF-Cookie-1:                                              ;
< Set-Cookie:            ; path=/;
< MF-Cookie-2:         ;
< Set-Cookie:         ; path=/;
< MF-Cookie-3:         ;
< Content-Length: 54128
<
<HTML>

So the HTTP node does not support old HTTP protocol?

It does look that way, From what I could tell though Node should support 1.0+ though. I have not managed to find an HTTP/1.0 only server to test with.

What version of Windows and IIS are you running that could be a quick way to get a test set up.

The server is 2008 R2 but i think eventually this web service is not from IIS but from an old proprietary web service that i don’t have access to.

I don’t know how to replicate it and test HTTP 1.0

Also maybe something like this happen?

Something with Content-Length and real body size of the request and n8n HTTP Node throws an error?

Done a quick bit of testing and it looks like under the hood Node does support HTTP/1.0 connections so we are no closer to working this one out.

Do you happen to have Node installed locally? I ran the code below which I found here just to test if HTTP/1.0 does work, It doesn’t test it in n8n but it would be nice to see if that is able to connect to your service as well to see if it is something odd with the service or something odd somewhere else in the n8n implementation.

Code
var net = require("net");
var client = new net.Socket();
client.connect(
  80,
  "example.com",
  function() {
    console.log("Connected");
    client.write(`GET / HTTP/1.0
Host: example.com

`);
  }
);

client.on("data", function(data) {
  console.log("Received " + data.length + " bytes\n" + data);
});

client.on("close", function() {
  console.log("Connection closed");
});

I installed nodejs on my local pc and run the code against the server.

It runs correctly and shows an output like curl command, similar.

So something is wrong with n8n then?

That is annoying but basically yeah, Could be that some of the processing the HTTP Request node does on the way is causing an issue.

Do you get the same issue if you try toggling the older HTTP Request library ( N8N_USE_DEPRECATED_REQUEST_LIB=true)?

It has not taken long but I think we might be near the end of my knowledge when it comes to HTTP and Node but depending on the result of that test there could be other things we can check.

Yeah same error different output

That is interesting so it looks like it might be parsing part of the HTML then hitting an issue, converting the data from your error message only shows what could be the bottom part of your pages content it is hard to tell without seeing the entire thing.

I have put a nicer to look at version of the error below with the actual buffer data removed so if you don’t want it on the internet you can edit your comment :slight_smile:

Error
{
  "status": "rejected",
  "reason": {
    "name": "RequestError",
    "message": "Error: Parse Error: Expected HTTP/",
    "cause": {
      "bytesParsed": 4896,
      "code": "HPE_INVALID_CONSTANT",
      "reason": "Expected HTTP/",
      "rawPacket": {
        "type": "Buffer",
        "data": [
          "<REMOVED>"
        ]
      }
    },
    "error": {
      "bytesParsed": 4896,
      "code": "HPE_INVALID_CONSTANT",
      "reason": "Expected HTTP/",
      "rawPacket": {
        "type": "Buffer",
        "data": [
          "<REMOVED>"
        ]
      }
    },
    "options": {
      "timeout": 3600000,
      "headers": {
        "accept": "application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, */*;q=0.1"
      },
      "method": "GET",
      "uri": "<THE_URL>",
      "gzip": true,
      "rejectUnauthorized": false,
      "json": true,
      "simple": true,
      "resolveWithFullResponse": false,
      "transform2xxOnly": false
    }
  }
}

Out of interest would you be able / willing to save the page HTML and send it as a DM or email it to me so I can see if it is just the body causing the issue?

You want the curl output in a dump file?

That would do, Or just pop open the page and do the right click > view source and copy it to a txt file.

I sent you a DM

1 Like