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

Large size http request been cut off when through protocol registerHttpProtocol API #8302

Closed
x-yao opened this issue Dec 29, 2016 · 7 comments

Comments

@x-yao
Copy link
Contributor

x-yao commented Dec 29, 2016

  • Electron version:1.4.12
  • Operating system:macOS Sierra

Expected behavior

When I Use registerHttpProtocol to watch http requests and let original request callback to the browser.Expected all request work find.

protocol.interceptHttpProtocol('http',(request, callback) => {
	let postData;
	if (request.uploadData) {
		postData = request.uploadData[0].bytes.toString();
	}
	let par = {
		url:request.url,
		method:request.method
	}
	if (request.method == "POST") {
		par.session = null;
		par.uploadData = {
			contentType:'text/html',
			data: postData
		}
	}else{
		par.session = null
	}
	callback(par)
}, (error) => {
	if (error) console.error('Failed to register protocol')
})

Expected like this :
Expected

Actual behavior

When request a large size file like huge non-compressed javascript(more than 40000 lines) it would be cut off through protocol registerHttpProtocol API and if use WebRequest API it would not be cut off.

Actual this :
Actual

@sofianguy
Copy link
Contributor

Thanks for contributing!

We are no longer releasing bug fixes for versions of Electron older than 1.5. We prefer to only keep issues that are on our immediate radar.

If you are still having the same issue in an up-to-date version, feel free to reach out and we'll reopen.

@megahertz
Copy link
Contributor

megahertz commented Mar 6, 2020

The same issue occurs with Electron v8.0.3 with the simple handler. 2mb gif file is always corrupted. It's reproduced on Linux and MacOS. Windows loads the page fine, but If "Fast 3G" emulation in DevTools is enabled, it has the same problem.

const { app, BrowserWindow, protocol } = require('electron');

app.on('ready', () => {
  protocol.registerHttpProtocol('https', (request, callback) => {
    console.log(request);
    callback(request);
  });

  const wnd = new BrowserWindow();
  wnd.loadURL('https://l96.ru/share/electron/');
});

Screenshot_20200306_164716

@danielweck
Copy link

I'm having the same issue with a 5MB PNG image file, which gets truncated when passing through registerHttpProtocol(), but works fine when delivered directly via its HTTP source (a local Express server). I tried changing the way the HTTP response is generated, the problem occurs with both a fully-loaded response body (byte buffer), and a stream pipe.
I can reproduce this on Electron v7, 8, and 9.

@danielweck
Copy link

Screenshots:

Screenshot 2020-03-27 at 20 48 42

Screenshot 2020-03-27 at 20 49 05

@danielweck
Copy link

I fixed this by using registerStreamProtocol() instead of registerHttpProtocol(): I create an HTTP request manually and I pipe the response into stream.PassThrough which is a ReadableStream (I pass the StreamProtocolResponse object to the result callback so that I can forward the response headers and HTTP status code)

@danielweck
Copy link

Follow-up in this open issue:
#21018 (comment)

@danielweck
Copy link

PS: note that registerStreamProtocol() has its own issues, notably when piping HTTP 206 response streams (partial byte range requests). See link in previous comment above for details.

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

No branches or pull requests

6 participants