node-modules / urllib

Request HTTP(s) URLs in a complex world.
MIT License
729 stars 118 forks source link

Requested URL array contains same URL twice #346

Closed bigalnz closed 2 years ago

bigalnz commented 4 years ago

I have a project that receives POST data from a camera. This data include a URL for a JPG image. I then use this URL received in the POST data to make a requerst to the camera to retreieve the image with a GET.

The issue is that the camera response indicates that I have requested the same URL twice:

const fs = require('fs'); var express = require('express') var multer = require('multer') var upload = multer({ storage: multer.memoryStorage() }) var app = express()

const httpClient = require('urllib'); const camera_url = 'http://192.168.78.10';

const options = { method: 'GET', rejectUnauthorized: false, digestAuth: "root:***", headers: { 'Content-Type': 'text/html' } };

// handler for receiving data from camera - list on test port 3000 app.post('/test', upload.fields([ {name: 'event'}, {name: 'image'} ] ), (req, res) => { var data = JSON.parse(req.files.event[0].buffer.toString()) res.send(200)

const url = camera_url + data.imagesURI[0];
console.log(url) // Clicking on this image in the console shows the plate OK
const PlateImage = httpClient.request(url, options).then(function (result) {
    console.log('this is url requested : ', url)
    console.log('response status from camera : ', result.res.statusCode);
    console.log('full result', result)
    console.log('this is data to string ', result.data.toString('base64'))
    return result.data.toString('base64')
})
PlateImage.then(function(image) {
    sendToOtherServer(req, data, image )
});

})

But my responses look like this (first one is OK 200 then the other are 400)

http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=28/20201008101338_667494lp_ARL12_5695965.jpg this is url requested : http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=28/20201008101338_667494lp_ARL12_5695965.jpg response status from camera : 200 full result { data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 06 04 05 06 05 04 06 06 05 06 07 07 06 08 0a 10 0a 0a 09 09 0a 14 0e 0f 0c ... 2994 more bytes>, status: 200, headers: { date: 'Wed, 07 Oct 2020 21:13:39 GMT', server: 'Apache/2.4.43 (Unix) OpenSSL/1.1.1g', 'authentication-info': 'rspauth="a4351eb8e8766ab0b7bf584d0459d5e2", cnonce="43c00aee4ed6c3f2", nc=00000001, qop=auth', 'content-type': 'image', status: '200 OK', 'keep-alive': 'timeout=5, max=100', connection: 'Keep-Alive', 'transfer-encoding': 'chunked' }, res: { status: 200, statusCode: 200, statusMessage: 'OK', headers: { date: 'Wed, 07 Oct 2020 21:13:39 GMT', server: 'Apache/2.4.43 (Unix) OpenSSL/1.1.1g', 'authentication-info': 'rspauth="a4351eb8e8766ab0b7bf584d0459d5e2", cnonce="43c00aee4ed6c3f2", nc=00000001, qop=auth', 'content-type': 'image', status: '200 OK', 'keep-alive': 'timeout=5, max=100', connection: 'Keep-Alive', 'transfer-encoding': 'chunked' }, size: 3044, aborted: false, rt: 20, keepAliveSocket: false, data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 06 04 05 06 05 04 06 06 05 06 07 07 06 08 0a 10 0a 0a 09 09 0a 14 0e 0f 0c ... 2994 more bytes>, requestUrls: [ 'http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=28/20201008101338_667494lp_ARL12_5695965.jpg', 'http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=28/20201008101338_667494lp_ARL12_5695965.jpg' ], timing: null, remoteAddress: '192.168.78.10', remotePort: 80, socketHandledRequests: 1, socketHandledResponses: 1 } } this is data to string << valid base64 image>> about to send to sGrid ARL12 plate image file written ok http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=30/20201008101339_254099lp_ABC123_5695966.jpg this is url requested : http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=30/20201008101339_254099lp_ABC123_5695966.jpg response status from camera : 400 full result { data: <Buffer 3c 21 44 4f 43 54 59 50 45 20 48 54 4d 4c 20 50 55 42 4c 49 43 20 22 2d 2f 2f 49 45 54 46 2f 2f 44 54 44 20 48 54 4d 4c 20 32 2e 30 2f 2f 45 4e 22 3e ... 176 more bytes>, status: 400, headers: { date: 'Wed, 07 Oct 2020 21:13:39 GMT', server: 'Apache/2.4.43 (Unix) OpenSSL/1.1.1g', 'content-length': '226', connection: 'close', 'content-type': 'text/html; charset=iso-8859-1' }, res: { status: 400, statusCode: 400, statusMessage: 'Bad Request', headers: { date: 'Wed, 07 Oct 2020 21:13:39 GMT', server: 'Apache/2.4.43 (Unix) OpenSSL/1.1.1g', 'content-length': '226', connection: 'close', 'content-type': 'text/html; charset=iso-8859-1' }, size: 226, aborted: false, rt: 15, keepAliveSocket: false, data: <Buffer 3c 21 44 4f 43 54 59 50 45 20 48 54 4d 4c 20 50 55 42 4c 49 43 20 22 2d 2f 2f 49 45 54 46 2f 2f 44 54 44 20 48 54 4d 4c 20 32 2e 30 2f 2f 45 4e 22 3e ... 176 more bytes>, requestUrls: [ 'http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=28/20201008101338_667494lp_ARL12_5695965.jpg', 'http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=28/20201008101338_667494lp_ARL12_5695965.jpg', 'http://192.168.78.10/local/fflprapp/tools.cgi?action=getImage&name=30/20201008101339_254099lp_ABC123_5695966.jpg' ], timing: null, remoteAddress: '192.168.78.10', remotePort: 80, socketHandledRequests: 1, socketHandledResponses: 1 } }

what is with the requestURLs array in the response?