Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7696835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:52:20+00:00 2026-05-31T21:52:20+00:00

Is there any javascript function, to parse the first line of the http header?

  • 0

Is there any javascript function, to parse the first line of the http header?

GET /page/?id=173&sessid=mk9sa774 HTTP/1.1

The url is encoded.

I would like to get an object, like this:

{
"method" : "GET",
"url" : "/page/",
"parameters": {
  "id" : 173,
  "sessid" : "mk9sa774"
  }
}

I searched a lot, but I haven’t found anything useful.

thanks in advance,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:52:21+00:00Added an answer on May 31, 2026 at 9:52 pm

    First you can split on spaces:

    var lineParts = line.split(' ');
    

    Now you can get the method, unparsed path, and version:

    var method  = lineParts[0];
    var path    = lineParts[1];
    var version = lineParts[2];
    

    Then you can split up the path into the query string and non-query string parts:

    var queryStringIndex = path.indexOf('?');
    var url, queryString;
    if(queryStringIndex == -1) {
        url = path, queryString = '';
    }else{
        url = path.substring(0, queryStringIndex);
        // I believe that technically the query string includes the '?',
        // but that's not important for us.
        queryString = path.substring(queryStringIndex + 1);
    }
    

    If there is a query string, we can then split it up into key=value strings:

    var queryStringParts = [];
    if(queryStringIndex != -1) {
        queryStringParts = queryString.split('&');
    }
    

    Then we can unescape them and stuff them into an object:

    var parameters = {};
    queryStringParts.forEach(function(part) {
        var equalsIndex = part.indexOf('=');
        var key, value;
        if(equalsIndex == -1) {
            key = part, value = "";
        }else{
            key   = part.substring(0, equalsIndex);
            value = part.substring(equalsIndex + 1);
        }
        key   = decodeURIComponent(key);
        value = decodeURIComponent(value);
        parameters[key] = value;
    });
    

    If you really wanted to, you could then put all that data into an object:

    return {
        method:     method,
        url:        url,
        version:    version,
        parameters: parameters
    };
    

    If you’re in a browser environment, that’s the only way to do it. If you’re using Node.JS, it can deal with the URL parsing for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any javascript function that can encrypt data: For example i want to
Is there any way that I can call a JavaScript function via css? For
is there any example on using java method to call rhino-javascript function and return
Is there any way I can make Firefox call a JavaScript function in my
I have a javascript function that checks for a date range. Is there any
I have a javascript function that runs every 3 seconds, is there any way
Is there any function that I can use to parse any string to ensure
Is there any globals function in Javascript which is similar to PHP globals that
Is there a way to parse the argument values passed to a JavaScript function
is there any javascript library that provides me with a custom event as soon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.