Code Monkey home page Code Monkey logo

Comments (6)

sylingd avatar sylingd commented on June 14, 2024 1

This is not very common. You can implement it with custom code.
For example:

for (let a in val) {
	if (val[a].name === 'Cookie') {
		val[a].value += ';myaddedcookie=abc';
		return;
	}
}
// If this request has not Cookie, add it
val.push({
	"name": "Cookie",
	"value": "myaddedcookie=abc"
});

from headereditor.

sylingd avatar sylingd commented on June 14, 2024 1

You can use regular expression. Documention: MDN. For example:

val[a].value = val[a].value.replace(/ball=(\w+)/, ''); // will remove ball=[english words], such as ball=words
val[a].value = val[a].value.replace(/ball=(\d+)/, ''); // will remove ball=[numbers], such as ball=12345
val[a].value = val[a].value.replace(/ball=([a-zA-Z0-9]+)/, ''); // will remove ball=[english words or numbers], such as ball=1a2b3qq135

from headereditor.

grenzor avatar grenzor commented on June 14, 2024

Thanks, that works for me!

On a somewhat related question, do you know of a custom code that is able to remove a specific header value, example: remove value 'ball' from Cookie: ball=1&cat=1 so it then becomes Cookie: cat=1

I messed around with some JS code to do this but wasn't able to get one working since my knowledge of JS is weak

from headereditor.

sylingd avatar sylingd commented on June 14, 2024

You can use replace function. Example:

for (let a in val) {
	if (val[a].name === 'Cookie') {
		val[a].value = val[a].value.replace('ball=value', '');
		break;
	}
}

If you want to learn more about Javascript, you can visit MDN

from headereditor.

grenzor avatar grenzor commented on June 14, 2024

Thanks again and also for the link, will look into it.

If I see correctly, the code would work only if the value in ball=value is constant, but what if the value is randomly generated?

from headereditor.

grenzor avatar grenzor commented on June 14, 2024

Interesting, I'll look more into regular expressions. Thank you!

from headereditor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.