Code

Opened 6 years ago

Closed 6 years ago

#6775 closed (invalid)

request.META should be a MultiValueDict

Reported by: Honza_Kral Owned by: nobody
Component: HTTP handling Version: master
Severity: Keywords: http multivaluedict querydict
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The RFC specifies that some headers in HTTP can appear more than once, we need to store the headers in MultiValueDict to reflect that.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2

Multiple message-header fields with the same field-name MAY be present in a message

Attachments (0)

Change History (1)

comment:1 in reply to: ↑ description Changed 6 years ago by Piotr Lewandowski <django@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

This change would be backward incompatible. Let's see what RFC 2616 says:

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma.

Let's check how will *mod_python* and *WSGI* act using curl:

curl -H 'Foo: spam' -H 'Foo: eggs' http://localhost:8000/

mod_python

In case of mod_python handler request.META is populated with custom headers by following chunk of code:

            for key, value in self._req.headers_in.items():
                key = 'HTTP_' + key.upper().replace('-', '_')
                self._meta[key] = value

Notice that self._req.headers_in provider by mod_python is an ordinary dict.

mod_python seems to handle multiple headers occurrences in the RFC2616-way - by combining multiple header fields' values into the comma separated list.

#python
print request.META['HTTP_FOO']
'spam, eggs'

I wonder if separating items using '<comma><space>' delimiter is the right thing but that's not Django's business.

WSGI

WSGI response was very similar:

#python
print request.META['HTTP_FOO']
'spam,eggs'

Summary

It seems that it's correct behaviour and no changes in Django are required so I'm closing this ticket as invalid.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.