locked
What is the purpose of uri_tokenizer.match_path() ? RRS feed

  • Question

  • Say I have the following code,

    http_listener::create( L"http://localhost:8080/mydomain", [&] ( http_request message ) {
    
    	uri_tokenizer uri_tokens( message.request_uri() );
    	if (uri_tokens.match_path(wstring(L"foo.html"))) {
    		// load foo.html
    	} 
            else if( uri_tokens.match_path(wstring(L"bar.html"))) {
    		// load bar.html
    	}
    		
    })
    .listen( []() { fgetc(stdin); })
    .wait();

    I am expecting the appropriate conditional block to be entered if the user requests "http://localhost:8080/mydomain/foo.html" or "http://localhost:8080/mydomain/bar.html" respectively, but this does not happen. In fact, match_path  does not appear to do anything at all, apart from defer to this->bind() which simply returns true if its argument is non-zero.

    Have I misinterpreted the purpose of match_path?

    Cheers,

    Andrew.


    Sunday, January 13, 2013 10:42 PM

Answers

  • Hi Andrew,

    The purpose of match_path was simply to split the path into separate tokens and return them in parameters passed in. So for example consider the following:

    uri_tokenizer uri_tokens(L"http://localhost:8080/mydomain/foo.html");
    
    std::wstring path1, path2;
    uri_tokens.match_path(path1, path2);
    
    // path1 now contains 'mydomain'
    // path2 new contains 'foo.html'

    For our next release we have actually decided to delete the uri_tokenizer class. Instead take a look at the
    uri::split_path method. It can be used to accomplish the same thing. Basically it splits all the path pieces
    into a vector of strings for you.

    Steve

    Tuesday, January 15, 2013 10:01 PM

All replies

  • Hi Andrew,

    The purpose of match_path was simply to split the path into separate tokens and return them in parameters passed in. So for example consider the following:

    uri_tokenizer uri_tokens(L"http://localhost:8080/mydomain/foo.html");
    
    std::wstring path1, path2;
    uri_tokens.match_path(path1, path2);
    
    // path1 now contains 'mydomain'
    // path2 new contains 'foo.html'

    For our next release we have actually decided to delete the uri_tokenizer class. Instead take a look at the
    uri::split_path method. It can be used to accomplish the same thing. Basically it splits all the path pieces
    into a vector of strings for you.

    Steve

    Tuesday, January 15, 2013 10:01 PM
  • Ah, I see. Thanks. 

    I'd already anticipated the change to uri_tokenizer.

    Cheers,

    Andrew.

    Wednesday, January 16, 2013 8:02 PM