<commit_before>/*
 * Copyright 2014 <NAME>
 *
 * <NAME> licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.github.jonbonazza.puni.core.requests;

import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Wrapper class for extending the functionality of DefaultFullHttpRequest.
 * This class adds the ability to retrieve an http request's form data and uri components.
 */
public class HttpRequest extends DefaultFullHttpRequest {

    protected Map<String, String> formData = new HashMap<>();
    protected String[] uriComponents;

    public HttpRequest(FullHttpRequest req) {
        super(req.getProtocolVersion(), req.getMethod(),
                req.getUri(), req.content().copy());
        String[] uriParts = getUri().split("\\?");
        uriComponents = uriParts[0].split("/");
        uriComponents = Arrays.copyOfRange(uriComponents, 1, uriComponents.length);
        if (uriParts.length > 1)
            parseFormData(uriParts[1]);
    }

    protected void parseFormData(String queryParamSection) {
        String[] queryParams = queryParamSection.split("&");
        for (String param : queryParams) {
            String[] paramComponents = param.split("=");
            if (paramComponents.length == 2)
                formData.put(paramComponents[0], paramComponents[1]);
        }
    }

    public Map<String, String> getFormData() {
        return formData;
    }

    public String[] getUriComponents() {
        return uriComponents;
    }
}<commit_msg>HttpRequest now supports multi-value params.<commit_after>/*
 * Copyright 2014 <NAME>
 *
 * <NAME> licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.github.jonbonazza.puni.core.requests;

import io.netty.handler.codec.http.DefaultFullHttpRequest;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.QueryStringDecoder;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Wrapper class for extending the functionality of DefaultFullHttpRequest.
 * This class adds the ability to retrieve an http request's form data and uri components.
 */
public class HttpRequest extends DefaultFullHttpRequest {

    protected Map<String, List<String>> formData;
    protected String[] uriComponents;

    public HttpRequest(FullHttpRequest req) {
        super(req.getProtocolVersion(), req.getMethod(),
                req.getUri(), req.content().copy());
        String[] uriParts = getUri().split("\\?");
        uriComponents = uriParts[0].split("/");
        uriComponents = Arrays.copyOfRange(uriComponents, 1, uriComponents.length);
        if (uriParts.length > 1)
            parseFormData(uriParts[1]);
    }

    protected void parseFormData(String queryParamSection) {
        QueryStringDecoder decoder = new QueryStringDecoder(getUri());
        formData = decoder.parameters();
    }

    public Map<String, List<String>> getFormData() {
        return formData;
    }

    public String[] getUriComponents() {
        return uriComponents;
    }
}
{'fraction_non_alphanumeric': 0.1020310633213859, 'fraction_numerical': 0.0064516129032258064, 'mean_word_length': 3.477005347593583, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1467485', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1091, 'n_words': 367}