How to use browser with server that does not return HTTP Response Headers? - browser

I'm working with an IoT device that has an embedded HTTP Server that returns csv formatted status data. Everything works fine between my data collector app and the IoT device in terms of communications - I make a request and the server returns data, no big deal.
However, the request fails when I attempt to connect to the server with a Web Browser due to the fact that the IoT device does not return any HTTP Response Headers and, apparently, modern Web Browsers reject packets that have no/malformed Response Headers.
Since I have no way of updating the IoT device's HTTP Response Headers, I'm stuck with having to find a solution on the browser side.
I've searched for Flags/Settings in Chromium and Firefox that would allow malformed/missing Response Headers, but to no avail. I've also tried using the ModHeader plugin to manipulate the Response Headers, but that doesn't solve the problem (ModHeader manipulates the response header AFTER the browser has already rejected the response).
I'm out of ideas on how to solve this problem for browser users. Do you have any tips/ideas on how to use a browser successfully with an HTTP Server that returns zero Response Headers?
PS The errors that are displayed by different client consoles for malformed response headers are:
Chromium: Failed to load resource: net::ERR_INVALID_HTTP_RESPONSE (Failed to load response data: No data found for resource with given identifier)
Firefox: XML Parsing Error: syntax error
Wireshark: Expert Info (Warning/Protocol): Illegal characters found in header name

Related

Azure Application Gateway is striping request body when it comes from APIGEE

When APIGEE is trying to hit API which is deployed in Azure as function app which has app gateway integrated, but when the request is coming it is stripping the request body. as the result we are getting 400 bad request we are clueless what is happening here, any help would be welcomed
• As per your explanation, you are sending a POST request to the application gateway in Azure behind which the function app is deployed. Thus, when the request from Apigee hits the application gateway endpoint, the information in body of the request gets eaten or disappeared. This happens with specific API proxies only, in this case, the apigee request sent is considering the application gateway deployed as an unacceptable API proxy. Thus, I would request you to please take the following steps: -
a) Gather a TCP dump when the API request was made with NGINX/Wireshark logs and analyze it to confirm the target port as 443.
b) Check any message being sent from the message processor to the backend server and check any message that states as below in the logs: -
[Unencrypted HTTP protocol detected over encrypted port, could indicate a dangerous misconfiguration.]
c) And if the target server definition was created without ‘SSLInfo’ section, then the above message is encountered in the logs. Then update the target server definition with the correct ‘SSLInfo’ section to make it secure.
d) Then restart both the ‘Message Processors’ on the apigee as well as the Azure side to get the latest definition of the target server.
e) Also, check if the encoding specified in the HTTP request header ‘Content-Encoding’ is valid or not and the payload format sent by the client as a part of the HTTP request matches the encoding format specified in the ‘Content-Encoding’ header or not.
• The error that you are encountering is a result of the above stated scenario. As a result, you can fix the issue by sending the request header as Content-Encoding:<payload format> and the request payload also in the same format. An example of doing the same is given below: -
curl -v "https://HOSTALIAS/v1/testgzip" -H "Content-Encoding: gzip" -X POST -d #request_payload.gz
For more details regarding the above, kindly refer to the documentation link below: -
https://docs.apigee.com/api-platform/troubleshoot/runtime/400-decompressionfailureatrequest

Express Server Responds to POST Request Before Recieving the Body

I have an express server that I created using express-generator, and setup by following one of the thousands of available online tutorials. As far as express servers go, it's fairly unremarkable. When I send POST request from Postman, or from my React app, it takes the body and stuffs it into the database, then sends the response, exactly as I expect.
The problem occurs when I try to send it a POST request from a microcontroller via a 4G modem using AT commands. This is considerably slower than a browser, and involves a delay of several milliseconds between the header and the body. During this delay, instead of waiting for the POST body, the server goes ahead and sends the response as though the body was empty.
At first, the problem appeared to be with the modem or the firmware, but I was able to narrow it down to the server by making POST requests to a different server. I made a POST to the dweet.io API, and observed that after the modem transmitted the header, it sat for a few seconds to allow the microcontroller to upload the body.
It feels like this has something to do with a timeout setting in express, but the only thing I could find in that department is server.timeout, which I have verified to be 120000. Is there any setting or middleware I could use to force the server to chill out and wait for the body?

Why Chrome Refreshes the URL after certain minutes of receiving no response?

In my node application I have an anchor tag which when clicked will request an Express GET route which makes some API calls and render the response in an EJS template.
When the API being requested from Express route takes too long to respond, the Node express route URL gets requested again automatically.
Can anyone explain this behaviour ?
In HTTP/1.1 Connections:
8.2.4 Client Behavior if Server Prematurely Closes Connection:
If an HTTP/1.1 client sends a request which includes a request body,
but which does not include an Expect request-header field with the
"100-continue" expectation, and if the client is not directly
connected to an HTTP/1.1 origin server, and if the client sees the
connection close before receiving any status from the server, the
client SHOULD retry the request
Browsers mostly will re-try a connecton until a proper response is given, on Chrome i believe it's 5 attempts.
It's a expected behavior.
There's a nice article from Oracle's blog that has a similar scenario described.

HTML request using a PLC

I am trying to make a get/post request to a multi-purpose modem for web interface and gsm interface using a PLC(Programmable Logic Controller).
I have been trying to send string data to the modem through the TCP library currently with Schneider Somachine. Every time I make a request, I receive an Error 400 bad request. I am hoping that my program is correct as I can receive an error statement via the modem, but am not sure about the request I need to make in order to receive a positive OK response from the controller.
I have tried making the following requests and all returned with an Error 400 bad request.
GET https://192.168.2.1
GET https://192.168.2.1/api/login?username=admin&password=admin
I have also tried the above without the GET statement and with POST statements as well.
The above requests were done with carriage return and new line characters in the end.
I would really appreciate if someone could help out with the request type that has to be made in order to get that response.
As far as I know, accessing PLC through ajax is not a routine operation. If you can, you can try LECPServer, an open source middleware. It can expose the PLC node address for reading and writing through HTTP POST.
https://github.com/xeden3/LECPServer
Your requests are malformed (that's why you get the 400 response).
It should look like:
GET /path/to/resource/index.html HTTP/1.0
The server (192.168.2.1) and the transport (http vs https) have already been taken care of by the connection. All you're trying to do is tell the device what you want to do. In this case you want to access the login page with your credentials. You also need to specify which version of the protocol to use.
Get /api/login?username=admin&password=admin HTTP/1.0

When handling XMLHttpRequest in Nodejs proxy server, I've already call "res.end()", but client's behavior seems can't get my res and timeout finally

I have a question.
In my Nodejs proxy server, from debug log, I can see I've already handled the request, send its correct response and call "res.end()" to end this request. And this request is XMLHttpRequest.
And from Chrome's developer tool, I can see that this request has got correct response from my Nodejs https server, and its status code is 200 OK.
But from the web UI, the client seems still waiting for my response because its image is always turning over and over, and seems to time out finally. Like the screenshot below.
Can anyone give me some advice? I don't understand why the client can't get my response data. And this request is XMLHttpRequest.Thanks very much.
I've found the answer. Because I need to response to long poll request immediately. If don't, the client will cancle the request or timeout

Resources