<commit_before>package httprequestutil

import (
  "github.com/wpxiong/beargo/log"
  "github.com/wpxiong/beargo/appcontext"
  "net/url"
)

func init() {
  log.InitLog()
}

func ProcessHttpRequestParam(appContext *appcontext.AppContext) {
    var getParameter url.Values = appContext.Request.HttpRequest.URL.Query()
    var formParameter url.Values
    contentType := appContext.Request.HttpRequest.Header.Get("Content-Type")
    switch contentType {
      case "application/x-www-form-urlencoded":
        if err := appContext.Request.HttpRequest.ParseForm(); err != nil {
          log.Error("process application/x-www-form-urlencoded error")
        } else {
          formParameter = appContext.Request.HttpRequest.Form
        }
      case "multipart/form-data":
        if err := appContext.Request.HttpRequest.ParseForm(); err != nil {
         log.Error("process multipart/form-data error")
        } else {
          formParameter = appContext.Request.HttpRequest.Form
        }
    }
    log.Debug(getParameter)
    log.Debug(formParameter)
}<commit_msg>commit<commit_after>package httprequestutil

import (
  "github.com/wpxiong/beargo/log"
  "github.com/wpxiong/beargo/appcontext"
  "net/url"
  "mime/multipart"
)

func init() {
  log.InitLog()
}

func MapMerge(dst, src url.Values) *url.Values{
    var valuesMap url.Values = make(map[string][]string)
    for key, value := range dst {
        if valuesMap[key] == nil {
          valuesMap[key] = make([]string,len(value))
        }
        valuesMap[key] = append(valuesMap[key],value...)
    }
    for key, value := range src {
       if valuesMap[key] == nil {
         valuesMap[key] = value
       }else {
         var slice1 []string = valuesMap[key]
         valuesMap[key] = append(slice1,value...)
       }
    }
    return &valuesMap
}

func ProcessHttpRequestParam(appContext *appcontext.AppContext) {
    var getParameter url.Values = appContext.Request.HttpRequest.URL.Query()
    var formParameter url.Values
    var filesParameter map[string][]*multipart.FileHeader  
    contentType := appContext.Request.HttpRequest.Header.Get("Content-Type")
    switch contentType {
      case "application/x-www-form-urlencoded":
        if err := appContext.Request.HttpRequest.ParseForm(); err != nil {
          log.Error("process application/x-www-form-urlencoded error")
        } else {
          formParameter = appContext.Request.HttpRequest.Form
        }
      case "multipart/form-data":
        if err := appContext.Request.HttpRequest.ParseMultipartForm(32 << 20 /* 32 MB */); err != nil {
            log.Error("process multipart/form-data error")
        } else {
            formParameter = appContext.Request.HttpRequest.MultipartForm.Value
            filesParameter = appContext.Request.HttpRequest.MultipartForm.File
        }
    }
    formParameter = make(map[string][]string)
    formParameter["xiong"] = []string{"gag"}
    paramMap := MapMerge(getParameter,formParameter)
    for key,value := range *paramMap {
        if len(value) == 1{
           appContext.Parameter[key] = value[0]
        }else {
           appContext.Parameter[key] = value
        }
    }
    log.Debug(filesParameter)
    log.Debug(appContext.Parameter)
}
{'fraction_non_alphanumeric': 0.12352576039726877, 'fraction_numerical': 0.0031036623215394167, 'mean_word_length': 2.809692671394799, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2479467', 'n_tokens_mistral': 974, 'n_tokens_neox': 965, 'n_words': 169}