MultiPart Data Support
Support has been added for inbound multipart processing for multipart-form and multipart-mixed subtypes in the Server Smalltalk - HTTP framework.
Multipart is a MIME data type. It was originally defined as part of HTML 4.0. There are several multipart subtypes; we are providing initial support for form and mixed subtypes. The multipart/form-data subtype is most commonly used for submitting files via HTTP. The protocol is similar to chunked transfer encoding, but in this case, each part of the transmission corresponds to the user entries from an HTML form. Multipart form-mixed data is typically used in SMTP email transmissions.
In the VA Smalltalk implementation, Incoming messages are parsed and "assembled" by classes in the Sst Http layer which process the incoming buffer of the socket stream and convert it to an instance of SstByteMessage, which then becomes part of an SstHttpRequest.
SstByteMessages have simple content -- a byte array. A Lookup Table has been added to SstByteMessage to store the message parts. A multipart-aware application can then extract the multipart content; the SstByteMessage will continue to function as it always has with the rest of the existing framework and previously built applications.
When an HTTP request has a Content-Type of multipart/form-data or multipart-mixed, it is parsed by SstHttpMultipartContentAssembler. The message parts are converted into instances of SstMultipartContent and are placed into a LookupTable in SstByteMessage. The original inbound unparsed message content is retained in the content instance variable of SstByteMessage.
For example, after processing this example Http request:
'Host: localhost:3000
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://localhost:3000/
Content-Type: multipart/form-data; boundary=---------------------------114772229410704779042051621609
Content-Length: 721
-----------------------------114772229410704779042051621609
Content-Disposition: form-data; name="name"
Al Smith
-----------------------------114772229410704779042051621609
Content-Disposition: form-data; name="email"
coolaj86@somemail.com
-----------------------------114772229410704779042051621609
Content-Disposition: form-data; name="attachments[]"; filename="file1.txt"
Content-Type: text/plain
This is file 1
-----------------------------114772229410704779042051621609--'
An instance of SstByteMessage would be created that contains a LookupTable with 3 entries. The keys are integer part numbers in the order in which they were encountered. The values are instances of SstMultipartContent.
New SstByteMessage Protocol
multipartContent
returns a LookupTable containing instances of SstMultipartContent representing the message parts.
SstMultipartContent Protocol
contentType
A string containing the content type header field if present.
contentDisposition
A string containing the content disposition header filed if one is present.
fieldName
The field name from the form for multipart/form data.
fileName
A string containing the name of the file if it is a file part.
content
A string containing the content of the part.
headerFields
contains a LookupTable with all header fields stored using field name as they key.
Any header fields which are not stored in instance variables may be found in the headerFields instance variable, which stores them in a LookupTable keyed by field name.
Seaside Support
SstHttpServletRequest has been extended to convert the multipart data into the object (WAFile) it expects.
Last modified date: 04/18/2022