Closed Bug 1623004 Opened 5 years ago Closed 5 years ago

Resend requests should set the correct content-length header

Categories

(DevTools :: Netmonitor, defect, P3)

defect

Tracking

(firefox77 fixed)

RESOLVED FIXED
Firefox 77
Tracking Status
firefox77 --- fixed

People

(Reporter: Harald, Assigned: ojaswa1942)

References

(Blocks 1 open bug)

Details

(Keywords: good-first-bug)

Attachments

(1 file)

Reported via https://discourse.mozilla.org/t/reset-content-length-header-when-editing-and-resending-requests/56037

Should be either removed or reset to the correct length (my favorite).

Honza, could this be a good first bug?

Flags: needinfo?(odvarko)

STR:

  1. Open DevTools and Select the Network panel
  2. Load http://janodvarko.cz/firebug/tests/601/Issue601.htm
  3. Click the POST button on the page
  4. Select the request and click the Edit and Resend button in the Headers side panel
  5. Change the Request Body text, e.g. keep just data in it
  6. Press the Send button in the form
  7. The new HTTP request fail on timeout with status 408 Request Timeout since the request header content-length was wrong

Honza

Has STR: --- → yes
Flags: needinfo?(odvarko)

Some instructions for anyone interested in fixing this bug:

  1. The Request Body text area (for POST data) is rendered here:
    https://searchfox.org/mozilla-central/rev/d69ec052bed8700af7a283e37b60b4af22734930/devtools/client/netmonitor/src/components/CustomRequestPanel.js#332-340

  2. There is a change handler updateCustomRequestFields registered for onChange
    It's implemented in the same file:
    https://searchfox.org/mozilla-central/rev/d69ec052bed8700af7a283e37b60b4af22734930/devtools/client/netmonitor/src/components/CustomRequestPanel.js#105

  3. We are interested when the POST data changes so case "custom-postdata-value"
    https://searchfox.org/mozilla-central/rev/d69ec052bed8700af7a283e37b60b4af22734930/devtools/client/netmonitor/src/components/CustomRequestPanel.js#127

In this case we need to parse request headers text and update the Content-Length header (using the current POST data length).
Related text area is rendered here:
https://searchfox.org/mozilla-central/rev/d69ec052bed8700af7a283e37b60b4af22734930/devtools/client/netmonitor/src/components/CustomRequestPanel.js#310-318

  1. Luckily we already have parseRequestText we can utilize here:
    https://searchfox.org/mozilla-central/rev/d69ec052bed8700af7a283e37b60b4af22734930/devtools/client/netmonitor/src/components/CustomRequestPanel.js#84

Honza

Whiteboard: good-first-bug
Keywords: good-first-bug
Whiteboard: good-first-bug

As I can see, we can edit both Request Body and Request Headers, making it possible for user to set the content-length property. If I correctly understand the problem, if we correct the value to correct length, won't it be a problem for user who don't intend to send correct value? I mean, it is very possible for someone wishing to change the length as per his requirements, specially if he's sending a custom request.

Flags: needinfo?(hkirschner)
Flags: needinfo?(hkirschner)
Assignee: nobody → ojaswa1942
Status: NEW → ASSIGNED

PFA the patch.

The following are the details of the change:

Inside case "custom-postdata-value":

  • Retrieve request headers
  • Replace content-length value in request headers by new content-length
  • Update both postData and headers

New behavior:

  • Only content length header changes with data (Other header values remain same)
  • In case someone wants to send a different content-length value, they can edit the header value before sending. (Resolves Comment #4)

Kindly review the patch.

Flags: needinfo?(odvarko)
Pushed by jodvarko@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/23fa040f986a Modify content-length header with change in custom post data r=Honza
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 77
Flags: needinfo?(odvarko)
See Also: → 1779359
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: