Closed Bug 767087 Opened 12 years ago Closed 12 years ago

Add a flag to force content sniffing on nsHttpChannel and nsBaseChannel.

Categories

(Core :: Networking, defect)

16 Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla16

People

(Reporter: padenot, Assigned: padenot)

References

Details

Attachments

(2 files, 1 obsolete file)

For bug 567077, we need a flag to force the type sniffers to sniff for the type in the case where the Content-Type header is "application/octet-stream". It has been proposed that the change would be made in necko.
Here is a possible patch, works great in combination with patches for bug 567077.

I'm new in that module, feel free to pass the review to another person if you feel you're not the right peer to ask for review here (or if you are too busy).
Attachment #635815 - Flags: review?(jduell.mcbugs)
Comment on attachment 635815 [details] [diff] [review]
Patch v0: add a flag for force content type sniffing for nsHttpChannel and nsBaseChannel.

Review of attachment 635815 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good.  I assume you've tested this manually?

bz: do you think this needs an xpcshell test, or is it simple enough that we're ok w/o one?

::: netwerk/base/public/nsIChannel.idl
@@ +242,5 @@
>      const unsigned long LOAD_CLASSIFY_URI = 1 << 22;
>  
>      /**
> +     * If this flag is set, the channel should call the content sniffers
> +     * registered in the "content-sniffing-services" category, if the

Let's go with this instead:

If this flag is set and a server's response is Content-Type application/octet-steam, the server's Content-Type will be ignored and the channel content will be sniffed as though no Content-Type had been passed.

::: netwerk/base/src/nsBaseChannel.cpp
@@ +688,5 @@
> +  // going as-is.
> +  bool shouldSniff = mContentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE) ||
> +            (mLoadFlags & LOAD_TREAT_APPLICATION_OCTET_STREAM_AS_UNKNOWN) &&
> +            mContentType.EqualsLiteral(APPLICATION_OCTET_STREAM);
> +

Everyone should know that && binds closer than ||: heck, we could do w/o any *any* parentheses in the whole expression.   But just to be clear, let's put another level of parenthesis around the whole || expression:

bool shouldSniff = mContentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE) ||
    ((mLoadFlags & LOAD_TREAT_APPLICATION_OCTET_STREAM_AS_UNKNOWN) &&
        mContentType.EqualsLiteral(APPLICATION_OCTET_STREAM));

::: netwerk/protocol/http/nsHttpChannel.cpp
@@ +881,5 @@
>      mTracingEnabled = false;
>  
> +    if (mResponseHead && (mResponseHead->ContentType().IsEmpty() ||
> +        mResponseHead->ContentType().EqualsLiteral(APPLICATION_OCTET_STREAM) &&
> +        (mLoadFlags & LOAD_TREAT_APPLICATION_OCTET_STREAM_AS_UNKNOWN))) {

To keep this more legible, let's declare 'bool shouldSniff' above this if statement, like you do for nsBaseChannel (and add extra parens there too)
Attachment #635815 - Flags: review?(jduell.mcbugs)
Attachment #635815 - Flags: review?(bzbarsky)
Attachment #635815 - Flags: review+
> Looks good.  I assume you've tested this manually?

Yes. Plus it is going to be tested by the tests I've written for bug 567077 (which is the reason why we need this feature in the first place). I could probably write another test for that feature if needed.
Status: NEW → ASSIGNED
Comment on attachment 635815 [details] [diff] [review]
Patch v0: add a flag for force content type sniffing for nsHttpChannel and nsBaseChannel.

This looks fine, though an xpcshell test can't hurt.  Shouldn't be hard to do....
Attachment #635815 - Flags: review?(bzbarsky) → review+
Carrying r+ forward.
Attachment #635815 - Attachment is obsolete: true
Attachment #636773 - Flags: review+
Here is a test for that feature, green on try [1].

[1]: https://tbpl.mozilla.org/?tree=Try&rev=af53f8131c39
Attachment #636778 - Flags: review?(jduell.mcbugs)
Comment on attachment 636778 [details] [diff] [review]
XPCShell test for the feature.

Review of attachment 636778 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks Paul!

http://hg.mozilla.org/integration/mozilla-inbound/rev/0a46999bfecb
https://hg.mozilla.org/integration/mozilla-inbound/rev/2d4d8153d27d

::: netwerk/test/unit/test_force_sniffing.js
@@ +1,1 @@
> +// This file tests the flat LOAD_TREAT_APPLICATION_OCTET_STREAM_AS_UNKNOWN.

s/flat/flag

@@ +70,5 @@
> +  httpserv = new nsHttpServer();
> +  httpserv.registerPathHandler("/test", handler);
> +  httpserv.start(4444);
> +
> +  // Register our fake sniffer that always return the content-type we want.

returns
Attachment #636778 - Flags: review?(jduell.mcbugs) → review+
https://hg.mozilla.org/mozilla-central/rev/0a46999bfecb
https://hg.mozilla.org/mozilla-central/rev/2d4d8153d27d
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla16
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: