libwww-perl / libwww-perl/HTTP-Message

form-data Content-Type doesn't seem to permit setting charset for individual content fields [rt.cpan.org #69078]

Open
#49 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
32
Forks
63
Avg merge
5h 14m
Merged PRs (30d)
1

Description

Migrated from rt.cpan.org#69078 (status was 'new')

Requestors:

  • mark@blackmans.org

From mark@blackmans.org on 2011-06-24 14:46:50:

Although the HTML 4.01 spec and the HTTP 1.1 spec refer to being able to set the
charset for individual form-data encoded controls, POST in HTTP::Request::Common
doesn't seem to have any way of specifying the charset per field.

In particular, the content field might have wide characters that I want to encode
and transmit.

POST $url, Content => [ surname => encode('utf8',"Jędrejek"), b64_data => $base64_string 
], Content_Type => 'form-data';

The receiving doesn't know what encoding was used for surname in the case above.

Perhaps the following syntax instead?

Content => [ surname => { Content => $encoded_string, Content_Type=> 'text/plain; 
charset='utf8' }, b64_data => $base64_string ]

Regrettably I've no patch to offer. Perhaps there is a way to achieve this currently, but I didn't 
work it out.

From mark@blackmans.org on 2011-06-24 15:01:14:

Reading more carefully, there is actually a work-around that is very much like the suggested
syntax.

{ surname => [undef,"t1.txt",Content=>encode("utf8","Jędrejek"),Content_Type=>"text/plain; 
charset=utf8"] }


On Fri Jun 24 10:46:50 2011, mark@blackmans.org wrote:
> Although the HTML 4.01 spec and the HTTP 1.1 spec refer to being able
> to set the
> charset for individual form-data encoded controls, POST in
> HTTP::Request::Common
> doesn't seem to have any way of specifying the charset per field.
> 
> In particular, the content field might have wide characters that I
> want to encode
> and transmit.
> 
> POST $url, Content => [ surname => encode('utf8',"Jędrejek"), b64_data
> => $base64_string
> ], Content_Type => 'form-data';
> 
> The receiving doesn't know what encoding was used for surname in the
> case above.
> 
> Perhaps the following syntax instead?
> 
> Content => [ surname => { Content => $encoded_string, Content_Type=>
> 'text/plain;
> charset='utf8' }, b64_data => $base64_string ]
> 
> Regrettably I've no patch to offer. Perhaps there is a way to achieve
> this currently, but I didn't
> work it out.


From mark@blackmans.org on 2011-06-24 15:21:52:

that form means the server treats those as file uploads rather than parameters though.

On Fri Jun 24 11:01:14 2011, mark@blackmans.org wrote:
> Reading more carefully, there is actually a work-around that is very
> much like the suggested
> syntax.
> 
> { surname =>
> [undef,"t1.txt",Content=>encode("utf8","Jędrejek"),Content_Type=>"text/plain;
> charset=utf8"] }
> 
> 
> On Fri Jun 24 10:46:50 2011, mark@blackmans.org wrote:
> > Although the HTML 4.01 spec and the HTTP 1.1 spec refer to being
> able
> > to set the
> > charset for individual form-data encoded controls, POST in
> > HTTP::Request::Common
> > doesn't seem to have any way of specifying the charset per field.
> >
> > In particular, the content field might have wide characters that I
> > want to encode
> > and transmit.
> >
> > POST $url, Content => [ surname => encode('utf8',"Jędrejek"),
> b64_data
> > => $base64_string
> > ], Content_Type => 'form-data';
> >
> > The receiving doesn't know what encoding was used for surname in the
> > case above.
> >
> > Perhaps the following syntax instead?
> >
> > Content => [ surname => { Content => $encoded_string, Content_Type=>
> > 'text/plain;
> > charset='utf8' }, b64_data => $base64_string ]
> >
> > Regrettably I've no patch to offer. Perhaps there is a way to
> achieve
> > this currently, but I didn't
> > work it out.
> 
> 


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with POST in HTTP::Request::Common and trace how form-data fields are represented and their content types are emitted. Compare the existing file-upload workaround with the requested non-file form field behavior; done means a field can carry an explicit charset without being treated as a file upload, with coverage for the proposed syntax and encoded value.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.