Skip to content

Commit 494ea18

Browse files
committed
FIXED: HTTP multipart message handling: set encoding for uploading a file and ensure that switching to octet
restores the binary mode. After report by Mike Elston.
1 parent eddcf29 commit 494ea18

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

http_multipart_plugin.pl

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Author: Jan Wielemaker
44
55
WWW: http://www.swi-prolog.org
6-
Copyright (c) 2014, University of Amsterdam
7-
VU University Amsterdam
6+
Copyright (c) 2014-2022, University of Amsterdam
7+
VU University Amsterdam
8+
SWI-Prolog Solutions b.v.
89
All rights reserved.
910
1011
Redistribution and use in source and binary forms, with or without
@@ -201,10 +202,11 @@
201202
mime_properties(Params, Properties),
202203
read_string(Stream, _, String),
203204
atom_string(Atom, String).
204-
part_value(Stream, Name, Params, _, Name=Value, Options) :-
205+
part_value(Stream, Name, Params, Encoding, Name=Value, Options) :-
205206
memberchk(filename(_), Params),
206207
option(on_filename(Goal), Options),
207208
!,
209+
set_encoding(Encoding, Stream, Options),
208210
call(Goal, Stream, Value, [name(Name)|Params]).
209211
part_value(Stream, Name, _, Encoding, Name=Value, Options) :-
210212
set_encoding(Encoding, Stream, Options),

multipart.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
Author: Jan Wielemaker
44
55
WWW: http://www.swi-prolog.org
6-
Copyright (c) 2014-2016, University of Amsterdam
6+
Copyright (c) 2014-2022, University of Amsterdam
77
VU University Amsterdam
8+
SWI-Prolog Solutions b.v.
89
All rights reserved.
910
1011
Redistribution and use in source and binary forms, with or without
@@ -225,6 +226,10 @@ multipart_close(void *handle)
225226
DEBUG(1, Sdprintf("multipart_close() ...\n"));
226227

227228
ctx->stream->encoding = ctx->parent_encoding;
229+
if ( ctx->stream->encoding == ENC_OCTET )
230+
ctx->stream->flags &= ~SIO_TEXT;
231+
else
232+
ctx->stream->flags |= SIO_TEXT;
228233

229234
if ( ctx->close_parent )
230235
{ IOSTREAM *parent = ctx->stream;
@@ -322,6 +327,7 @@ multipart_open(term_t org, term_t new, term_t options)
322327
s2->encoding = s->encoding;
323328
ctx->parent_encoding = s->encoding;
324329
s->encoding = ENC_OCTET;
330+
s->flags &= ~SIO_TEXT;
325331
ctx->multipart_stream = s2;
326332
if ( PL_unify_stream(new, s2) )
327333
{ Sset_filter(s, s2);
@@ -354,6 +360,7 @@ multipart_open_next(term_t stream)
354360
{ ctx->state = s_part_data_next;
355361
Sclearerr(ctx->multipart_stream);
356362
ctx->multipart_stream->encoding = ENC_OCTET;
363+
ctx->multipart_stream->flags &= ~SIO_TEXT;
357364
return TRUE;
358365
}
359366
case s_end:

0 commit comments

Comments
 (0)