Project

General

Profile

Actions

Bug #520

closed

WFileResource and Built in HTTP Server : response should be of type StaticReply not Reply

Added by Momo LALMI over 13 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Urgent
Assignee:
Target version:
-
Start date:
09/18/2010
Due date:
% Done:

90%

Estimated time:

Description

To handle "Range" header, response = "206 Partial Content" instead of "200 Ok" ...

All browsers were not able to play OGG files because of this,

please see below the difference between what a browser is not able to understand (Reply using WFileResource) and what it understand ( Static file )

//-------------------------------------------------------------------------------------------------------------------------

// USING WFILERESOURCE*

//-------------------------------------------------------------------------------------------------------------------------

GET /?wtd=tENyqreaoEjSTMET&request=resource&resource=o101&rand=21891 HTTP/1.1

Host: 192.168.0.10

Connection: keep-alive

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3

Accept-Encoding: gzip,deflate,sdch

Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Range: bytes=0-1024

HTTP/1.1 200 OK

Date: Sat, 18 Sep 2010 11:41:27 GMT

Content-Type: audio/ogg

Transfer-Encoding: chunked

GET /?wtd=tENyqreaoEjSTMET&request=resource&resource=o101&rand=21891 HTTP/1.1

Host: 192.168.0.10

Connection: keep-alive

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3

Accept-Encoding: gzip,deflate,sdch

Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Range: bytes=10622-

HTTP/1.1 200 OK

Date: Sat, 18 Sep 2010 11:41:27 GMT

Content-Type: audio/ogg

Transfer-Encoding: chunked

//-------------------------------------------------------------------------------------------------------------------------

// USING STATIC REPLY

//-------------------------------------------------------------------------------------------------------------------------

GET /play.ogg HTTP/1.1

Host: 192.168.0.10

Connection: keep-alive

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3

Accept-Encoding: gzip,deflate,sdch

Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Range: bytes=0-1024

HTTP/1.1 206 Partial Content

Date: Sat, 18 Sep 2010 11:43:18 GMT

Content-Type: audio/ogg

Content-Range: bytes 0-1024/10622

Cache-Control: max-age=3600

ETag: 10622-Mon, 13 Sep 2010 15:19:57 GMT

Expires: Tue, 19 Oct 2010 11:43:18 GMT

Last-Modified: Mon, 13 Sep 2010 15:19:57 GMT

Content-Length: 1025

GET /play.ogg HTTP/1.1

Host: 192.168.0.10

Connection: keep-alive

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3

Accept-Encoding: gzip,deflate,sdch

Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Range: bytes=1025-10621

If-Range: 10622-Mon

HTTP/1.1 206 Partial Content

Date: Sat, 18 Sep 2010 11:43:18 GMT

Content-Type: audio/ogg

Content-Range: bytes 1025-10621/10622

Cache-Control: max-age=3600

ETag: 10622-Mon, 13 Sep 2010 15:19:57 GMT

Expires: Tue, 19 Oct 2010 11:43:18 GMT

Last-Modified: Mon, 13 Sep 2010 15:19:57 GMT

Content-Length: 9597

Actions #1

Updated by Momo LALMI over 13 years ago

If possible : in WResource protected method :

virtual void handleRequest(const Http::Request& request, Http::Response& response)

allow users's application to handle completely the "response" object : i.e : do not force : "Transfer-Encoding: chunked"

Someone may stream audio to WHTML5Audio player using the following headers :


GET /nrk-alltid-nyheter-128.ogg HTTP/1.1

Host: radio.hiof.no

Connection: keep-alive

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.62 Safari/534.3

Accept-Encoding: gzip,deflate,sdch

Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Range: bytes=0-1024

HTTP/1.0 200 OK

Content-Type: application/ogg

Server: Icecast 2.3.2

Cache-Control: no-cache

Actions #2

Updated by Koen Deforche over 13 years ago

  • Assignee set to Wim Dumon
Actions #3

Updated by Momo LALMI over 13 years ago

Here is the code I used to assign a WFileResource to "src" element of WHTML5Audio

Unfortunatly, all browsers were not able to understance the content of the "play.ogg" file !

WFileResource * audioResource = new WFileResource();

audioResource->setFileName("play.ogg");

audioResource->setMimeType("audio/ogg");

WDialog * dialog = new WDialog("Replay");

WVBoxLayout * vbox = new WVBoxLayout( );

dialog~~contents()~~>setLayout(vbox , AlignTop | AlignCenter);

WPushButton * closeButton = new WPushButton("Close");

closeButton->setMaximumSize ( 100 , WLength::Auto ) ;

WHTML5Audio * audioPlayer = new WHTML5Audio();

audioPlayer->setPreloadMode( WHTML5Audio::PreloadAuto );

audioPlayer->setOptions( WHTML5Audio::Controls );

audioPlayer~~addSource( audioResource~~>url(), "audio/ogg" );

//WFlashObject *f = new WFlashObject("resources/WtSoundManager.swf");

//f->setFlashVariable("src", "play.mp3");

//audioPlayer->setAlternativeContent(f);

audioPlayer->resize(300, 30);

dialog->resize(350, 100);

vbox->addWidget ( audioPlayer , 0 , AlignCenter ) ;

vbox->addWidget ( closeButton , 0 , AlignCenter ) ;

closeButton->clicked().connect( audioPlayer , &Wt_MyHTML5Audio::pause);

closeButton->clicked().connect( dialog , &Wt::WDialog::accept);

dialog->setModal(true);

dialog->show();

Actions #4

Updated by Wim Dumon over 13 years ago

Those media files (and HTML5 audio/video) were the reason why we added Range support to wthttp. WFileResource should indeed support them too. (note however that it is legal http to send a 200 and the full in response to a request with ranges, but the browsers don't seem to accept it)

The plan is now to add a range parser to WResource and to update WFileResource so that it serves ranges with 206 response codes when a Range header is present, similar to what StaticReply does.

Wim.

Actions #5

Updated by Momo LALMI over 13 years ago

Thank you Wim,

This is the perfect solution for my project :)

Actions #6

Updated by Wim Dumon over 13 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 90

Worked on this today. Of course, to support video, we didn't only need ranges but also content-length support, so I added that too. The code will be in git soon.

Actions #7

Updated by Momo LALMI over 13 years ago

Thank you Wim, you're the best :)

Wt is fantastic :)

Actions #8

Updated by Koen Deforche over 13 years ago

  • Status changed from Resolved to Closed

Fixed in 3.1.6

Actions

Also available in: Atom PDF