I am trying to run a broadcast link, but this link only works with the so-called user-agent and referer
How can I add it this Option
You should be able to set it with the HttpDataSourceFactory. n.b. this is against Media3, but I believe it's almost the same.
val dataSourceFactory = DefaultHttpDataSource.Factory()
.setUserAgent("XXX")
.setDefaultRequestProperties(mapOf("Referer" to "https://example.org/"))
player =
ExoPlayer.Builder(this)
.setMediaSourceFactory(DefaultMediaSourceFactory(dataSourceFactory))
.build()
Related
I've been searching for a while about the recommended and current way of creating Watir::Browser.new for :chrome and set it to accept a certain language. However, this seems to be a topic with little interest, seems to be ever changing, etc.
So, please, can someone explain what the current and recommended way of setting Chrome's language is?
I'm not talking about Chrome's user interface but the Accept-Language HTTP header that later gets sent with the HTTP request so that an application can render it's web UI using the correct locale and language.
For Firefox this works but I have no luck for Chrome:
profile = Selenium::WebDriver::Firefox::Profile.new
profile["intl.accept_languages"] = "ES"
caps = Selenium::WebDriver::Remote::Capabilities.firefox(firefox_profile: profile)
caps.platform = "Linux"
caps.version = 20
browser = Watir::Browser.new :firefox, :desired_capabilities => caps
Thanks.
The "intl.accept_languages" is a Chrome preference, so can be passed in as:
Watir::Browser.new :chrome, options: {prefs: {'intl' => {'accept_languages' => 'ES'}}}
I was wondering if there was any way to re-order HTTP headers that are being sent by our browser, before getting sent back to the web server?
Since the order of the headers leaves some kind of "fingerprinting", see this post and this post, I was thinking about using MITMProxy (with Inline Scripting, I guess) to modify headers on-the-fly. Is this possible?
How would one achieve that?
Note: I'm looking for a method that could be scripted, not a method using a graphical tool like the Burp Suite (although Burp is known to be able to re-order headers)
I'm open to suggestions. Perhaps NGINX might come to the rescue as well?
EDIT: I should be more specific, by giving an example...
Let's say I'm using Firefox. With the use of a funky add-on, I'm spoofing my user-agent to "look" like a Chrome browser. But then if I test my browser with ip-check.info, the "signature" of my browser remains the one of Firefox, even though my spoofed user-agent shows "Chrome".
So the solution, in this specific case, should be to re-order the HTTP headers in the same manner as Chrome does.
How can this be done?
For the record, the order of the HTTP headers should not matter at all according to RFC 7230. But now that you have asked... this can be done in mitmproxy as follows:
import random
def request(context, flow):
# flow.request.headers.fields is a tuple of (name, value) header tuples.
h = list(flow.request.headers.fields)
random.shuffle(h)
flow.request.headers.fields = tuple(h)
See the mitmproxy documentation on netlib.http.Headers for more details.
There are tons of way to reorder them as you wish:
def reorder(headers, header_order=["Host","User-Agent","Accept"]):
lines = []
for name in header_order: # add existing headers in the specified order
if name in headers:
lines.extend(headers.get_all(name))
del headers[name]
lines.extend(headers.fields) # all other headers
return lines
request.headers.fields = reorder(request.headers)
I am writing a client side code in Visual C++ 2012 using C++ Rest SDK (codename "Casablanca").
I have a client created and wish to POST a text string to the server. However, when I send the following code, it is compiling but not sending sending the request.
When I remove everything after "methods::POST" and send a blank post request, then it is sent and received by the server.
Can you please guide me where the problem is. The documentation related to this function is available on Casablanca Documentation.
pplx::task<http_response>resp = client.request(methods::POST,L"",L"This is the random text that I wish to send", L"text/plain");
I think the usage you give here looks correct.
Is your Casablanca the latest version ? Please check that out from here : http://casablanca.codeplex.com/
If you are sure your measurement is accurate, you may want to create a minimal repro and file a bug here : http://casablanca.codeplex.com/workitem/list/basic
I was having a similar problem, all my POSTs was arriving in blank on server , after a few hours work above it, i found a possible solution.
I changed the default content type to application/x-www-form-urlencoded and I started to pass the values like this Example data=text1&data2=text2
client.request(methods::POST,L"",L"data=text1&data2=text2", L"application/x-www-form-urlencoded");
The body parameter must be a json::value.
I cannot comment yet so I have to put my thoughts in an answer. I solved this problem like this: There is an overload of the request method that takes as a parameter the content type so that you do not have to change the code.
m_client->request(methods::POST, L"/statuses/update.json?" + url_encode(data),L"",L"application/x-www-form-urlencoded");
Obviously you would have to implement the url_encode method but that is not difficult. There is a pretty good implementation in "Cassablanca". A search on this site will alos turn up some good examples.
I would like to create a simple add-on that would play a different MP3 recording every time the user double clicks a word in a webpage he is visiting and selects a special option from the context menu.
The MP3 files are located on a remote server. Normally I would use JavaScript+Flash to play the MP3 file. In a Firefox add-on, however, I'm unable to load external scripts for some reason (playing the sound works fine if it's the webpage itself that loads the scripts, but of course I need it to work with every website and not just the ones that include the script).
So what's the easiest way to play a remote MP3 file in a Firefox add-on using JavaScript?
This may not entirely solve your question, as I don't BELIEVE it plays MP3s, but I'm not certain.
Firefox has nsISound, which I KNOW can play remote WAV files, as I've tested and proved it.
You may want to test it for yourself and see if it leads you a little closer!
var ios = Components.classes['#mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
var sound = ios.newURI("http://www.yoursite.com/snds/haha.wav", null, null);
var player = Components.classes["#mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
player.play(sound);
Good luck, I hope this at least gets you close!
I know this is an old question, but if someone needs a way to do it:
let player = document.createElement("audio");
player.src = browser.runtime.getURL(SOUND_URL);
player.play();
There is one caveat: the user must have allowed autoplay on the website.
Here is a working code....
var sound = Components.classes["#mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
var soundUri = Components.classes['#mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI);
soundUri.spec = "chrome://secchat/content/RING.WAV";
sound.play(soundUri);
var window = require('sdk/window/utils').getMostRecentBrowserWindow();
var audio = ('http://example.com/audio.mp3');
audio.play();
I am using QNetworkManager to fetch files from a server, however what I cannot figure out is if the files are compressed during the transfer with the standard gzip compression and if not how to get them to download compressed.
How would I go about checking?
I just ran a quick test by adding:
request.setRawHeader("Accept-Encoding", "gzip,deflate");
to the QNetworkRequest and the data returns what look compressed (because its ~20% smaller and unusable).
It appears that the QNetworkManager and the QNetworkReply are not intelligent as far as decompression is concerned. It looks like I have to implement a gzip and/or deflate on the returned QByteArray.
When you set a custom Accept-Encoding raw header on a QNetworkRequest object (for example via an overridden QNetworkAccessManager::createRequest() ), QtWebKit will never decompress the reply anymore: source code of qhttpnetworkconnection.cpp : ====================
// If the request had a accept-encoding set, we better not mess
// with it. If it was not set, we announce that we understand gzip
// and remember this fact in request.d->autoDecompress so that
// we can later decompress the HTTP reply if it has such an
// encoding.
value = request.headerField("accept-encoding");
if (value.isEmpty()) {
#ifndef QT_NO_COMPRESS
request.setHeaderField("Accept-Encoding", "gzip, deflate");
request.d->autoDecompress = true;
#else
// if zlib is not available set this to false always
request.d->autoDecompress = false;
#endif
You should use a packet sniffer / network analyzer and check for yourself.
QNetworkAccessManager does support receiving compressed HTTP replies, so in theory it should work if the HTTP server is correctly set up.
Read this elsewhere so w/o having tested it: just don't set the accept-encoded header yourself, then QNam should handle it transparently (return decompressed payload).
Considering the following sentence, I would say no, but they can be :
The downloadProgress() signal is also
emitted when data is received, but the
number of bytes contained in it may
not represent the actual bytes
received, if any transformation is
done to the contents (for example,
decompressing and removing the
protocol overhead).
You can find it here : https://doc.qt.io/qt/qnetworkreply.html
I didn't test it tho !
To compress, if I remember well, you can send QByteArray... And on this kind of objects, you can use "compress"...
You could also have a look at some Qt examples, like :
https://doc.qt.io/qt/qtnetwork-broadcastsender-example.html
I didn't look at all of them but maybe you'll find some interesting things !
Hope it helps a bit !