Aloe Express; MimeTypes;

Hello,

can You put another MimeType into Aloe Express?

MimeTypes.Value("mjs") = "application/javascript"  // needed for ES6 modules

in method MIMETypeGet

By the way, dictionary is rebuild for every call to MIMETypeGet (even UseETags sends “not changed” to further calls to same file).
Would a property as dictionary not be easier? (Don’t know all the dependencies in Aloe Express either;-)

Thanks a lot!

[quote=442928:@Hans-Norbert Gratzal]Hello,
By the way, dictionary is rebuild for every call to MIMETypeGet (even UseETags sends “not changed” to further calls to same file).
Would a property as dictionary not be easier? (Don’t know all the dependencies in Aloe Express either;-)

Thanks a lot![/quote]

I went through the code in detail. In my copy of the code I changed the start of the method from:

Dim MimeTypes As New Dictionary ' Add all the MimeTypes

To:

[code]STATIC MimeTypes As Dictionary

If MIMETypes Is NIL Then
MimeTypes = New Dictionary
’ Add all the MimeTypes
End if
[/code]

And it does not cause any issued… For something like this I like using Static as you only need to have one instance of the dictionary AND it does not clutter up the properties list (For almost 2 decades I wished I could put properties in classes and modules into folders to group/organize them when there is a lot in Xojo/RS/RB!)

I also found a repository of MIMETypes on the web and added the ones not already there so for you use can add whatever MIMETypes you want.

  • karen

Hello Karen!

Thanks a lot for Your info and the tipps!

Of course, and I did so; but everything must be redone when getting a new version of the tool; but, no problem. Will keep it documented.

[code]STATIC MimeTypes As Dictionary

If MIMETypes Is NIL Then
MimeTypes = New Dictionary
’ Add all the MimeTypes
End if[/code]

Very good idea to have a direct solution!
I don’t like Xojo’s static because it’s global to the class not to the method only; I even would consider it a “false static”.

Ok, everything works fine!
Thanks a lot again!
Regards!

In which case you should be using a private property on the class.

In this case the list of MIMETypes should be same for all class instances. It makes no sense to recreate the dictionary for every instance…

As this is for a server, one wants to keep system resource use (processor and ram) to a minimum, so it should either be DIMed as Static, or as a private shared property on the class, and only initialized once.

[quote=443052:@Hans-Norbert Gratzal]I don’t like Xojo’s static because it’s global to the class not to the method only; I even would consider it a “false static”.

[/quote]

I think you are getting STATIC variables and SHARED properties mixed up.

Static variables are private to the method but shared across all instances .When static variables are defined in instance methods, although shared across all instances they can only be accessed within that method within instances, and never outside that method either from inside or outside the class.

Shared properties are global to the class and independent of any instance. You can set their scope to control if they can be accessed outside the class or not and from subclasses or not.

  • Karen