Trying to serve prepacked JavaScript GZipped files - jetty

I have gzipped file bundle.js.gz on my Jetty embedded server.
I have added correct Mime type and encoding, but I am still getting
bundle.js.gz:1 Uncaught SyntaxError: Unexpected token ILLEGAL error in Chrome.
This is how I add the encoding to to the handler:
MimeTypes mimeTypes = externalWebApp.getMimeTypes();
mimeTypes.addMimeMapping("gz", "text/javascript; gzip");
This takes change, I can see Content-Type: text/javascript; gzip in Chrome Dev tools.
I try to include the resource like this:
<script src="/dist/bundle.js.gz" /></script>
Any suggestions?

Related

Django CORS header ‘Access-Control-Allow-Origin’ missing despite being in Response Headers

I have a webpage with a Django Backend API and an angular frontend SPA. I have django-cors-headers==3.5.0 installed and set up (configurations at the end). When trying to load an .mp3 file from my angular frontend SPA from localhost:4200, and only when loading the mp3 file, I receive the following error message:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading
the remote resource at
https://www.aldrune.com/media/session_audio/2020-12-01_-_Session_28.mp3.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Please note that at the same time I am able to take a look at the HTTP Request and I can see that contrary to the given error message, the response DOES have the header:
Access-Control-Allow-Origin: *
What gives? How can I have the header in my response and yet my browser claims it's not there? And why does this only happen with the .mp3 file, while all my media and static-file images, that stem from the exact same application- and http-server are unaffected?
I am aware a lot of similar questions about Djanog and CORS have been asked before, but I couldn't find any that asked while seeing very clearly that the header that supposedly isn't there is very visible in the request.
Below the setup on my server:
#settings.py
INSTALLED_APPS : list = [
...
'corsheaders',
...
]
...
MIDDLEWARE : list = [
'corsheaders.middleware.CorsMiddleware',
...
'csp.middleware.CSPMiddleware',
]
...
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_HEADERS = default_headers + (
"content-disposition",
)
Edit: As requested I went and checked my headers with postman. As he expected, the headers of the response directly to the url of the .mp3 file (https://www.aldrune.com/media/session_audio/2020-12-01_-_Session_28.mp3.) did not contain the said header.
#Sideshowbarker and #Kevin Christopher Henry brought me down the correct path on this one. The request that failed was not the one I showed a screenshot for, that was a request to my API for data of the webpage which runs on Django for which I do have a CORS header. The request that failed however was the request explicitly for the .mp3 files. And that one was routed from my HTTP Server directly to my media file, as opposed to running through Django where it would've received a CORS header.
Also contrary to my previous understanding the browser is the one stating by default via its Same-Origin-Policy that I, running my frontend dev-server on localhost, do not get access to content on my server aldrune.com unless the server says that this origin "localhost" is ok.
So given that (based on how you typically deploy with Django) your files are served via the HTTP Server and not via Django, you need to configure your HTTP Server to give back a CORS header that allows your localhost to access the file, in my case that was Apache.
As such I added a rule to my apache config specifically for my media files to allow the localhost origin - no need to allow more than necessary. A short resource about this can be found here.
<Directory /path/to/my/media/directory>
... //Other settings for this directory not shown
SetEnvIf Origin "(http)?(s)?(://)?(www\.)?(localhost:4200|aldrune.com.*)" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true
</Directory>

How can I activate json compression for litespeed web server?

I'm using lottiefiles and want to activate json compression to improve my gtmetrix score... How can I activate that with litespeed web server?
Thank you in advance!
I got this answer from Lucas Rolff at wpcache slack channel:
LiteSpeed does not automatically compress json, neither as gzip or brotli, the default compressed types are:
text/*, application/x-javascript, application/xml, application/javascript, image/svg+xml,application/rss+xml
This can be modified in the LiteSpeed WebAdmin console under Configuration -> Server -> Tuning, if you want to include json (MIME type being application/json), or use the AddOutputFilterByType as in the link above in your htaccess file.
I added application/json in my LiteSpeed WebAdmin console and it is working perfect!
We have updated the default compressible type, MIME type application/json is in the default list now for new installation.

JMeter returns wsdl as a response

Im trying to do simple web service test using JMeter. I'm using SOAP/XML-RPC Request with simpliest configuration
URL = https://...address here..?wsdl
SOAP action and Use KeepAlive stay unchecked
XML request is loaded from file, correctly
What is more i have added View Result Tree to see results.
Thats all.
Problem is i'm still getting whole wsdl file as a response (i have expected a normal soap response for my xml soap requst).
I have tested in SOAPui this request and url - everythink working fine. Do i need do add smth more? maybe this is problem with https protocol?
What is more i have tried WebService (SOAP) Request (DEPRECATED) however im getting exception becouse of using https while i want to use load WSDL.
Any ideas to solve my problem?
Here is a request from View Result Tree
POST https://...address here..?wsdl
POST data:
Filename: D:\install\apache-jmeter-2.11\TEST\request.xml
<actual file content, not shown here>
[no cookies]
Request Headers:
Content-Type: text/xml
Connection: close
User-Agent: Jakarta Commons-HttpClient/3.1
Host: hostname
Content-Length: 1826
EDIT: i solved this problem by doing configuration like this:
ULR = https://..address here.. (NO WSDL)
SOAP action specified (url from wsdl)
KeepAlive checked
XML pasted in textbox section
However when i load xml from file - test fails with message couldnt parse stream. The same message pasted into textbox section - works perfectly. Whats wrong?
Configuration:
URL : scheme://..address here.. (NO WSDL)
SOAP action specified (url from wsdl)
KeepAlive checked
path to XML file pasted into right section
File encoding:
XML was not loading as i expected because of encoding.
I had set UTF-8 with BOM encoding while my service expected UTF-8 without BOM.

Why django staticfiles serving svg as application/octet-stream instead of image/svg+xml

I used wagtail-generator with yoeman to generate a wagtail django project and svg files served by django with django.contrib.staticfiles output application/octet-stream mimetype instead of image/svg+xml mimetype which breaks picture rendering.
I tried this solution without success but I'm sure that using something like nginx to serve static files would fix this (did not try yet).
Based on this answer to another of my questions, I can copy wagtail's template in my templates so I can change the admin logo, but it doesn't fix the svg problem ;)
What I'm getting right now:
And here's the response from Chrome network tab in case it could help:
$ wget http://localhost:8000/static/wagtailadmin/images/wagtail-logo.svg
output:
--2014-07-02 16:14:36-- http://localhost:8000/static/wagtailadmin/images/wagtail-logo.svg
Resolving localhost... 127.0.0.1, ::1, fe80::1
Connecting to localhost|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3082 (3.0K) [application/octet-stream]
Saving to: 'wagtail-logo.svg'
100%[=============================================================>] 3,082 --.-K/s in 0.006s
2014-07-02 16:14:36 (466 KB/s) - 'wagtail-logo.svg' saved [3082/3082]

Why am I getting different mime types on my flask app on localhost and openshift?

I have a dynamic css file which loads fonts using font-face which is generated by a request and I am setting the content headers explicitly. It's all working well as far as mime types are concerned at localhost(text/css in network tab) except that the fonts are not loaded in chrome but works in firefox. But that's a different issue, so now I put the code on openshift and by magic response has a text/html header. What am I missing here ?
resp = make_response(render_template('webfonts.css', fonts=fonts))
resp.headers.add('content-type', 'text/css')
return resp
heres the flask code.
and heres the url
http://flaskexample-diadara.rhcloud.com/api/webfonts?font=LohitGujarati
I had the same issue (with the Flask built-in server) and also came across your question, I found the following:
While adding the header can be found elsewhere as the recommended solution it actually doesn't set one of the properties in the Response object (which actually makes sense if you think about it) making the server still send out a default text/html header.
The way that I found it to work is this:
response = Response(render_template('css/' + filename), mimetype='text/css')
return response
You should also do
from flask import Response