-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Shouldn't _contentLength / setContentLength be factored out? #2132
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
Comments
|
Streaming was the only bit I overlooked, hadn't considered that. Which is another reason I'd be for the refactor, it was non-obvious that this is how streaming an known or unknown length data stream is started.
It's boilerplate one has to grok from sources and leave a comment to remember why you wrote this strange thing. Perhaps purpose driven API's could resolve the strangeness in the current api? And setContentLength could be dropped entirely.
IF it were factored into that (now there'd have issues with compatibility, so discretion is necessary) one could do away with the _contentLength variable. and setContentLength _contentLength is only branched upon in 2 locations In one location it's verifying not use _contentLength, and use the size of the content as known in the scope of the current function.
This feels like a lot of weird pomp-and-circumstance to get a stream setup. Especially since send is being used in multiple ways, and it's behavior coaxed to changing by way of state variables. and scope variables. |
The startStream/endStream thing looks fine. If you have time, feel free to do a pull request. But I think the old functions have to be kept for a while — there are libraries which happen to use them. |
Agreed, I expect a lot of beginners and hackers more interested in an end goal using this. Not an audience that wants to update libraries because I changed something... also don't want to get hate mail ;) Isn't there a standard for gcc/g++ for issuing warnings for deprecated usage? #warning I think, is that something you'd like to include this time around in the setContentLength function, or perhaps say 6 mo from now, and then 6 mo after retire the api (or whatever your preference is, I'll set a reminder and manage a pull request for that timeframe) |
|
@igrr I suspect that the confusion that started this issue is this: template<typename T> size_t streamFile(T &file, const String& contentType){
setContentLength(file.size()); // <--------- setter method called with no purpose
if (String(file.name()).endsWith(".gz") &&
contentType != "application/x-gzip" &&
contentType != "application/octet-stream"){
sendHeader("Content-Encoding", "gzip");
}
send(200, contentType, "");
return _currentClient.write(file);
} The setContentLength() method is called, but it seems to me that it serves no purpose calling it in there. |
This won't fit into 2.5.0. Pushing milestone back. |
I noticed that there's a
Its one and only one use is inside the header in 'streamFile' where the contentLength is available already via file.size()
So adding an overloaded send that allows a code/content/body/size which I noticed doesn't exist... except for - send_P which is related to PROGMEM / PGM_P (I could be miss understanding this)
It sorta looks like the _contentLength and supporting code is a kludge around missing a send with this footprint. Which I sorta expected to have, maybe the progmen/pgm_p stuff is more common?
Refactoring this would reduce variable clutter and factor out a state check within_prepareHeader that isn't used for any other functionality and add a function that appears to be missing.
Unless it's there due to backwards compatibility.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: