Datum never gets the contentType

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Datum never gets the contentType

Lautaro Fernández
Hi list, I noticed that if I upload some file the same will never get the right content type. This should be done in the message "HTTPPost>>partFromStream:boundary:" if I'm not mistake. And, in my humble opinion the contentType will never be set up in the datum in the message "partFromStream:boundary".

In the "standard message" when completes the datum, it ends the message (I mean that returns thanks to '^') by doing:
[...code]
                ^name -> (aSwazooStream datum: datum boundary: aBoundaryBytes.)
[...more code]

And at that point, the datum's contentType is nil. So, if I change that line, for these three I got the right content type for my uploads:
[...code]
                self readEntityFrom: aSwazooStream datum: datum boundary: aBoundaryBytes. "fullfils the datum"
                datum contentType: contentType.     "completes the datum's contentType read in a previous step"
                ^name -> datum].
[...more code]

What do you think about this?
I missing something or is this some kind of a bug?

Thanks,
Lautaro Fernández

PS: down you will see the differences between the standard message and the one I modified in a more generous context.

---Original message---:

partFromStream: aSwazooStream boundary: aBoundaryBytes
    "one mime part from a stream. Nil if no more multipart data"
    | bytes name filename datum contentType |
    bytes := aSwazooStream nextBytes: 2. self incReadPosition; incReadPosition.
    bytes = '--' asByteArray  ifTrue: [^nil].    "end of multipart data"
       
    name := nil. datum := nil. contentType := nil. "just to avoid compliation warning"
    [true] whileTrue: [| line |  "read all lines and at the end a body of that part"
        line := (aSwazooStream upTo: Character cr asInteger) asByteString.
        self readPosition: self readPosition + line size + 1 "cr".
        line := bytes asString, line. bytes := ''.
        aSwazooStream peekByte = Character lf asInteger ifTrue: [| field | "this is a name line"
            aSwazooStream nextByte.  self incReadPosition. "skip linefeed"
            line isEmpty     ifTrue: [| | "empty line indicates start of entity"
                name isNil ifTrue: [^nil].  "name must be read in previous circle
">>>>>>>>"
                ^name -> (aSwazooStream datum: datum boundary: aBoundaryBytes.)].
"<<<<<<<<"
            field := HeaderField fromLine: line.
            field isContentDisposition ifTrue:
                    [name := (field parameterAt: 'name') copyWithout: $".
                    datum := (self isPostDataStreamedAt: name)
                        ifTrue: [self postData at: name]  "streamed datum must exist before"
                        ifFalse: [HTTPPostDatum new].
                    contentType notNil ifTrue: [datum contentType: contentType]. "if read in prev.circle"
                    filename := field parameterAt: 'filename' .   "only for file uploads"
                    filename notNil ifTrue: [datum filename: (filename copyWithout: $")] ].
            field isContentType ifTrue: [contentType := field mediaType ] ] ]
---end Old message---

---New message:---

partFromStream: aSwazooStream boundary: aBoundaryBytes
    "one mime part from a stream. Nil if no more multipart data"
    | bytes name filename datum contentType |
    bytes := aSwazooStream nextBytes: 2. self incReadPosition; incReadPosition.
    bytes = '--' asByteArray  ifTrue: [^nil].    "end of multipart data"
       
    name := nil. datum := nil. contentType := nil. "just to avoid compliation warning"
    [true] whileTrue: [| line |  "read all lines and at the end a body of that part"
        line := (aSwazooStream upTo: Character cr asInteger) asByteString.
        self readPosition: self readPosition + line size + 1 "cr".
        line := bytes asString, line. bytes := ''.
        aSwazooStream peekByte = Character lf asInteger ifTrue: [| field | "this is a name line"
            aSwazooStream nextByte.  self incReadPosition. "skip linefeed"
            line isEmpty     ifTrue: [| | "empty line indicates start of entity"
                name isNil ifTrue: [^nil].  "name must be read in previous circle"
">>>>>>>
start of the changes "
                self readEntityFrom: aSwazooStream datum: datum boundary: aBoundaryBytes. "fullfils the datum"
                datum contentType: contentType.     "completes the datum's contentType read in a previous step"
                ^name -> datum].
"end of the changes
<<<<<<<<<<"

            field := HeaderField fromLine: line.
            field isContentDisposition ifTrue:
                    [name := (field parameterAt: 'name') copyWithout: $".
                    datum := (self isPostDataStreamedAt: name)
                        ifTrue: [self postData at: name]  "streamed datum must exist before"
                        ifFalse: [HTTPPostDatum new].
                    contentType notNil ifTrue: [datum contentType: contentType]. "if read in prev.circle"
                    filename := field parameterAt: 'filename' .   "only for file uploads"
                    filename notNil ifTrue: [datum filename: (filename copyWithout: $")] ].
            field isContentType ifTrue: [contentType := field mediaType ] ] ]
--- End New message---
--
Luke LAut SkyFernadezWalker
Reply | Threaded
Open this post in threaded view
|

Re: Datum never gets the contentType

Bruce Badger
It would be really great if you could make an SUnit test for this.
Would you be able to do that?

2008/6/24 Lautaro Fernández <[hidden email]>:

> Hi list, I noticed that if I upload some file the same will never get the
> right content type. This should be done in the message
> "HTTPPost>>partFromStream:boundary:" if I'm not mistake. And, in my humble
> opinion the contentType will never be set up in the datum in the message
> "partFromStream:boundary".
>
> In the "standard message" when completes the datum, it ends the message (I
> mean that returns thanks to '^') by doing:
> [...code]
>                 ^name -> (aSwazooStream datum: datum boundary:
> aBoundaryBytes.)
> [...more code]
>
> And at that point, the datum's contentType is nil. So, if I change that
> line, for these three I got the right content type for my uploads:
> [...code]
>                 self readEntityFrom: aSwazooStream datum: datum boundary:
> aBoundaryBytes. "fullfils the datum"
>                 datum contentType: contentType.     "completes the datum's
> contentType read in a previous step"
>                 ^name -> datum].
> [...more code]
>
> What do you think about this?
> I missing something or is this some kind of a bug?
>
> Thanks,
> Lautaro Fernández
>
> PS: down you will see the differences between the standard message and the
> one I modified in a more generous context.
>
> ---Original message---:
>
> partFromStream: aSwazooStream boundary: aBoundaryBytes
>     "one mime part from a stream. Nil if no more multipart data"
>     | bytes name filename datum contentType |
>     bytes := aSwazooStream nextBytes: 2. self incReadPosition;
> incReadPosition.
>     bytes = '--' asByteArray  ifTrue: [^nil].    "end of multipart data"
>
>     name := nil. datum := nil. contentType := nil. "just to avoid
> compliation warning"
>     [true] whileTrue: [| line |  "read all lines and at the end a body of
> that part"
>         line := (aSwazooStream upTo: Character cr asInteger) asByteString.
>         self readPosition: self readPosition + line size + 1 "cr".
>         line := bytes asString, line. bytes := ''.
>         aSwazooStream peekByte = Character lf asInteger ifTrue: [| field |
> "this is a name line"
>             aSwazooStream nextByte.  self incReadPosition. "skip linefeed"
>             line isEmpty     ifTrue: [| | "empty line indicates start of
> entity"
>                 name isNil ifTrue: [^nil].  "name must be read in previous
> circle
> ">>>>>>>>"
>                 ^name -> (aSwazooStream datum: datum boundary:
> aBoundaryBytes.)].
> "<<<<<<<<"
>             field := HeaderField fromLine: line.
>             field isContentDisposition ifTrue:
>                     [name := (field parameterAt: 'name') copyWithout: $".
>                     datum := (self isPostDataStreamedAt: name)
>                         ifTrue: [self postData at: name]  "streamed datum
> must exist before"
>                         ifFalse: [HTTPPostDatum new].
>                     contentType notNil ifTrue: [datum contentType:
> contentType]. "if read in prev.circle"
>                     filename := field parameterAt: 'filename' .   "only for
> file uploads"
>                     filename notNil ifTrue: [datum filename: (filename
> copyWithout: $")] ].
>             field isContentType ifTrue: [contentType := field mediaType ] ]
> ]
> ---end Old message---
>
> ---New message:---
>
> partFromStream: aSwazooStream boundary: aBoundaryBytes
>     "one mime part from a stream. Nil if no more multipart data"
>     | bytes name filename datum contentType |
>     bytes := aSwazooStream nextBytes: 2. self incReadPosition;
> incReadPosition.
>     bytes = '--' asByteArray  ifTrue: [^nil].    "end of multipart data"
>
>     name := nil. datum := nil. contentType := nil. "just to avoid
> compliation warning"
>     [true] whileTrue: [| line |  "read all lines and at the end a body of
> that part"
>         line := (aSwazooStream upTo: Character cr asInteger) asByteString.
>         self readPosition: self readPosition + line size + 1 "cr".
>         line := bytes asString, line. bytes := ''.
>         aSwazooStream peekByte = Character lf asInteger ifTrue: [| field |
> "this is a name line"
>             aSwazooStream nextByte.  self incReadPosition. "skip linefeed"
>             line isEmpty     ifTrue: [| | "empty line indicates start of
> entity"
>                 name isNil ifTrue: [^nil].  "name must be read in previous
> circle"
> ">>>>>>>
> start of the changes "
>                 self readEntityFrom: aSwazooStream datum: datum boundary:
> aBoundaryBytes. "fullfils the datum"
>                 datum contentType: contentType.     "completes the datum's
> contentType read in a previous step"
>                 ^name -> datum].
> "end of the changes
> <<<<<<<<<<"
>
>             field := HeaderField fromLine: line.
>             field isContentDisposition ifTrue:
>                     [name := (field parameterAt: 'name') copyWithout: $".
>                     datum := (self isPostDataStreamedAt: name)
>                         ifTrue: [self postData at: name]  "streamed datum
> must exist before"
>                         ifFalse: [HTTPPostDatum new].
>                     contentType notNil ifTrue: [datum contentType:
> contentType]. "if read in prev.circle"
>                     filename := field parameterAt: 'filename' .   "only for
> file uploads"
>                     filename notNil ifTrue: [datum filename: (filename
> copyWithout: $")] ].
>             field isContentType ifTrue: [contentType := field mediaType ] ]
> ]
> --- End New message---
> --
> Luke LAut SkyFernadezWalker
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Swazoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/swazoo-devel
>
>



--
Make the most of your skills - with OpenSkills
http://www.openskills.org/
Reply | Threaded
Open this post in threaded view
|

Re: Datum never gets the contentType

Lautaro Fernández
Hi Bruce, sorry for this delayed mail...
Here you have a test that doesn't pass the contentType.

HTTPRequestTest>>testContentType
    | post |
    post := self postFile. "set the data to the post"
    self assert: post isPostDataEmpty not. "read the content of the stream"
(*) self assert: (post postDataAt: 'field7') contentType = 'application/octet-stream'.

At that point (*) "(post postDataAt: 'field7') contentType" is equal to: 'text/plain', but if you see the message HTTPRequestTest>>postFile the content type is  'application/octet-stream'.

With the lines I added in "HTTPPost>>partFromStream:boundary:" the content type is the right one.

Hope this helps,
Lautaro Fernández

2008/6/26 Bruce Badger <[hidden email]>:
It would be really great if you could make an SUnit test for this.
Would you be able to do that?

2008/6/24 Lautaro Fernández <[hidden email]>:
> Hi list, I noticed that if I upload some file the same will never get the
> right content type. This should be done in the message
> "HTTPPost>>partFromStream:boundary:" if I'm not mistake. And, in my humble
> opinion the contentType will never be set up in the datum in the message
> "partFromStream:boundary".
>
> In the "standard message" when completes the datum, it ends the message (I
> mean that returns thanks to '^') by doing:
> [...code]
>                 ^name -> (aSwazooStream datum: datum boundary:
> aBoundaryBytes.)
> [...more code]
>
> And at that point, the datum's contentType is nil. So, if I change that
> line, for these three I got the right content type for my uploads:
> [...code]
>                 self readEntityFrom: aSwazooStream datum: datum boundary:
> aBoundaryBytes. "fullfils the datum"
>                 datum contentType: contentType.     "completes the datum's
> contentType read in a previous step"
>                 ^name -> datum].
> [...more code]
>
> What do you think about this?
> I missing something or is this some kind of a bug?
>
> Thanks,
> Lautaro Fernández
>
> PS: down you will see the differences between the standard message and the
> one I modified in a more generous context.
>
> ---Original message---:
>
> partFromStream: aSwazooStream boundary: aBoundaryBytes
>     "one mime part from a stream. Nil if no more multipart data"
>     | bytes name filename datum contentType |
>     bytes := aSwazooStream nextBytes: 2. self incReadPosition;
> incReadPosition.
>     bytes = '--' asByteArray  ifTrue: [^nil].    "end of multipart data"
>
>     name := nil. datum := nil. contentType := nil. "just to avoid
> compliation warning"
>     [true] whileTrue: [| line |  "read all lines and at the end a body of
> that part"
>         line := (aSwazooStream upTo: Character cr asInteger) asByteString.
>         self readPosition: self readPosition + line size + 1 "cr".
>         line := bytes asString, line. bytes := ''.
>         aSwazooStream peekByte = Character lf asInteger ifTrue: [| field |
> "this is a name line"
>             aSwazooStream nextByte.  self incReadPosition. "skip linefeed"
>             line isEmpty     ifTrue: [| | "empty line indicates start of
> entity"
>                 name isNil ifTrue: [^nil].  "name must be read in previous
> circle
> ">>>>>>>>"
>                 ^name -> (aSwazooStream datum: datum boundary:
> aBoundaryBytes.)].
> "<<<<<<<<"
>             field := HeaderField fromLine: line.
>             field isContentDisposition ifTrue:
>                     [name := (field parameterAt: 'name') copyWithout: $".
>                     datum := (self isPostDataStreamedAt: name)
>                         ifTrue: [self postData at: name]  "streamed datum
> must exist before"
>                         ifFalse: [HTTPPostDatum new].
>                     contentType notNil ifTrue: [datum contentType:
> contentType]. "if read in prev.circle"
>                     filename := field parameterAt: 'filename' .   "only for
> file uploads"
>                     filename notNil ifTrue: [datum filename: (filename
> copyWithout: $")] ].
>             field isContentType ifTrue: [contentType := field mediaType ] ]
> ]
> ---end Old message---
>
> ---New message:---
>
> partFromStream: aSwazooStream boundary: aBoundaryBytes
>     "one mime part from a stream. Nil if no more multipart data"
>     | bytes name filename datum contentType |
>     bytes := aSwazooStream nextBytes: 2. self incReadPosition;
> incReadPosition.
>     bytes = '--' asByteArray  ifTrue: [^nil].    "end of multipart data"
>
>     name := nil. datum := nil. contentType := nil. "just to avoid
> compliation warning"
>     [true] whileTrue: [| line |  "read all lines and at the end a body of
> that part"
>         line := (aSwazooStream upTo: Character cr asInteger) asByteString.
>         self readPosition: self readPosition + line size + 1 "cr".
>         line := bytes asString, line. bytes := ''.
>         aSwazooStream peekByte = Character lf asInteger ifTrue: [| field |
> "this is a name line"
>             aSwazooStream nextByte.  self incReadPosition. "skip linefeed"
>             line isEmpty     ifTrue: [| | "empty line indicates start of
> entity"
>                 name isNil ifTrue: [^nil].  "name must be read in previous
> circle"
> ">>>>>>>
> start of the changes "
>                 self readEntityFrom: aSwazooStream datum: datum boundary:
> aBoundaryBytes. "fullfils the datum"
>                 datum contentType: contentType.     "completes the datum's
> contentType read in a previous step"
>                 ^name -> datum].
> "end of the changes
> <<<<<<<<<<"
>
>             field := HeaderField fromLine: line.
>             field isContentDisposition ifTrue:
>                     [name := (field parameterAt: 'name') copyWithout: $".
>                     datum := (self isPostDataStreamedAt: name)
>                         ifTrue: [self postData at: name]  "streamed datum
> must exist before"
>                         ifFalse: [HTTPPostDatum new].
>                     contentType notNil ifTrue: [datum contentType:
> contentType]. "if read in prev.circle"
>                     filename := field parameterAt: 'filename' .   "only for
> file uploads"
>                     filename notNil ifTrue: [datum filename: (filename
> copyWithout: $")] ].
>             field isContentType ifTrue: [contentType := field mediaType ] ]
> ]
> --- End New message---
> --
> Luke LAut SkyFernadezWalker
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> Swazoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/swazoo-devel
>
>



--
Make the most of your skills - with OpenSkills
http://www.openskills.org/
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel



--
Luke LAut SkyFernadezWalker
Reply | Threaded
Open this post in threaded view
|

Re: Datum never gets the contentType

Janko Mivšek
Lautaro,

Perfect, you just solved a problem I also had few days ago! I just
adding your patch to Swazoo, now it goes to testing on production
systems. Expect it in the next release, probably before ESUG conference.

PS: My apologies for not being responsive to you too!

Best regards
JAnko

Lautaro Fernández wrote:

> Hi Bruce, sorry for this delayed mail...
> Here you have a test that doesn't pass the contentType.
>
> HTTPRequestTest>>testContentType
>     | post |
>     post := self postFile. "set the data to the post"
>     self assert: post isPostDataEmpty not. "read the content of the stream"
> (*) self assert: (post postDataAt: 'field7') contentType =
> 'application/octet-stream'.
>
> At that point (*) "(post postDataAt: 'field7') contentType" is equal to:
> 'text/plain', but if you see the message HTTPRequestTest>>postFile the
> content type is  'application/octet-stream'.
>
> With the lines I added in "HTTPPost>>partFromStream:boundary:" the
> content type is the right one.
>
> Hope this helps,
> Lautaro Fernández
>
> 2008/6/26 Bruce Badger <[hidden email] <mailto:[hidden email]>>:
>
>     It would be really great if you could make an SUnit test for this.
>     Would you be able to do that?
>
>     2008/6/24 Lautaro Fernández <[hidden email]
>     <mailto:[hidden email]>>:
>      > Hi list, I noticed that if I upload some file the same will never
>     get the
>      > right content type. This should be done in the message
>      > "HTTPPost>>partFromStream:boundary:" if I'm not mistake. And, in
>     my humble
>      > opinion the contentType will never be set up in the datum in the
>     message
>      > "partFromStream:boundary".
>      >
>      > In the "standard message" when completes the datum, it ends the
>     message (I
>      > mean that returns thanks to '^') by doing:
>      > [...code]
>      >                 ^name -> (aSwazooStream datum: datum boundary:
>      > aBoundaryBytes.)
>      > [...more code]
>      >
>      > And at that point, the datum's contentType is nil. So, if I
>     change that
>      > line, for these three I got the right content type for my uploads:
>      > [...code]
>      >                 self readEntityFrom: aSwazooStream datum: datum
>     boundary:
>      > aBoundaryBytes. "fullfils the datum"
>      >                 datum contentType: contentType.     "completes
>     the datum's
>      > contentType read in a previous step"
>      >                 ^name -> datum].
>      > [...more code]
>      >
>      > What do you think about this?
>      > I missing something or is this some kind of a bug?
>      >
>      > Thanks,
>      > Lautaro Fernández
>      >
>      > PS: down you will see the differences between the standard
>     message and the
>      > one I modified in a more generous context.
>      >
>      > ---Original message---:
>      >
>      > partFromStream: aSwazooStream boundary: aBoundaryBytes
>      >     "one mime part from a stream. Nil if no more multipart data"
>      >     | bytes name filename datum contentType |
>      >     bytes := aSwazooStream nextBytes: 2. self incReadPosition;
>      > incReadPosition.
>      >     bytes = '--' asByteArray  ifTrue: [^nil].    "end of
>     multipart data"
>      >
>      >     name := nil. datum := nil. contentType := nil. "just to avoid
>      > compliation warning"
>      >     [true] whileTrue: [| line |  "read all lines and at the end a
>     body of
>      > that part"
>      >         line := (aSwazooStream upTo: Character cr asInteger)
>     asByteString.
>      >         self readPosition: self readPosition + line size + 1 "cr".
>      >         line := bytes asString, line. bytes := ''.
>      >         aSwazooStream peekByte = Character lf asInteger ifTrue:
>     [| field |
>      > "this is a name line"
>      >             aSwazooStream nextByte.  self incReadPosition. "skip
>     linefeed"
>      >             line isEmpty     ifTrue: [| | "empty line indicates
>     start of
>      > entity"
>      >                 name isNil ifTrue: [^nil].  "name must be read in
>     previous
>      > circle
>      > ">>>>>>>>"
>      >                 ^name -> (aSwazooStream datum: datum boundary:
>      > aBoundaryBytes.)].
>      > "<<<<<<<<"
>      >             field := HeaderField fromLine: line.
>      >             field isContentDisposition ifTrue:
>      >                     [name := (field parameterAt: 'name')
>     copyWithout: $".
>      >                     datum := (self isPostDataStreamedAt: name)
>      >                         ifTrue: [self postData at: name]
>      "streamed datum
>      > must exist before"
>      >                         ifFalse: [HTTPPostDatum new].
>      >                     contentType notNil ifTrue: [datum contentType:
>      > contentType]. "if read in prev.circle"
>      >                     filename := field parameterAt: 'filename' .  
>     "only for
>      > file uploads"
>      >                     filename notNil ifTrue: [datum filename:
>     (filename
>      > copyWithout: $")] ].
>      >             field isContentType ifTrue: [contentType := field
>     mediaType ] ]
>      > ]
>      > ---end Old message---
>      >
>      > ---New message:---
>      >
>      > partFromStream: aSwazooStream boundary: aBoundaryBytes
>      >     "one mime part from a stream. Nil if no more multipart data"
>      >     | bytes name filename datum contentType |
>      >     bytes := aSwazooStream nextBytes: 2. self incReadPosition;
>      > incReadPosition.
>      >     bytes = '--' asByteArray  ifTrue: [^nil].    "end of
>     multipart data"
>      >
>      >     name := nil. datum := nil. contentType := nil. "just to avoid
>      > compliation warning"
>      >     [true] whileTrue: [| line |  "read all lines and at the end a
>     body of
>      > that part"
>      >         line := (aSwazooStream upTo: Character cr asInteger)
>     asByteString.
>      >         self readPosition: self readPosition + line size + 1 "cr".
>      >         line := bytes asString, line. bytes := ''.
>      >         aSwazooStream peekByte = Character lf asInteger ifTrue:
>     [| field |
>      > "this is a name line"
>      >             aSwazooStream nextByte.  self incReadPosition. "skip
>     linefeed"
>      >             line isEmpty     ifTrue: [| | "empty line indicates
>     start of
>      > entity"
>      >                 name isNil ifTrue: [^nil].  "name must be read in
>     previous
>      > circle"
>      > ">>>>>>>
>      > start of the changes "
>      >                 self readEntityFrom: aSwazooStream datum: datum
>     boundary:
>      > aBoundaryBytes. "fullfils the datum"
>      >                 datum contentType: contentType.     "completes
>     the datum's
>      > contentType read in a previous step"
>      >                 ^name -> datum].
>      > "end of the changes
>      > <<<<<<<<<<"
>      >
>      >             field := HeaderField fromLine: line.
>      >             field isContentDisposition ifTrue:
>      >                     [name := (field parameterAt: 'name')
>     copyWithout: $".
>      >                     datum := (self isPostDataStreamedAt: name)
>      >                         ifTrue: [self postData at: name]
>      "streamed datum
>      > must exist before"
>      >                         ifFalse: [HTTPPostDatum new].
>      >                     contentType notNil ifTrue: [datum contentType:
>      > contentType]. "if read in prev.circle"
>      >                     filename := field parameterAt: 'filename' .  
>     "only for
>      > file uploads"
>      >                     filename notNil ifTrue: [datum filename:
>     (filename
>      > copyWithout: $")] ].
>      >             field isContentType ifTrue: [contentType := field
>     mediaType ] ]
>      > ]
>      > --- End New message---
>      > --
>      > Luke LAut SkyFernadezWalker
>      >
>     -------------------------------------------------------------------------
>      > Check out the new SourceForge.net Marketplace.
>      > It's the best place to buy or sell services for
>      > just about anything Open Source.
>      > http://sourceforge.net/services/buy/index.php
>      > _______________________________________________
>      > Swazoo-devel mailing list
>      > [hidden email]
>     <mailto:[hidden email]>
>      > https://lists.sourceforge.net/lists/listinfo/swazoo-devel
>      >
>      >
>
>
>
>     --
>     Make the most of your skills - with OpenSkills
>     http://www.openskills.org/
>     -------------------------------------------------------------------------
>     Check out the new SourceForge.net Marketplace.
>     It's the best place to buy or sell services for
>     just about anything Open Source.
>     http://sourceforge.net/services/buy/index.php
>     _______________________________________________
>     Swazoo-devel mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     https://lists.sourceforge.net/lists/listinfo/swazoo-devel
>
>
>
>
> --
> Luke LAut SkyFernadezWalker
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Swazoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/swazoo-devel

--
Janko Mivšek
Svetovalec za informatiko
Eranova d.o.o.
Ljubljana, Slovenija
www.eranova.si
tel:  01 514 22 55
faks: 01 514 22 56
gsm: 031 674 565


Reply | Threaded
Open this post in threaded view
|

Re: Datum never gets the contentType

Lautaro Fernández
Hi Janko,
I'm glad that the patch helped you. It took me  some time to realize where was the problem but I didn't know if it was mine.

Thanks for your answers and again I'm happy to help
Bye bye!
Lautaro

2008/6/30 Janko Mivšek <[hidden email]>:
Lautaro,

Perfect, you just solved a problem I also had few days ago! I just
adding your patch to Swazoo, now it goes to testing on production
systems. Expect it in the next release, probably before ESUG conference.

PS: My apologies for not being responsive to you too!

Best regards
JAnko

Lautaro Fernández wrote:
> Hi Bruce, sorry for this delayed mail...
> Here you have a test that doesn't pass the contentType.
>
> HTTPRequestTest>>testContentType
>     | post |
>     post := self postFile. "set the data to the post"
>     self assert: post isPostDataEmpty not. "read the content of the stream"
> (*) self assert: (post postDataAt: 'field7') contentType =
> 'application/octet-stream'.
>
> At that point (*) "(post postDataAt: 'field7') contentType" is equal to:
> 'text/plain', but if you see the message HTTPRequestTest>>postFile the
> content type is  'application/octet-stream'.
>
> With the lines I added in "HTTPPost>>partFromStream:boundary:" the
> content type is the right one.
>
> Hope this helps,
> Lautaro Fernández
>
> 2008/6/26 Bruce Badger <[hidden email] <mailto:[hidden email]>>:
>
>     It would be really great if you could make an SUnit test for this.
>     Would you be able to do that?
>
>     2008/6/24 Lautaro Fernández <[hidden email]
>     <mailto:[hidden email]>>:
>      > Hi list, I noticed that if I upload some file the same will never
>     get the
>      > right content type. This should be done in the message
>      > "HTTPPost>>partFromStream:boundary:" if I'm not mistake. And, in
>     my humble
>      > opinion the contentType will never be set up in the datum in the
>     message
>      > "partFromStream:boundary".
>      >
>      > In the "standard message" when completes the datum, it ends the
>     message (I
>      > mean that returns thanks to '^') by doing:
>      > [...code]
>      >                 ^name -> (aSwazooStream datum: datum boundary:
>      > aBoundaryBytes.)
>      > [...more code]
>      >
>      > And at that point, the datum's contentType is nil. So, if I
>     change that
>      > line, for these three I got the right content type for my uploads:
>      > [...code]
>      >                 self readEntityFrom: aSwazooStream datum: datum
>     boundary:
>      > aBoundaryBytes. "fullfils the datum"
>      >                 datum contentType: contentType.     "completes
>     the datum's
>      > contentType read in a previous step"
>      >                 ^name -> datum].
>      > [...more code]
>      >
>      > What do you think about this?
>      > I missing something or is this some kind of a bug?
>      >
>      > Thanks,
>      > Lautaro Fernández
>      >
>      > PS: down you will see the differences between the standard
>     message and the
>      > one I modified in a more generous context.
>      >
>      > ---Original message---:
>      >
>      > partFromStream: aSwazooStream boundary: aBoundaryBytes
>      >     "one mime part from a stream. Nil if no more multipart data"
>      >     | bytes name filename datum contentType |
>      >     bytes := aSwazooStream nextBytes: 2. self incReadPosition;
>      > incReadPosition.
>      >     bytes = '--' asByteArray  ifTrue: [^nil].    "end of
>     multipart data"
>      >
>      >     name := nil. datum := nil. contentType := nil. "just to avoid
>      > compliation warning"
>      >     [true] whileTrue: [| line |  "read all lines and at the end a
>     body of
>      > that part"
>      >         line := (aSwazooStream upTo: Character cr asInteger)
>     asByteString.
>      >         self readPosition: self readPosition + line size + 1 "cr".
>      >         line := bytes asString, line. bytes := ''.
>      >         aSwazooStream peekByte = Character lf asInteger ifTrue:
>     [| field |
>      > "this is a name line"
>      >             aSwazooStream nextByte.  self incReadPosition. "skip
>     linefeed"
>      >             line isEmpty     ifTrue: [| | "empty line indicates
>     start of
>      > entity"
>      >                 name isNil ifTrue: [^nil].  "name must be read in
>     previous
>      > circle
>      > ">>>>>>>>"
>      >                 ^name -> (aSwazooStream datum: datum boundary:
>      > aBoundaryBytes.)].
>      > "<<<<<<<<"
>      >             field := HeaderField fromLine: line.
>      >             field isContentDisposition ifTrue:
>      >                     [name := (field parameterAt: 'name')
>     copyWithout: $".
>      >                     datum := (self isPostDataStreamedAt: name)
>      >                         ifTrue: [self postData at: name]
>      "streamed datum
>      > must exist before"
>      >                         ifFalse: [HTTPPostDatum new].
>      >                     contentType notNil ifTrue: [datum contentType:
>      > contentType]. "if read in prev.circle"
>      >                     filename := field parameterAt: 'filename' .
>     "only for
>      > file uploads"
>      >                     filename notNil ifTrue: [datum filename:
>     (filename
>      > copyWithout: $")] ].
>      >             field isContentType ifTrue: [contentType := field
>     mediaType ] ]
>      > ]
>      > ---end Old message---
>      >
>      > ---New message:---
>      >
>      > partFromStream: aSwazooStream boundary: aBoundaryBytes
>      >     "one mime part from a stream. Nil if no more multipart data"
>      >     | bytes name filename datum contentType |
>      >     bytes := aSwazooStream nextBytes: 2. self incReadPosition;
>      > incReadPosition.
>      >     bytes = '--' asByteArray  ifTrue: [^nil].    "end of
>     multipart data"
>      >
>      >     name := nil. datum := nil. contentType := nil. "just to avoid
>      > compliation warning"
>      >     [true] whileTrue: [| line |  "read all lines and at the end a
>     body of
>      > that part"
>      >         line := (aSwazooStream upTo: Character cr asInteger)
>     asByteString.
>      >         self readPosition: self readPosition + line size + 1 "cr".
>      >         line := bytes asString, line. bytes := ''.
>      >         aSwazooStream peekByte = Character lf asInteger ifTrue:
>     [| field |
>      > "this is a name line"
>      >             aSwazooStream nextByte.  self incReadPosition. "skip
>     linefeed"
>      >             line isEmpty     ifTrue: [| | "empty line indicates
>     start of
>      > entity"
>      >                 name isNil ifTrue: [^nil].  "name must be read in
>     previous
>      > circle"
>      > ">>>>>>>
>      > start of the changes "
>      >                 self readEntityFrom: aSwazooStream datum: datum
>     boundary:
>      > aBoundaryBytes. "fullfils the datum"
>      >                 datum contentType: contentType.     "completes
>     the datum's
>      > contentType read in a previous step"
>      >                 ^name -> datum].
>      > "end of the changes
>      > <<<<<<<<<<"
>      >
>      >             field := HeaderField fromLine: line.
>      >             field isContentDisposition ifTrue:
>      >                     [name := (field parameterAt: 'name')
>     copyWithout: $".
>      >                     datum := (self isPostDataStreamedAt: name)
>      >                         ifTrue: [self postData at: name]
>      "streamed datum
>      > must exist before"
>      >                         ifFalse: [HTTPPostDatum new].
>      >                     contentType notNil ifTrue: [datum contentType:
>      > contentType]. "if read in prev.circle"
>      >                     filename := field parameterAt: 'filename' .
>     "only for
>      > file uploads"
>      >                     filename notNil ifTrue: [datum filename:
>     (filename
>      > copyWithout: $")] ].
>      >             field isContentType ifTrue: [contentType := field
>     mediaType ] ]
>      > ]
>      > --- End New message---
>      > --
>      > Luke LAut SkyFernadezWalker
>      >
>     -------------------------------------------------------------------------
>      > Check out the new SourceForge.net Marketplace.
>      > It's the best place to buy or sell services for
>      > just about anything Open Source.
>      > http://sourceforge.net/services/buy/index.php
>      > _______________________________________________
>      > Swazoo-devel mailing list
>      > [hidden email]
>     <mailto:[hidden email]>
>      > https://lists.sourceforge.net/lists/listinfo/swazoo-devel
>      >
>      >
>
>
>
>     --
>     Make the most of your skills - with OpenSkills
>     http://www.openskills.org/
>     -------------------------------------------------------------------------
>     Check out the new SourceForge.net Marketplace.
>     It's the best place to buy or sell services for
>     just about anything Open Source.
>     http://sourceforge.net/services/buy/index.php
>     _______________________________________________
>     Swazoo-devel mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     https://lists.sourceforge.net/lists/listinfo/swazoo-devel
>
>
>
>
> --
> Luke LAut SkyFernadezWalker
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Swazoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/swazoo-devel

--
Janko Mivšek
Svetovalec za informatiko
Eranova d.o.o.
Ljubljana, Slovenija
www.eranova.si
tel:  01 514 22 55
faks: 01 514 22 56
gsm: 031 674 565

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Swazoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swazoo-devel



--
Luke LAut SkyFernadezWalker
Reply | Threaded
Open this post in threaded view
|

Re: Datum never gets the contentType

Bruce Badger
In reply to this post by Lautaro Fernández
Lautaro,

Heh - I'd not heard of "buena onda" before.  Thanks for the test case
and the supporting methods (which I should have seen in your original
method - doh!).

Just so you know, Hyper branch of the Swazoo HTTP server works fine
with this test, and has been able to handle this case for several
years.

It's good to have your test in the test suite, so many thanks again
for producing that.

All the best,
    Bruce
--
Make the most of your skills - with OpenSkills
http://www.openskills.org/