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
tool_writeout: add new writeout variable, num_headers #5947
Conversation
Where might this be useful? Who would want to know the number of headers without knowing their contents, too?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There's no docs for the variable
- How's it supposed to count amount of headers when one or more redirect are involved?
- Test 970 needs update too right?
src/tool_writeout.c
Outdated
case VAR_HEADER_COUNT: | ||
{ | ||
fprintf(stream, "%ld", per->header_count); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need these braces.
src/tool_cb_hdr.c
Outdated
if(hdrcbdata->config->writeout) { | ||
char *value = NULL; | ||
|
||
value = memchr(ptr, ':', cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this later. You can also init at variable creation
src/tool_writeout.c
Outdated
if(outs->filename) | ||
fprintf(stream, "%s", outs->filename); | ||
if(per->outs.filename) | ||
fprintf(stream, "%s", per->outs.filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use fputs. I don't think it's necessary to have the printf overhead here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, but this is a thing of the past and not changes I made, but I will change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but I don't know what you mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean I didn't wrote fprintf(stream, "%s",
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still something you can change :-)
I will write soon.
I think same as
Yes, after updating the JSON response to include |
You get an "empty" header last, don't you? That means the end of the headers for this response. |
Right, but how it can help when I don't know about previous responses? Do I need to count redirects? |
Shouldn't you just clear the counter when you get a new set of headers after a previous empty header? That way you'd always count only the last set. |
c2d3858
to
a88904e
Compare
👉 View analysis in DeepCode’s Dashboard | Configure the bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine! How about adding a test with a redirect as well just to make sure it does the right thing then as well?
docs/cmdline-opts/write-out.d
Outdated
@@ -39,6 +39,9 @@ option. (Added in 7.26.0) | |||
The initial path curl ended up in when logging on to the remote FTP | |||
server. (Added in 7.15.4) | |||
.TP | |||
.B header_count | |||
The count of retrieved headers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest:: "The number of response headers in the most recent request (restarted at each redirect)"
Should this mention that it doesn't include the first status line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this mention that it doesn't include the first status line?
I think it's not necessary when we are talking about headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just learned that some users think of that as a (special) header too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops!
By mentioning this, we also have to mention: the status line which includes the status code and reason message IS NOT a header.
So, do you prefer to mention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to mention it because, as @bagder said, some treat the status line as header line (why???).
If we can be clear on the subject, that we should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. So, @bagder, what is your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being clear is good, which is why I brought this up to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, please give me a good sentence to add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe like:
"The number of response headers in the most recent request (restarted at each redirect). Note that the status line IS NOT a header."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Added.
a88904e
to
62616be
Compare
62616be
to
4711135
Compare
This variable gives the number of headers.
4711135
to
695b59b
Compare
Thanks! |
It's a draft PR.
This variable gives the number of headers. Currently it just work with disabled redirect because I didn't find out how to reset the header counter while redirect.
And also this variable is not present in JSON-formatted writeout because the JSON handler just works with curl_easy_getinfo.