I have this on the last line in my .htaccess
# Default response
RewriteRule ^.*$ https://miranda-zhang.github.io/cloud-computing-schema/v1.0/406.html [R=406,L]
But when I tested, it seems to return a default Apache server page.
$ curl -H "Accept: anything else" http://150.203.213.249/test
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 336 100 336 0 0 336 0 0:00:01 --:--:-- 0:00:01 328k<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /test could not be found on this server.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at 150.203.213.249 Port 80</address>
</body></html>
This is intended as an entry to w3id.org
However, I can change the code to 308 to make it redirect, is this a bad practice or it doesn't matter?
You can just use an ErrorDocument directive to render a custom page for 406 (or for 408):
ErrorDocument 406 /error.html
Related
I have a cronjob that uses curl to send http post to my home-assistant.io server that in turn uses google_say to make my Google Home tell people to start getting ready in the morning... for a bit of fun. :)
It works great but when trying to add some dynamic content such as saying the day of the week, I'm struggling with the construct of using date within curl. I would also like it determine the number of days until the weekend. I have tried the following:
"message": "Its "'"$(date +%A)"'" morning and x days until the weekend. Time to get ready."
but get an error saying:
<html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1>Server got itself in trouble</body></html>
Am I wrong in thinking that "'"$(date +%A)"'" should work in this situation? Also I'd like to add how many days until the weekend, probably something like:
6 - $(date +%u)
I appreciate that I could do this very easily by doing some calculations before curl and referencing those but would like to do it in a single line if possible. The line is referenced from an .sh file at present, not a single line in cron.
This is the full line as requested:
curl -X POST -H "x-ha-access: apiPass" -H "Content-Type: application/json" -d '{"entity_id": "media_player.Living_room_Home", "message": "Its "'"$(date +%A)"'" morning and 2 days until the weekend. Time to get ready."}' http://ipAddr:8123/api/services/tts/google_say?api_password=apiPass
Thanks.
It works perfectly fine with this line:
curl --trace-ascii 1 -X POST -H "x-ha-access: apiPass" -H "Content-Type: application/json" -d '{"entity_id": "media_player.Living_room_Home", "message": "Its '$(date +%A)' morning and 2 days until the weekend. Time to get ready."}'
With result:
== Info: Trying ::1...
== Info: TCP_NODELAY set
== Info: Connected to localhost (::1) port 80 (#0)
=> Send header, 197 bytes (0xc5)
0000: POST /api/services/tts/google_say?api_password=apiPass HTTP/1.1
0041: Host: localhost
0052: User-Agent: curl/7.50.3
006b: Accept: */*
0078: x-ha-access: apiPass
008e: Content-Type: application/json
00ae: Content-Length: 130
00c3:
=> Send data, 130 bytes (0x82)
0000: {"entity_id": "media_player.Living_room_Home", "message": "Its T
0040: uesday morning and 2 days until the weekend. Time to get ready.
0080: "}
== Info: upload completely sent off: 130 out of 130 bytes
<= Recv header, 24 bytes (0x18)
0000: HTTP/1.1 404 Not Found
<= Recv header, 28 bytes (0x1c)
0000: Server: Microsoft-IIS/10.0
<= Recv header, 37 bytes (0x25)
0000: Date: Tue, 07 Nov 2017 21:12:21 GMT
<= Recv header, 19 bytes (0x13)
0000: Content-Length: 0
<= Recv header, 2 bytes (0x2)
0000:
== Info: Curl_http_done: called premature == 0
== Info: Connection #0 to host localhost left intact
Would this help?
echo $(( $(date -d 'next saturday' +%j) - $(date +%j) - 1 )) days until the weekend
The -d option in GNU date lets you provide a surprisingly flexible description of the date you want.
It's my 1st question here, so be gentle ;-)
I search how write a shell who can download a file from dropfile.to with curl
Context: We exchange videos we took with our GoPro with dropfile.to instead of cut them and send them by mail.
We don't need any registration but this website keep the videos during 24 hours before delete them automatically.
So, I write a shell who read my mail (done) and download automatically a video when it find a dropfile.to link...
For now, I know when I press the button "dowload file" on dropfile.to/$code, I send a POST request with the parameter dl_file_name : "$code"; the website do a redirection and do a GET request; the file I want is in the header answer as a file attachment...
so the curl request should be something like:
curl -L -O -J -d download-file:$code https://dropfile.to/$code
with options:
-L for the redirection
-O for download the result
-J for download the attachment file
-d for the POST method
Sadly, it not work... T_T
and when i use directly the get URL i found in my browser like:
curl -O -J $urlGet
i have some erors like:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 178 0 0 337 0 --:--:-- --:--:-- --:--:-- 337
100 154 100 154 0 0 139 0 0:00:01 0:00:01 --:--:-- 3080
Warning: Remote filename has no length!
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
curl: (23) Failed writing body (0 != 3445)
I hope you can help me
In application/x-www-form-urlencoded format, names and values are separated with equal symbol (=) :
code="p42zvEV"
curl -L -J -O "https://dropfile.to/$code" -d "dl_file_name=$code"
I've installed couchdb and mingw64 on my windows 10, I can use futon to operate my couch db, no problem. Then I tried command line using curl.
I used curl to create database named "my_database", I can query it using "GET":
$ curl -X GET http://localhost:5984/my_database/002
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 81 100 81 0 0 397 0 --:--:-- --:--:-- --:--:-- 397{"_id":"002","_rev":"1-5e653801ca3cefde8abb6492ae3bcbcd","name":"mesi","age":23}
But I cannot do any data update, seems my curl syntax had problem:
$ curl -X PUT http://127.0.0.1:5984/my_database/002/msg.jpg?res=1-5e653801ca3cefde8abb6492ae3bcbcd --data-binary #/e/msg.jpg -H "ContentType:image/jpg"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
14 910k 100 58 14 128k 58 128k 0:00:07 --:--:-- 0:00:07 125M{"error":"conflict","reason":"Document update conflict."}
I know the jpg file is there:
$ ls /e/msg.jpg
/e/msg.jpg
Why I cannot update the jpg document as attachement? I guess I might have some syntax error using curl or couchdb, but how to fix it?
Using futon_db: created document, but what's the URL resource name of it?
Whenever you update a document/Attachment in CouchDB, you need to specify the revision (otherwise it cause conflicts). I guess that you only forgot to write rev properly (you wrote res).
Syntax taken from this question :
curl -vX PUT http://localhost:5984/YOUR_DB/YOUR_DOCUMENT/YOUR_ATTACHMENT.jpg?rev=REVISION_OF_THE_DOCUMENT_BEFORE_UPLOADING_AN_ATTACHMENT --data-binary #FILE_ON_THE_DISK.JPG -H "Content-Type: image/jpg"
When I use cURL, I Found it seems that cURL knew whether its own output will be redirect, or be input for another program.
Following are two different command:
curl http://www.google.com/
The output will be:
<HTML><HEAD>......blah, blah......</HEAD></HTML>
But if I use redirect or pipe, cURL will print its download status.
curl http://www.google.com/ | xargs echo
the output will be leading with:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 376 100 376 0 0 2729 0 --:--:-- --:--:-- --:--:-- 5295
<HTML><HEAD>......blah, blah......</HEAD></HTML>
My question is: how cURL know whether its print will be redirect?
isatty(3) will tell you if a FD is connected to a TTY.
Using varnish-cache, I am running varnishtop -c -i RxURL to show number of client requests from the cache. The output looks somewhat like this:
list length 40
121.76 RxURL /some/path/to/file
105.17 RxURL /some/other/file
42.91 RxURL /and/another
14.61 RxURL /yet/another
14.59 RxURL /etc
13.63 RxURL /etc/etc
What do the numbers 121.76, 105.17 etc. stand for?
They are increasing when first issuing varnishtop, but then they tend to stabilize, so I tend to believe the represent number of hits per specific timeframe. Is that so, and what is the timeframe?
This is not explained in the man page. Thank you for any assistance!
Edit: varnish version is 2.1
The varnishtop command shows the rolling aggregate count over 60 seconds. That means even if all traffic stops, it will take 60 seconds to average down on the display.
list length 40
Total number of items in the list since the screen can only show so many at a time.
121.76 RxURL /some/path/to/file
~121 requests received in the last 60 seconds for /some/path/to/file.
Some other interesting monitoring stats:
# most frequent cookies
varnishtop -i RxHeader -I Cookie
# continually updated list of frequent URLs
varnishtop -i RxURL
# most frequent UA strings
varnishtop -i RxHeader -C -I ^User-Agent
# frequent charset (Accept-Charset can be replaced with any other HTTP header)
varnishtop -i RxHeader -C -I '^Accept-Charset'
# Requests resulting in 404's
varnishlog -b -m "RxStatus:404"
It's the average number of requests per 60 seconds. The manual does say it - but at the parameter explanation rather than the general description of the tool:
-p period Specifies the number of seconds to measure over, the default is 60 seconds. The first number in the list is the average number of requests seen over this time period.