Patrick Rein uploaded a new version of Network to project The Trunk: http://source.squeak.org/trunk/Network-pre.277.mcz
==================== Summary ====================
Name: Network-pre.277 Author: pre Time: 1 June 2023, 2:10:16.680896 pm UUID: f0681b24-25cb-8c4d-aded-38c32566757a Ancestors: Network-mt.276
Implements case-insensitive comparison of MIMETypes and case-insensitive access to parameters.
=============== Diff against Network-mt.276 ===============
Item was changed: Object subclass: #MIMEType instanceVariableNames: 'main sub parameters' classVariableNames: 'DefaultSuffixes StandardMIMEMappings' poolDictionaries: '' category: 'Network-MIME'! + + !MIMEType commentStamp: 'pre 6/1/2023 14:05' prior: 0! + A MIMEType instances represent a specific MIME type including parameters. + + It adheres to https://datatracker.ietf.org/doc/html/rfc2045. + + ------ + + Design decisions: + - the comparison currently normalizes the main and sub-type ad hoc to preserve the original case + - parameter names are normalized to simplify the lookup logic!
Item was changed: ----- Method: MIMEType class>>fromMIMEString: (in category 'instance creation') ----- fromMIMEString: mimeString "Examples: MIMEType fromMIMEString: 'text/plain' MIMEType fromMIMEString: 'text/plain;charset=utf8' MIMEType fromMIMEString: 'Message/Partial; number=2; total=3; id=""oc=jpbe0M2Yt4s@thumper.bellcore.com""'"
| idx main sub parameters | + parameters := OrderedDictionary new. idx := mimeString indexOf: $/. idx = 0 ifTrue: [self error: 'Illegal mime type string "' , mimeString , '".']. main := mimeString copyFrom: 1 to: idx-1. idx := mimeString indexOf: $; startingAt: idx+1. idx = 0 ifTrue: [ sub := mimeString copyFrom: main size + 2 to: mimeString size] ifFalse: [ | pos key val | sub := mimeString copyFrom: main size + 2 to: idx-1. - parameters := OrderedDictionary new. pos := idx. [pos < mimeString size] whileTrue: [ idx := idx + 1. "Skip $;" [(mimeString at: idx) isSeparator] whileTrue: [idx := idx+1]. pos := mimeString indexOf: $= startingAt: idx. key := mimeString copyFrom: idx to: pos-1. idx := pos+1. (mimeString at: idx) = $" ifFalse: ["token" pos := mimeString indexOf: $; startingAt: idx. pos = 0 ifTrue: [pos := mimeString size + 1]. val := mimeString copyFrom: idx to: pos-1. idx := pos] ifTrue: ["quoted-string" idx := idx+1. pos := mimeString indexOf: $" startingAt: idx. pos = 0 ifTrue: [self error: 'Illegal quoted-string in mime type string "' , mimeString , '".']. val := mimeString copyFrom: idx to: pos-1. idx := pos+1]. parameters at: key put: val]]. ^self main: main sub: sub parameters: parameters !
Item was changed: ----- Method: MIMEType class>>main:sub: (in category 'instance creation') ----- main: mainType sub: subType ^self new main: mainType; sub: subType!
Item was changed: ----- Method: MIMEType class>>main:sub:parameters: (in category 'instance creation') ----- main: mainType sub: subType parameters: parameters + + ^(self main: mainType sub: subType) + parameters: parameters; + yourself! - ^self new - main: mainType; - sub: subType; - parameters: parameters!
Item was changed: ----- Method: MIMEType>>= (in category 'comparing') ----- = anotherObject anotherObject class == self class ifFalse: [^false]. + ^self main asLowercase = anotherObject main asLowercase + and: [self sub asLowercase = anotherObject sub asLowercase]! - ^self main = anotherObject main - and: [self sub = anotherObject sub]!
Item was changed: ----- Method: MIMEType>>hash (in category 'comparing') ----- hash + ^self main asLowercase hash bitXor: self sub asLowercase hash! - ^self main hash bitXor: self sub hash!
Item was added: + ----- Method: MIMEType>>initialize (in category 'initialize-release') ----- + initialize + + super initialize. + self + main: ''; + sub: ''; + parameters: OrderedDictionary new.!
Item was added: + ----- Method: MIMEType>>parameterAt: (in category 'accessing') ----- + parameterAt: parameterName + + ^ parameters at: parameterName asLowercase!
Item was removed: - ----- Method: MIMEType>>parameters (in category 'accessing') ----- - parameters - ^ parameters!
Item was changed: ----- Method: MIMEType>>parameters: (in category 'accessing') ----- parameters: params + "We normalize as the access to parameters is case insensitive. --pre" + parameters := Dictionary newFrom: (params keys collect: [:key | + key asLowercase -> (params at: key)]).! - parameters := params!
packages@lists.squeakfoundation.org